ARPACK-NG

repository·master·Indexed 43 days ago

https://github.com/opencollab/arpack-ng

A community-maintained collection of Fortran77 subroutines for solving large-scale eigenvalue problems. It serves as a modern replacement for the original ARPACK, featuring improved support for ILP64, ISO_C_BINDING, Eigen, and Python (via pyarpack). The library includes the Reverse Communication Interface (RCI) and PARPACK for parallel eigenvalue problems using MPI.

Tokens
7.3K
Snippets
25
Records
44
Agent score
56%

What's inside ARPACK-NG

  1. Understand the arpack-ng directory structure

    master

    The repository is organized into several key functional areas:

    • SRC/: Contains top-level routines and the highest-level Reverse Communication Interface (RCI) routines (e.g., ssaupd, dsaupd, snaupd, dnaupd, cnaupd, znaupd). The headers for these routines contain full documentation of calling sequences.
    • PARPACK/: Contains the Parallel ARPACK routines.
    • DOCUMENTS/: Contains template files (ex-sym.doc, ex-nonsym.doc, ex-complex.doc) for invoking computational modes.
    • EXAMPLES/: Contains driver programs for various modes. Key subdirectories include:
      • BAND: Banded matrices
      • COMPLEX: Complex arithmetic
      • NONSYM: Non-symmetric problems
      • SIMPLE: Basic usage for common eigenvalue problems
      • SVD: Singular Value Decomposition
      • SYM: Symmetric problems
      • PYARPACK: Python examples
      • MATRIX_MARKET: Matrix Market file testing (requires Eigen).
    • TESTS/ and PARPACK/TESTS/MPI/: Contain examples of ISO_C_BINDING usage.
  2. Provide eigenvalue and eigenvector estimates to arpack

    master

    Providing an Eigenvalue Estimate

    To provide an estimate of an eigenvalue, you must apply a shift of approximately that amount to lambda. For implementation details, refer to the backTransform function in arpackSolver.hpp.

    Providing an Eigenvector Estimate

    To provide an estimate of an eigenvector:

    1. Copy the estimate into the vector v (do not put it in resid).
    2. Set info to 1 before calling the aupd methods.

    This ensures the algorithm targets a non-null vector where A*v = lambda*v.

  3. Enable ISO_C_BINDING support

    master

    ISO_C_BINDING (ICB) allows for safe and seamless interoperability between Fortran and C/C++. When enabled, the installation provides arpack.h/hpp and parpack.h/hpp.

    Usage Pattern:

    1. Compile arpack-ng with the --enable-icb flag (autotools) or -D ICB=ON (CMake).
    2. In your C code, #include "arpack.h".
    3. Replace standard Fortran calls (e.g., [sdcz][ae]upd) with their ICB-compliant counterparts (e.g., [sdcz][ae]upd_c). These suffixed functions expose the same arguments as the original Fortran functions but are typed for C compatibility.
    # Using autotools
    $ ./configure --enable-icb
    
    # Using CMake
    $ cmake -D ICB=ON
  4. Use Intel MKL instead of BLAS/LAPACK

    master

    To use arpack-ng with Intel MKL (oneAPI/oneMKL):

    1. Detection: Let your build system (Autotools or CMake) find MKL via pkg-config (by setting PKG_CONFIG_PATH) or via CMake options:

      • For lp64: BLA_VENDOR=Intel10_64lp
      • For ilp64: BLA_VENDOR=Intel10_64ilp
    2. Verification: Use the Intel Link Advisor to determine correct flags. Ensure your build system uses the exact flags expected by Intel by checking the output (e.g., using make VERBOSE=1).

  5. Install arpack-ng via CMake

    master

    To build and install arpack-ng using CMake, create a build directory within the source directory. This method allows for easy configuration of features like MPI and shared libraries.

    Note: You will need sudo privileges to install the library to your system's standard location.

    $ mkdir build
    $ cd build
    $ cmake -D EXAMPLES=ON -D MPI=ON -D BUILD_SHARED_LIBS=ON ..
    $ make
    $ sudo make install
  6. Install arpack-ng on macOS

    master

    When using GNU compilers on macOS, you may need to customize the configuration flags to ensure compatibility with the Accelerate framework and to handle underscore naming conventions. Run the following command from the source directory:

    $ LIBS="-framework Accelerate" FFLAGS="-ff2c -fno-second-underscore" FCFLAGS="-ff2c -fno-second-underscore" ./configure
  7. Integrate arpack-ng into an Autotools project

    master

    To use arpack-ng with Autotools, ensure you have pkg-config installed.

    1. Set the PKG_CONFIG_PATH environment variable to the installation directory containing arpack.pc.
    2. Add the following lines to your configure.ac file to detect and substitute the necessary flags:
    PKG_CHECK_MODULES([ARPACK], [arpack])
    AC_SUBST([ARPACK_CFLAGS])
    AC_SUBST([ARPACK_LIBS])
  8. Install arpack-ng via autotools

    master

    To build and install arpack-ng using the autotools build system, follow these steps in the source directory. This process builds the library, including examples and parallel support using MPI if enabled.

    Note: You will need sudo privileges to install the library to your system's standard location.

    $ sh bootstrap
    $ ./configure --enable-mpi
    $ make
    $ make check
    $ sudo make install
  9. Integrate arpack-ng into a CMake project

    master

    To use arpack-ng in CMake, use the ARPACK::ARPACK target.

    Important: You must update the CMAKE_MODULE_PATH environment variable so that find_package(arpackng) can locate the arpack-ng CMake files.

    Using standard ARPACK

    FIND_PACKAGE(arpackng)
    ADD_EXECUTABLE(main main.f)
    TARGET_INCLUDE_DIRECTORIES(main PUBLIC ARPACK::ARPACK)
    TARGET_LINK_LIBRARIES(main ARPACK::ARPACK)

    Using PARPACK (Parallel ARPACK)

    When using PARPACK, you must also find and link the MPI component (specifically the Fortran interface):

    FIND_PACKAGE(arpackng)
    FIND_PACKAGE(MPI REQUIRED COMPONENTS Fortran)
    ADD_EXECUTABLE(main main.f)
    TARGET_INCLUDE_DIRECTORIES(main PUBLIC PARPACK::PARPACK)
    TARGET_LINK_LIBRARIES(main PARPACK::PARPACK)
    TARGET_INCLUDE_DIRECTORIES(main PUBLIC MPI::MPI_Fortran)
    TARGET_LINK_LIBRARIES(main MPI::MPI_Fortran)
  10. Install arpack-ng on Windows

    master

    You can install arpack-ng on Windows using one of the following package managers:

    1. MSYS2: Use pacman to install the MinGW-w64 package: pacman -S mingw-w64-x86_64-arpack

    2. vcpkg: Use the vcpkg command: vcpkg install arpack-ng

    pacman -S mingw-w64-x86_64-arpack
    vcpkg install arpack-ng
  11. Explore ARPACK example drivers

    master

    The EXAMPLES directory contains driver programs that demonstrate how to call ARPACK subroutines __aupd.f and __eupd.f to solve eigenvalue problems. These drivers illustrate how to configure various ARPACK parameters for different modes, including regular, shift-invert, Cayley, and Bucking modes.

    Users can modify these drivers and provide their own matrix-vector multiplication routines to solve specific problems. The examples are organized by problem type:

    • SIMPLE: Simple drivers for beginners.
    • SYM: Symmetric eigenvalue problems.
    • NONSYM: Nonsymmetric eigenvalue problems.
    • COMPLEX: Eigenvalue problems with complex matrices.
    • BAND: Eigenvalue problems with banded matrices.
    • SVD: Singular Value Decomposition (computing singular values and vectors of an $m \times n$ matrix).
  12. Ensure data type consistency in pyarpack

    master

    Because pyarpack interfaces directly with C++, you must ensure that the Python/Numpy data types exactly match the solver's expected C++ types. There is no automatic type checking at the C++ side; incorrect types will cause the C++ layer to fail to read the data.

    Mandatory Steps for Consistency:

    1. Explicitly define Numpy dtypes: Use dtype='complex128', dtype='float64', etc.
    2. Cast values on append: When building arrays, you must cast values explicitly (e.g., np.complex128(value)).
    3. Match Solver Flavor: The solver instance must match the array type (e.g., complexDouble() for complex128).

    Mapping Reference:

    • pyarpackSlv.complexDouble() $\Leftrightarrow$ np.array(..., dtype='complex128')

    Debugging: If you suspect type mismatches, set arckSlv.debug = 1 to view debug traces.

    import numpy as np
    from pyarpack import sparseBiCG as pyarpackSlv
    
    # CORRECT: Explicitly specifying type
    Aij = np.array([], dtype='complex128')
    
    # CORRECT: Casting value on append is MANDATORY
    Aij = np.append(Aij, np.complex128(complex(200., 200.)))
    
    # CORRECT: Solver flavor matches numpy dtype
    arckSlv = pyarpackSlv.complexDouble()
    
    # Debugging
    arckSlv.debug = 1