### Configure ARPACK-NG Example Builds with CMake Source: https://github.com/opencollab/arpack-ng/blob/master/CMakeLists.txt This snippet demonstrates how to define source file lists and set runtime output directories for various ARPACK-NG example categories. It uses custom CMake functions 'examples' and 'pexamples' to process Fortran source files into executable binaries. ```cmake set(arpackexample_DIR ${arpack_SOURCE_DIR}/EXAMPLES/BAND/) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/EXAMPLES/BAND/) set(examples_EXTRA_SRCS ${arpackexample_DIR}/cnband.f) set(examples_STAT_SRCS cnbdr1.f cnbdr2.f cnbdr3.f cnbdr4.f) examples(examples_STAT_SRCS) if (MPI) set(parpackexample_DIR ${arpack_SOURCE_DIR}/PARPACK/EXAMPLES/MPI/) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/PARPACK/EXAMPLES/MPI/) set(pexamples_STAT_SRCS pcndrv1.f pdndrv1.f) pexamples(pexamples_STAT_SRCS) endif() ``` -------------------------------- ### Configure and Copy Example Files Source: https://github.com/opencollab/arpack-ng/blob/master/CMakeLists.txt Configures example matrix market files and shell scripts, copying them to the runtime output directory for testing purposes. This ensures that test scripts have access to the necessary input data. ```cmake configure_file(EXAMPLES/MATRIX_MARKET/issue401.mtx ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/issue401.mtx) configure_file(EXAMPLES/MATRIX_MARKET/issue401.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/issue401.sh) configure_file(EXAMPLES/MATRIX_MARKET/issue215.mtx ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/issue215.mtx) configure_file(EXAMPLES/MATRIX_MARKET/issue215.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/issue215.sh) ``` -------------------------------- ### Install CMake and ARPACK-NG via CMake Source: https://github.com/opencollab/arpack-ng/blob/master/README.md Commands to install the CMake build tool and perform a standard build and installation of ARPACK-NG from source. ```bash python3 -m pip install cmake which cmake && cmake --version mkdir build cd build cmake -D EXAMPLES=ON -D MPI=ON -D BUILD_SHARED_LIBS=ON .. make sudo make install ``` -------------------------------- ### Build arpack-ng using Autotools (Bash) Source: https://github.com/opencollab/arpack-ng/blob/master/README.md This sequence of commands outlines the process of building and installing the arpack-ng library using the autotools build system. It includes bootstrapping, configuring with MPI support, compiling, checking, and installing the library. ```bash sh bootstrap ./configure --enable-mpi make make check sudo make install ``` -------------------------------- ### Install ARPACK-NG targets and headers Source: https://github.com/opencollab/arpack-ng/blob/master/CMakeLists.txt Handles the installation of compiled libraries, header files, and export targets to the system or specified installation directory. It includes conditional logic to handle MPI-specific components and Interface C Binding (ICB) headers. ```cmake install(TARGETS arpack EXPORT arpackngTargets ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) if(ICB) install(FILES ICB/arpack.h DESTINATION "${ARPACK_INSTALL_INCLUDEDIR}") install(FILES ICB/arpack.hpp DESTINATION ${ARPACK_INSTALL_INCLUDEDIR}) endif() ``` -------------------------------- ### Configure ARPACK-NG with ILP64 BLAS/LAPACK Source: https://github.com/opencollab/arpack-ng/blob/master/README.md This example demonstrates how to configure ARPACK-NG to use ILP64-compatible BLAS and LAPACK libraries, ensuring correct symbol mapping and compilation flags for mixed-precision environments. ```bash #!/bin/bash ./bootstrap export FFLAGS='-DMKL_ILP64 -I/usr/include/mkl' export FCFLAGS='-DMKL_ILP64 -I/usr/include/mkl' export LIBS='-Wl,--no-as-needed -L/usr/lib/x86_64-linux-gnu -lmkl_sequential -lmkl_core -lpthread -lm -ldl' export INTERFACE64=1 ./configure --with-blas=mkl_gf_ilp64 --with-lapack=mkl_gf_ilp64 make all check ``` -------------------------------- ### Customize ARPACK-NG Build Configuration Source: https://github.com/opencollab/arpack-ng/blob/master/README.md Methods for customizing the installation directories, enabling ILP64 support, and enabling ISO_C_BINDING using both Autotools and CMake. ```bash # Autotools customization LIBSUFFIX="64" ./configure INTERFACE64="1" ITF64SUFFIX="ILP64" ./configure ./configure --enable-icb # CMake customization cmake -D LIBSUFFIX="64" .. cmake -D INTERFACE64=ON -D ITF64SUFFIX="ILP64" .. cmake -D ICB=ON ``` -------------------------------- ### Display arpack-ng Configuration Summary Source: https://github.com/opencollab/arpack-ng/blob/master/CMakeLists.txt This section prints a summary of the arpack-ng build configuration, including the installation prefix, MPI support status, and ICB (Inter-Community Bridge) status. It then calls `cprsummary` for Fortran, C, and C++ compilers. ```cmake message("-- Configuration summary for arpack-ng-${arpack_ng_VERSION}:") message(" -- prefix: ${CMAKE_INSTALL_PREFIX}") message(" -- MPI: ${MPI} (ICB provided ${HAVE_MPI_ICB})") message(" -- ICB: ${ICB}") message(" -- INTERFACE64: ${INTERFACE64}") cprsummary("FC" "${CMAKE_Fortran_COMPILER}" "${CMAKE_Fortran_FLAGS_DEBUG}" "${CMAKE_Fortran_FLAGS_MINSIZEREL}" "${CMAKE_Fortran_FLAGS_RELEASE}" "${CMAKE_Fortran_FLAGS_RELWITHDEBINFO}" "${CMAKE_Fortran_FLAGS}") if (ICB) cprsummary("CC" "${CMAKE_C_COMPILER}" "${CMAKE_C_FLAGS_DEBUG}" "${CMAKE_C_FLAGS_MINSIZEREL}" "${CMAKE_C_FLAGS_RELEASE}" "${CMAKE_C_FLAGS_RELWITHDEBINFO}" "${CMAKE_C_FLAGS}") cprsummary("CXX" "${CMAKE_CXX_COMPILER}" "${CMAKE_CXX_FLAGS_DEBUG}" "${CMAKE_CXX_FLAGS_MINSIZEREL}" "${CMAKE_CXX_FLAGS_RELEASE}" "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}" "${CMAKE_CXX_FLAGS}") endif() ``` -------------------------------- ### Create and Link Example Executables (CMake) Source: https://github.com/opencollab/arpack-ng/blob/master/CMakeLists.txt Defines a CMake function to create executable targets from a list of source files. It links the executables against the 'arpack' library, LAPACK/BLAS, and any extra linker flags, and adds them as tests. ```cmake function(examples list_name) foreach(l ${${list_name}}) get_filename_component(lwe ${l} NAME_WE) add_executable(${lwe} ${arpackexample_DIR}/${l} ${examples_EXTRA_SRCS}) target_link_libraries(${lwe} arpack ${LAPACK_BLAS_LIBS} ${EXTRA_LDFLAGS}) add_test(NAME "${lwe}_ex" COMMAND ${lwe}) endforeach() endfunction(examples) ``` -------------------------------- ### Define ARPACK Installation Paths (CMake) Source: https://github.com/opencollab/arpack-ng/blob/master/CMakeLists.txt Sets the installation directories for ARPACK headers and CMake configuration files. It utilizes CMake's built-in variables and custom suffixes based on library configurations. ```cmake include(GNUInstallDirs) set(ARPACK_INSTALL_INCLUDEDIR "${CMAKE_INSTALL_INCLUDEDIR}/arpack${ITF64SUFFIX}") set(ARPACK_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/cmake/arpackng${LIBSUFFIX}${ITF64SUFFIX}") ``` -------------------------------- ### Install Python Module Source: https://github.com/opencollab/arpack-ng/blob/master/CMakeLists.txt Installs the compiled Python module 'pyarpack' to the specified library destination. This makes the module available for use in Python environments. ```cmake install(TARGETS pyarpack ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}/pyarpack LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/pyarpack) ``` -------------------------------- ### Configure and Add Python Tests Source: https://github.com/opencollab/arpack-ng/blob/master/CMakeLists.txt Configures Python example scripts by processing input files (e.g., .py.in) and adds them as tests. It sets the PYTHONPATH environment variable for each test to ensure the 'pyarpack' module is found. ```cmake configure_file("${PROJECT_SOURCE_DIR}/EXAMPLES/PYARPACK/pyarpackSparseBiCGDiag.py.in" "${CMAKE_BINARY_DIR}/pyarpackSparseBiCGDiag.py" @ONLY) add_test(NAME pyarpackSparseBiCGDiag_tst COMMAND ${PYTHON_EXECUTABLE} pyarpackSparseBiCGDiag.py) set_tests_properties(pyarpackSparseBiCGDiag_tst PROPERTIES ENVIRONMENT PYTHONPATH=${CMAKE_BINARY_DIR}/lib:$ENV{PYTHONPATH}) configure_file("${PROJECT_SOURCE_DIR}/EXAMPLES/PYARPACK/pyarpackSparseBiCGILU.py.in" "${CMAKE_BINARY_DIR}/pyarpackSparseBiCGILU.py" @ONLY) add_test(NAME pyarpackSparseBiCGILU_tst COMMAND ${PYTHON_EXECUTABLE} pyarpackSparseBiCGILU.py) set_tests_properties(pyarpackSparseBiCGILU_tst PROPERTIES ENVIRONMENT PYTHONPATH=${CMAKE_BINARY_DIR}/lib:$ENV{PYTHONPATH}) configure_file("${PROJECT_SOURCE_DIR}/EXAMPLES/PYARPACK/pyarpackSparseCGDiag.py.in" "${CMAKE_BINARY_DIR}/pyarpackSparseCGDiag.py" @ONLY) add_test(NAME pyarpackSparseCGDiag_tst COMMAND ${PYTHON_EXECUTABLE} pyarpackSparseCGDiag.py) set_tests_properties(pyarpackSparseCGDiag_tst PROPERTIES ENVIRONMENT PYTHONPATH=${CMAKE_BINARY_DIR}/lib:$ENV{PYTHONPATH}) configure_file("${PROJECT_SOURCE_DIR}/EXAMPLES/PYARPACK/pyarpackSparseCGILU.py.in" "${CMAKE_BINARY_DIR}/pyarpackSparseCGILU.py" @ONLY) add_test(NAME pyarpackSparseCGILU_tst COMMAND ${PYTHON_EXECUTABLE} pyarpackSparseCGILU.py) set_tests_properties(pyarpackSparseCGILU_tst PROPERTIES ENVIRONMENT PYTHONPATH=${CMAKE_BINARY_DIR}/lib:$ENV{PYTHONPATH}) configure_file("${PROJECT_SOURCE_DIR}/EXAMPLES/PYARPACK/pyarpackSparseLLT.py.in" "${CMAKE_BINARY_DIR}/pyarpackSparseLLT.py" @ONLY) add_test(NAME pyarpackSparseLLT_tst COMMAND ${PYTHON_EXECUTABLE} pyarpackSparseLLT.py) set_tests_properties(pyarpackSparseLLT_tst PROPERTIES ENVIRONMENT PYTHONPATH=${CMAKE_BINARY_DIR}/lib:$ENV{PYTHONPATH}) configure_file("${PROJECT_SOURCE_DIR}/EXAMPLES/PYARPACK/pyarpackSparseLDLT.py.in" "${CMAKE_BINARY_DIR}/pyarpackSparseLDLT.py" @ONLY) add_test(NAME pyarpackSparseLDLT_tst COMMAND ${PYTHON_EXECUTABLE} pyarpackSparseLDLT.py) set_tests_properties(pyarpackSparseLDLT_tst PROPERTIES ENVIRONMENT PYTHONPATH=${CMAKE_BINARY_DIR}/lib:$ENV{PYTHONPATH}) configure_file("${PROJECT_SOURCE_DIR}/EXAMPLES/PYARPACK/pyarpackSparseLU.py.in" "${CMAKE_BINARY_DIR}/pyarpackSparseLU.py" @ONLY) add_test(NAME pyarpackSparseLU_tst COMMAND ${PYTHON_EXECUTABLE} pyarpackSparseLU.py) set_tests_properties(pyarpackSparseLU_tst PROPERTIES ENVIRONMENT PYTHONPATH=${CMAKE_BINARY_DIR}/lib:$ENV{PYTHONPATH}) configure_file("${PROJECT_SOURCE_DIR}/EXAMPLES/PYARPACK/pyarpackSparseQR.py.in" "${CMAKE_BINARY_DIR}/pyarpackSparseQR.py" @ONLY) add_test(NAME pyarpackSparseQR_tst COMMAND ${PYTHON_EXECUTABLE} pyarpackSparseQR.py) set_tests_properties(pyarpackSparseQR_tst PROPERTIES ENVIRONMENT PYTHONPATH=${CMAKE_BINARY_DIR}/lib:$ENV{PYTHONPATH}) configure_file("${PROJECT_SOURCE_DIR}/EXAMPLES/PYARPACK/pyarpackDenseLLT.py.in" "${CMAKE_BINARY_DIR}/pyarpackDenseLLT.py" @ONLY) add_test(NAME pyarpackDenseLLT_tst COMMAND ${PYTHON_EXECUTABLE} pyarpackDenseLLT.py) set_tests_properties(pyarpackDenseLLT_tst PROPERTIES ENVIRONMENT PYTHONPATH=${CMAKE_BINARY_DIR}/lib:$ENV{PYTHONPATH}) ``` -------------------------------- ### Create and Link Parallel Example Executables (CMake) Source: https://github.com/opencollab/arpack-ng/blob/master/CMakeLists.txt Defines a CMake function to create parallel executable targets from a list of source files. It links against 'parpack', 'arpack', and MPI, and sets up tests to run them using 'mpiexec'. ```cmake function(pexamples list_name) foreach(l ${${list_name}}) get_filename_component(lwe ${l} NAME_WE) add_executable(${lwe} ${parpackexample_DIR}/${l} ) target_link_libraries(${lwe} parpack arpack MPI::MPI_Fortran) add_test(NAME "${lwe}_ex" COMMAND mpiexec -n 2 ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${lwe}) endforeach() endfunction(pexamples) ``` -------------------------------- ### ARPACK-NG General Eigenvalue Solver (C++) Source: https://context7.com/opencollab/arpack-ng/llms.txt Illustrates the C++ interface for solving general (non-symmetric) eigenvalue problems using `arpack::naupd` and `arpack::neupd`. This example demonstrates automatic type dispatch for `std::complex` and includes a custom matrix-vector product within the reverse communication loop. ```cpp #include #include #include #include "arpack.hpp" int main() { const a_int N = 1000; const a_int nev = 9; const a_int ncv = 2 * nev + 1; const a_int lworkl = ncv * (3 * ncv + 5); const double tol = 1e-6; std::complex sigma(0.0, 0.0); std::vector> resid(N); std::vector> V(N * ncv); std::vector> d(nev); std::vector> z(N * nev); std::vector> workd(3 * N); std::vector> workl(lworkl); std::vector> workev(2 * ncv); std::vector rwork(ncv); std::vector select(ncv); a_int iparam[11] = {}, ipntr[14] = {}; iparam[0] = 1; iparam[2] = 10 * N; iparam[3] = 1; iparam[6] = 1; a_int info = 0, ido = 0; do { // Automatic type dispatch for complex arpack::naupd(ido, arpack::bmat::identity, N, arpack::which::largest_magnitude, nev, tol, resid.data(), ncv, V.data(), N, iparam, ipntr, workd.data(), workl.data(), lworkl, rwork.data(), info); if (ido == 1 || ido == -1) { // Complex matrix-vector product for (int i = 0; i < N; ++i) { workd[ipntr[1] - 1 + i] = workd[ipntr[0] - 1 + i] * std::complex(i + 1, -(i + 1)); } } } while (ido == 1 || ido == -1); arpack::neupd(0, arpack::howmny::ritz_vectors, select.data(), d.data(), z.data(), N, sigma, workev.data(), arpack::bmat::identity, N, arpack::which::largest_magnitude, nev, tol, resid.data(), ncv, V.data(), N, iparam, ipntr, workd.data(), workl.data(), lworkl, rwork.data(), info); for (int i = 0; i < nev; ++i) { std::cout << "lambda[" << i << "] = " << d[i] << std::endl; } return 0; } ``` -------------------------------- ### Configure CMake package export files Source: https://github.com/opencollab/arpack-ng/blob/master/CMakeLists.txt Generates and installs the necessary CMake configuration files to allow users to locate the ARPACK-NG package using the find_package command in their own projects. ```cmake configure_file(cmake/arpackng-config.cmake.in "${PROJECT_BINARY_DIR}/arpackng-config.cmake" @ONLY) configure_file(cmake/arpackng-config-version.cmake.in "${PROJECT_BINARY_DIR}/arpackng-config-version.cmake" @ONLY) install( FILES "${PROJECT_BINARY_DIR}/arpackng-config.cmake" "${PROJECT_BINARY_DIR}/arpackng-config-version.cmake" DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/arpackng${LIBSUFFIX}${ITF64SUFFIX}) ``` -------------------------------- ### Solve Sparse Eigenvalue Problems with C++ and Eigen Source: https://context7.com/opencollab/arpack-ng/llms.txt Utilizes the arpackSolver C++ class template to solve eigenvalue problems. Includes examples for standard sparse matrix solving and generalized shift-invert mode using direct solvers. ```cpp #include "arpackSolver.hpp" int main() { arpackItrSolver solver; EigSMxD A; solver.createMatrix("matrix.mtx", A); solver.symPb = true; solver.nbEV = 10; solver.nbCV = 2 * solver.nbEV + 1; solver.tol = 1.e-6; solver.mag = "LM"; solver.maxIt = 1000; solver.verbose = 1; solver.slvTol = 1.e-6; solver.slvMaxIt = 100; int rc = solver.solve(A); if (rc != 0) return 1; solver.checkEigVec(A); return 0; } ``` ```cpp #include "arpackSolver.hpp" int main() { arpackDrtSolver solver; EigSMxD A, B; solver.createMatrix("A.mtx", A); solver.createMatrix("B.mtx", B); solver.symPb = true; solver.nbEV = 5; solver.nbCV = 15; solver.tol = 1.e-8; solver.mag = "SM"; solver.sigmaReal = 0.5; solver.maxIt = 500; solver.slvPvtThd = 1.e-6; int rc = solver.solve(A, &B); return 0; } ``` -------------------------------- ### Solve Generalized Eigenvalue Problem with Python Source: https://context7.com/opencollab/arpack-ng/llms.txt Demonstrates setting up a generalized eigenvalue problem (A*x = lambda*B*x) using the pyarpack interface. It includes matrix construction, solver configuration with shift-invert mode, and result verification. ```python import numpy as np import pyarpackSlv n = 8 i = np.array([], dtype='int32') j = np.array([], dtype='int32') Aij = np.array([], dtype='float32') Bij = np.array([], dtype='float32') for k in range(n): for l in [k-1, k, k+1]: if l < 0 or l > n-1: continue i = np.append(i, np.int32(k)) j = np.append(j, np.int32(l)) if l == k: Aij = np.append(Aij, np.float32(200.)) Bij = np.append(Bij, np.float32(33.3)) else: Aij = np.append(Aij, np.float32(-100.)) Bij = np.append(Bij, np.float32(16.6)) A = (n, i, j, Aij) B = (n, i, j, Bij) arpackSlv = pyarpackSlv.float() arpackSlv.nbEV = 2 arpackSlv.nbCV = 2 * arpackSlv.nbEV + 1 arpackSlv.mag = 'LM' arpackSlv.maxIt = 200 arpackSlv.sigmaReal = 1.0 arpackSlv.slvTol = 1.e-6 arpackSlv.slvMaxIt = 100 rc = arpackSlv.solve(A, B) assert rc == 0, "Solve failed" rc = arpackSlv.checkEigVec(A, B, 1.e-2) assert rc == 0, "Eigenvector check failed" for val, vec in zip(arpackSlv.val, arpackSlv.vec): print(f"Eigenvalue: {val}") ``` -------------------------------- ### Build and Integrate arpack-ng Source: https://context7.com/opencollab/arpack-ng/llms.txt Provides instructions for building arpack-ng from source using CMake or Autotools, and how to integrate the library into external projects using CMake. ```bash git clone https://github.com/opencollab/arpack-ng.git cd arpack-ng mkdir build && cd build cmake -D EXAMPLES=ON -D ICB=ON -D MPI=ON -D EIGEN=ON -D PYTHON3=ON -D BUILD_SHARED_LIBS=ON .. make -j4 make check sudo make install ``` ```bash sh bootstrap ./configure --enable-mpi --enable-icb make make check sudo make install ``` ```cmake find_package(arpackng REQUIRED) add_executable(myapp main.cpp) target_include_directories(myapp PUBLIC ARPACK::ARPACK) target_link_libraries(myapp ARPACK::ARPACK) ``` -------------------------------- ### Configure arpack-ng with ISO_C_BINDING (Bash) Source: https://github.com/opencollab/arpack-ng/blob/master/README.md These commands demonstrate how to enable ISO_C_BINDING support when configuring the arpack-ng project. This allows for seamless interoperability between Fortran and C/C++ code. ```bash ./configure --enable-icb cmake -D ICB=ON ``` -------------------------------- ### Summarize Library Include Paths and Link Libraries Source: https://github.com/opencollab/arpack-ng/blob/master/CMakeLists.txt The `libsummary` function is used to display compile-time include paths and link-time libraries for a given library. It iterates through provided include directories and libraries, printing them in a formatted manner. ```cmake function(libsummary title include libraries) message(" -- ${title}:") foreach(inc ${include}) message(" -- compile: ${inc}") endforeach() foreach(lib ${libraries}) message(" -- link: ${lib}") endforeach() endfunction(libsummary) ``` -------------------------------- ### Summarize EIGEN and Python Dependencies Source: https://github.com/opencollab/arpack-ng/blob/master/CMakeLists.txt This snippet summarizes the include directory for the EIGEN3 library if it's found. It also summarizes the include paths, libraries, and executable for Python 3 and the Boost libraries if Python 3 support is enabled. ```cmake if (EIGEN) libsummary("EIGEN3" "${EIGEN3_INCLUDE_DIR}" "") endif() if (PYTHON3) libsummary("PYTHON" "${PYTHON_INCLUDE_DIRS}" "${PYTHON_LIBRARIES}") message(" -- exe: ${PYTHON_EXECUTABLE}") libsummary("BOOST" "${Boost_INCLUDE_DIRS}" "${Boost_LIBRARIES}") endif() ``` -------------------------------- ### Define Parallel Library (parpack) Source: https://github.com/opencollab/arpack-ng/blob/master/CMakeLists.txt Conditionally defines the parallel library 'parpack' if MPI is enabled. It links against the 'arpack' library and the MPI Fortran library for both installation and build interfaces. Target properties for output name, version, and SOVERSION are also configured. ```cmake if (MPI) # use -DBUILD_SHARED_LIBS=ON|OFF to control static/shared add_library(parpack ${parpacksrc_STAT_SRCS} ${parpackutil_STAT_SRCS} ${parpacksrc_ICB}) target_link_libraries(parpack PUBLIC arpack $,,MPI::MPI_Fortran>> $ ) set_target_properties(parpack PROPERTIES OUTPUT_NAME parpack${LIBSUFFIX}${ITF64SUFFIX}) set_target_properties(parpack PROPERTIES VERSION 2.1.0) set_target_properties(parpack PROPERTIES SOVERSION 2) endif () ``` -------------------------------- ### Define arpack Library Source: https://github.com/opencollab/arpack-ng/blob/master/CMakeLists.txt Defines the static or shared library 'arpack' using specified source files. It links against LAPACK and BLAS libraries, both for installation and build interfaces. Public link options and target properties like output name, version, and SOVERSION are also set. ```cmake add_library(arpack ${arpackutil_STAT_SRCS} ${arpacksrc_STAT_SRCS} ${arpacksrc_ICB}) target_link_libraries(arpack PUBLIC $,,LAPACK::LAPACK>> $,,BLAS::BLAS>> $ $ ) target_link_options(arpack PUBLIC "${EXTRA_LDFLAGS}") set_target_properties(arpack PROPERTIES OUTPUT_NAME arpack${LIBSUFFIX}${ITF64SUFFIX}) set_target_properties(arpack PROPERTIES VERSION 2.1.0) set_target_properties(arpack PROPERTIES SOVERSION 2) target_include_directories(arpack PUBLIC # Exported location of headers $ # Find arpackdef.h, arpackicb.h, stat*.h, debug*.h at build time $ $ # For ICB interface $ ) ``` -------------------------------- ### Solve Sparse Eigenvalue Problem with pyarpack in Python Source: https://context7.com/opencollab/arpack-ng/llms.txt Shows how to define a sparse matrix in COO format and configure the pyarpack solver to compute eigenvalues. It includes steps for solver configuration, execution, and result verification. ```python #!/usr/bin/env python import numpy as np from pyarpack import sparseBiCGDiag as pyarpackSlv n = 4 i = np.array([], dtype='int32') j = np.array([], dtype='int32') Aij = np.array([], dtype='float64') for k in range(n): for l in [k-1, k, k+1]: if l < 0 or l > n-1: continue i = np.append(i, np.int32(k)) j = np.append(j, np.int32(l)) if l == k: Aij = np.append(Aij, np.float64(200.)) else: Aij = np.append(Aij, np.float64(-100.)) A = (n, i, j, Aij) arpackSlv = pyarpackSlv.double() arpackSlv.nbEV = 2 arpackSlv.nbCV = 2 * arpackSlv.nbEV + 1 arpackSlv.mag = 'LM' arpackSlv.maxIt = 200 arpackSlv.tol = 1.e-6 arpackSlv.verbose = 1 rc = arpackSlv.solve(A) assert rc == 0, "Solve failed" rc = arpackSlv.checkEigVec(A) assert rc == 0, "Eigenvector check failed" print(f"Mode: {arpackSlv.mode}") print(f"Iterations: {arpackSlv.nbIt}") print(f"RCI time: {arpackSlv.rciTime}s") for val, vec in zip(arpackSlv.val, arpackSlv.vec): print(f"Eigenvalue: {val}") print(f"Eigenvector: {vec}") ``` -------------------------------- ### Configure arpack-ng with Eigen and ISO_C_BINDING (Bash) Source: https://github.com/opencollab/arpack-ng/blob/master/README.md This command sequence shows how to configure the arpack-ng build using CMake, enabling support for both ISO_C_BINDING and the Eigen C++ template library for advanced eigensolver functionalities. ```bash mkdir build cd build cmake -D EXAMPLES=ON -D ICB=ON -D EIGEN=ON .. make all check ``` -------------------------------- ### dsaupd: Solve Real Symmetric Eigenvalue Problem (Fortran) Source: https://context7.com/opencollab/arpack-ng/llms.txt The `dsaupd` routine computes eigenvalues and eigenvectors for real symmetric matrices using the Implicitly Restarted Lanczos Method. It employs reverse communication to obtain matrix-vector products from the user. This example demonstrates solving a standard eigenvalue problem (A*x = λ*x) for the 4 largest magnitude eigenvalues. ```Fortran c Solve A*x = lambda*x for a symmetric matrix (2D Laplacian) c Find the 4 largest magnitude eigenvalues program dssimp integer maxn, maxnev, maxncv, ldv parameter (maxn=256, maxnev=10, maxncv=25, ldv=maxn) Double precision v(ldv,maxncv), workl(maxncv*(maxncv+8)), & workd(3*maxn), d(maxncv,2), resid(maxn) logical select(maxncv) integer iparam(11), ipntr(11) character bmat*1, which*2 integer ido, n, nev, ncv, lworkl, info Double precision tol, sigma c Problem setup n = 100 ! Matrix dimension nev = 4 ! Number of eigenvalues requested ncv = 20 ! Number of Arnoldi vectors (ncv > nev) bmat = 'I' ! Standard eigenvalue problem which = 'LM' ! Largest magnitude eigenvalues tol = 0.0D+0 ! Use machine precision lworkl = ncv*(ncv+8) c Algorithm parameters iparam(1) = 1 ! Exact shifts iparam(3) = 300 ! Maximum iterations iparam(7) = 1 ! Mode 1: A*x = lambda*x info = 0 ! Random starting vector ido = 0 ! First call c Reverse Communication Loop 10 continue call dsaupd(ido, bmat, n, which, nev, tol, resid, & ncv, v, ldv, iparam, ipntr, workd, workl, & lworkl, info) if (ido .eq. -1 .or. ido .eq. 1) then c Compute Y = A * X (user-supplied matrix-vector product) call av(n, workd(ipntr(1)), workd(ipntr(2))) go to 10 end if c Check for errors if (info .lt. 0) then print *, 'Error in dsaupd, info =', info stop end if end ``` -------------------------------- ### Verify Fortran ISO_C_BINDING support with CMake Source: https://github.com/opencollab/arpack-ng/blob/master/CMakeLists.txt Checks if the current Fortran compiler supports the ISO_C_BINDING module by attempting to compile a temporary program. If compilation fails, it triggers a fatal error to prevent build issues. ```cmake if (ICB) file(WRITE ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/PROG_ICB.f90 "\n PROGRAM PROG_ICB\n USE iso_c_binding\n IMPLICIT NONE\n INTEGER(C_INT) :: a\n a = 1\n END PROGRAM PROG_ICB\n ") try_compile(COMPILE_ICB ${CMAKE_BINARY_DIR} ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/PROG_ICB.f90) if(NOT ${COMPILE_ICB}) message(FATAL_ERROR "-- Fortran compiler does not support iso_c_binding.") else() message("-- Fortran compiler does support iso_c_binding.") endif() endif() ``` -------------------------------- ### Solve Double Precision Non-Symmetric Eigenvalue Problem (Fortran) Source: https://context7.com/opencollab/arpack-ng/llms.txt The `dnaupd` and `dneupd` routines solve non-symmetric real eigenvalue problems A*x = lambda*x using the Implicitly Restarted Arnoldi Method. They require setup of problem dimensions, desired eigenvalue criteria, and workspace arrays. The reverse communication loop handles matrix-vector products, and `dneupd` extracts the computed eigenvalues. ```fortran c Solve non-symmetric eigenvalue problem A*x = lambda*x integer maxn, maxnev, maxncv, ldv parameter (maxn=256, maxnev=10, maxncv=25, ldv=maxn) Double precision v(ldv,maxncv), workl(3*maxncv*maxncv+6*maxncv), & workd(3*maxn), dr(maxnev+1), di(maxnev+1), & workev(3*maxncv), resid(maxn) logical select(maxncv) integer iparam(11), ipntr(14) character bmat*1, which*2 integer ido, n, nev, ncv, lworkl, info Double precision tol, sigmar, sigmai c Problem setup for non-symmetric matrix n = 100 nev = 4 ncv = 20 bmat = 'I' which = 'LM' ! Largest magnitude (also: 'SR', 'LR', 'SI', 'LI') tol = 0.0D+0 lworkl = 3*ncv*ncv + 6*ncv iparam(1) = 1 ! Exact shifts iparam(3) = 300 ! Max iterations iparam(7) = 1 ! Mode 1 info = 0 ido = 0 c Reverse Communication Loop 10 continue call dnaupd(ido, bmat, n, which, nev, tol, resid, & ncv, v, ldv, iparam, ipntr, workd, workl, & lworkl, info) if (ido .eq. -1 .or. ido .eq. 1) then call av(n, workd(ipntr(1)), workd(ipntr(2))) go to 10 end if c Extract results (eigenvalues may be complex: dr + i*di) rvec = .true. sigmar = 0.0D+0 sigmai = 0.0D+0 call dneupd(rvec, 'A', select, dr, di, v, ldv, & sigmar, sigmai, workev, bmat, n, which, nev, & tol, resid, ncv, v, ldv, iparam, ipntr, & workd, workl, lworkl, info) c Print complex eigenvalues nconv = iparam(5) do j = 1, nconv print *, 'Eigenvalue', j, ':', dr(j), '+', di(j), 'i' end do ``` -------------------------------- ### Find and Configure MPI Library (CMake) Source: https://github.com/opencollab/arpack-ng/blob/master/CMakeLists.txt This snippet finds the MPI library, checks for Fortran, C, and CXX components, and sets up CMake targets for them. It includes compatibility checks for older CMake versions and verifies ISO_C_BINDING support. It also sets Fortran compiler flags based on the compiler. ```cmake if (MPI) if (NOT TARGET MPI::MPI_Fortran) # Search only if not already found by upper CMakeLists.txt include(FindMPI) find_package(MPI REQUIRED COMPONENTS Fortran) # MPI::MPI_* target was already created at this point by FindMPI.cmake if cmake version >= 3.9 if (NOT TARGET MPI::MPI_Fortran) # Create target "at hand" to ensure compatibility if cmake version < 3.9 add_library(MPI::MPI_Fortran INTERFACE IMPORTED) set_target_properties(MPI::MPI_Fortran PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${MPI_Fortran_INCLUDE_DIRS}") set_target_properties(MPI::MPI_Fortran PROPERTIES INTERFACE_LINK_LIBRARIES "${MPI_Fortran_LIBRARIES}") endif() endif() set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${MPI_Fortran_COMPILE_FLAG}") if(CMAKE_SYSTEM_NAME MATCHES "Windows" AND CMAKE_Fortran_COMPILER_ID MATCHES "GNU") set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fallow-invalid-boz") endif() # Check if we can use ISO_C_BINDING provided by MPI. file(WRITE ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/PROG_ICB.f90 " PROGRAM PROG_ICB USE :: mpi_f08 IMPLICIT NONE type(MPI_Comm) comm type(MPI_Status) status END PROGRAM PROG_ICB ") try_compile(COMPILE_ICB ${CMAKE_BINARY_DIR} ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/PROG_ICB.f90 LINK_LIBRARIES MPI::MPI_Fortran) if(NOT ${COMPILE_ICB}) message("-- MPI library does not support iso_c_binding.") set(HAVE_MPI_ICB 0) else() message("-- MPI library does support iso_c_binding.") set(HAVE_MPI_ICB 1) add_compile_definitions(HAVE_MPI_ICB=1) endif() # As MPI can be used with or without ISO_C_BINDING (#ifdef), we need to preprocess code before compiling. if ("${CMAKE_Fortran_COMPILER_ID}" MATCHES "GNU") set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -cpp") elseif ("${CMAKE_Fortran_COMPILER_ID}" MATCHES "Intel") set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fpp") else () message(WARNING "build script does not know how to preprocess Fortran code: set it manually via FFLAGS.") endif () if(ICB) if (NOT TARGET MPI::MPI_C) # Search only if not already found by upper CMakeLists.txt include(FindMPI) find_package(MPI REQUIRED COMPONENTS C) if (NOT TARGET MPI::MPI_C) # Create target "at hand" to ensure compatibility if cmake version < 3.9 add_library(MPI::MPI_C INTERFACE IMPORTED) set_target_properties(MPI::MPI_C PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${MPI_C_INCLUDE_DIRS}") set_target_properties(MPI::MPI_C PROPERTIES INTERFACE_LINK_LIBRARIES "${MPI_C_LIBRARIES}") endif() endif() if (NOT TARGET MPI::MPI_CXX) # Search only if not already found by upper CMakeLists.txt include(FindMPI) find_package(MPI REQUIRED COMPONENTS CXX) if (NOT TARGET MPI::MPI_CXX) # Create target "at hand" to ensure compatibility if cmake version < 3.9 add_library(MPI::MPI_CXX INTERFACE IMPORTED) set_target_properties(MPI::MPI_CXX PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${MPI_CXX_INCLUDE_DIRS}") set_target_properties(MPI::MPI_CXX PROPERTIES INTERFACE_LINK_LIBRARIES "${MPI_CXX_LIBRARIES}") endif() endif() include(CheckSymbolExists) check_symbol_exists(MPI_Comm_c2f "${MPI_C_INCLUDE_DIRS}/mpi.h" MPI_Comm_c2f_FOUND) if(NOT ${MPI_Comm_c2f_FOUND}) message(FATAL_ERROR "symbol MPI_Comm_c2f does not exist") endif() endif() endif() ``` -------------------------------- ### Configure arpack-ng with Python3, Eigen, and ISO_C_BINDING (Bash) Source: https://github.com/opencollab/arpack-ng/blob/master/README.md This command demonstrates configuring arpack-ng with CMake to enable Python3 support, leveraging ISO_C_BINDING and Eigen for a C++ eigensolver accessible from Python. This requires creating a build directory and navigating into it. ```bash mkdir build cd build cmake -D EXAMPLES=ON -D ICB=ON -D EIGEN=ON -D PYTHON3=ON .. make all check ``` -------------------------------- ### Clone arpack-ng Repository (Bash) Source: https://github.com/opencollab/arpack-ng/blob/master/README.md These commands show how to download the arpack-ng source code from GitHub using either the HTTPS or SSH protocol. After cloning, you navigate into the newly created directory. ```bash $ git clone https://github.com/opencollab/arpack-ng.git $ cd ./arpack-ng ``` ```bash $ git clone git@github.com:opencollab/arpack-ng.git $ cd ./arpack-ng ``` -------------------------------- ### Solve Complex Eigenvalue Problems with znaupd_c and zneupd_c Source: https://context7.com/opencollab/arpack-ng/llms.txt Demonstrates the implementation of a complex eigenvalue solver in C. It handles complex matrix-vector products and utilizes the zneupd_c routine for post-processing. ```c #include #include #include "arpack.h" /* Complex matrix-vector product */ void zMatVec(const a_dcomplex* x, a_dcomplex* y, int n) { for (int i = 0; i < n; ++i) { y[i] = x[i] * CMPLX(i + 1.0, i + 1.0); } } int main() { const a_int N = 1000; const a_int nev = 9; const a_int ncv = 2 * nev + 1; const a_int lworkl = ncv * (3 * ncv + 5); a_dcomplex *resid = calloc(N, sizeof(a_dcomplex)); a_dcomplex *V = calloc(N * ncv, sizeof(a_dcomplex)); a_dcomplex *d = calloc(nev, sizeof(a_dcomplex)); a_dcomplex *workd = calloc(3 * N, sizeof(a_dcomplex)); a_dcomplex *workl = calloc(lworkl, sizeof(a_dcomplex)); a_dcomplex *workev = calloc(2 * ncv, sizeof(a_dcomplex)); double *rwork = calloc(ncv, sizeof(double)); a_int *select = calloc(ncv, sizeof(a_int)); a_int iparam[11] = {0}, ipntr[14] = {0}; iparam[0] = 1; iparam[2] = 10 * N; iparam[3] = 1; iparam[6] = 1; char bmat[] = "I", which[] = "LM", howmny[] = "A"; a_dcomplex sigma = CMPLX(0., 0.); a_int info = 0, ido = 0; do { znaupd_c(&ido, bmat, N, which, nev, 1e-6, resid, ncv, V, N, iparam, ipntr, workd, workl, lworkl, rwork, &info); if (ido == 1 || ido == -1) { zMatVec(&workd[ipntr[0] - 1], &workd[ipntr[1] - 1], N); } } while (ido == 1 || ido == -1); a_dcomplex *z = calloc(N * nev, sizeof(a_dcomplex)); zneupd_c(0, howmny, select, d, z, N, sigma, workev, bmat, N, which, nev, 1e-6, resid, ncv, V, N, iparam, ipntr, workd, workl, lworkl, rwork, &info); for (int i = 0; i < nev; ++i) { printf("lambda[%d] = %f + %fi\n", i, creal(d[i]), cimag(d[i])); } return 0; } ```