This example demonstrates the use of the rocALUTION library for eigenvalue approximation using the Power Method and solving linear systems using Chebyshev iteration.
The example covers three main operations:
- Power Method for Eigenvalue Approximation: Estimates the maximum and minimum eigenvalues of a matrix
- Chebyshev Iteration: Solves linear systems using Chebyshev polynomial iteration
- CG with Chebyshev Preconditioner: Combines Conjugate Gradient with Approximate Inverse Chebyshev preconditioning
- Parse command line arguments for matrix file path and OMP thread count.
- Initialize the rocALUTION platform and configure thread settings.
- Print rocALUTION platform information.
- Create rocALUTION objects and read the matrix from MTX format file.
- Gershgorin Circle Theorem: Compute initial eigenvalue bounds using Gershgorin approximation.
- Move objects to the accelerator and allocate vectors for power iteration.
- Power Method for λ_max:
- Initialize vector to ones and iterate matrix-vector multiplications
- Normalize vectors and compute Rayleigh quotient for maximum eigenvalue
- Power Method for λ_min:
- Modify matrix by subtracting λ_max from diagonal
- Apply power method to find minimum eigenvalue of shifted matrix
- Restore original matrix and compute actual minimum eigenvalue
- Chebyshev Iteration:
- Set up Chebyshev solver with computed eigenvalue bounds
- Solve linear system using Chebyshev polynomial iteration
- CG with AIChebyshev Preconditioner:
- Set up Approximate Inverse Chebyshev preconditioner
- Solve linear system using CG with Chebyshev preconditioning
- Compute and report errors for both solving approaches.
- Clear solver resources and stop the rocALUTION platform.
-
rocALUTION Platform Management: The rocALUTION library is initialized with
rocalution::init_rocalution()and terminated withrocalution::stop_rocalution(). Platform information can be obtained usingrocalution::info_rocalution(), and OMP thread count can be configured withrocalution::set_omp_threads_rocalution(). -
Matrix Operations:
-
rocalution::LocalMatrix::ReadFileMTX(): Loads a matrix from Matrix Market format file. -
rocalution::LocalMatrix::Gershgorin(): Computes eigenvalue bounds using Gershgorin Circle Theorem. -
rocalution::LocalMatrix::AddScalarDiagonal(): Adds a scalar value to the matrix diagonal. -
rocalution::LocalMatrix::Apply(): Performs matrix-vector multiplication$y = Ax$ . -
rocalution::LocalMatrix::Info(): Prints matrix information including dimensions and format.
-
-
Vector Operations:
-
rocalution::LocalVector::Allocate(): Allocates memory for a vector with specified size and name. -
rocalution::LocalVector::Ones(): Initializes all vector elements to value 1. -
rocalution::LocalVector::Scale(): Scales vector elements by a scalar value. -
rocalution::LocalVector::Norm(): Computes the L2 norm (Euclidean norm) of the vector. -
rocalution::LocalVector::Dot(): Computes the dot product of two vectors. -
rocalution::LocalVector::CloneBackend(): Clones the backend (host/device) configuration from another object. -
rocalution::LocalVector::Zeros(): Initializes all vector elements to value 0. -
rocalution::LocalVector::ScaleAdd(): Computes vector operation$y = \alpha \cdot x + y$ .
-
-
Eigenvalue Approximation:
- Power Method: Iterative algorithm to find extreme eigenvalues through repeated matrix-vector multiplication and normalization.
-
Rayleigh Quotient: Computed as
$\lambda = \frac{x^T A x}{x^T x}$ to estimate eigenvalues.
-
Solver Configuration:
-
rocalution::IterativeLinearSolver::SetOperator(): Associates the linear system matrix with the solver. -
rocalution::IterativeLinearSolver::SetPreconditioner(): Configures the preconditioner for accelerated convergence. -
rocalution::IterativeLinearSolver::Build(): Initializes solver data structures and preconditioner. -
rocalution::IterativeLinearSolver::Solve(): Executes the iterative solver to find the solution. -
rocalution::IterativeLinearSolver::Clear(): Releases solver resources and memory.
-
-
Chebyshev-Specific Configuration:
-
rocalution::Chebyshev::Set(): Sets eigenvalue bounds for Chebyshev polynomial iteration. -
rocalution::AIChebyshev::Set(): Configures Approximate Inverse Chebyshev preconditioner with polynomial degree and eigenvalue bounds.
-
-
Performance Measurement:
-
rocalution::rocalution_time(): Returns high-resolution timer value for performance measurement.
-
rocalution::init_rocalutionrocalution::stop_rocalutionrocalution::info_rocalutionrocalution::set_omp_threads_rocalutionrocalution::rocalution_time
rocalution::LocalMatrix::ReadFileMTXrocalution::LocalMatrix::Gershgorinrocalution::LocalMatrix::AddScalarDiagonalrocalution::LocalMatrix::Applyrocalution::LocalMatrix::Inforocalution::LocalMatrix::GetMrocalution::LocalMatrix::GetNrocalution::LocalMatrix::MoveToAccelerator
rocalution::LocalVector::Allocaterocalution::LocalVector::Onesrocalution::LocalVector::Scalerocalution::LocalVector::Normrocalution::LocalVector::Dotrocalution::LocalVector::CloneBackendrocalution::LocalVector::Zerosrocalution::LocalVector::ScaleAddrocalution::LocalVector::MoveToAccelerator
rocalution::Chebyshev<rocalution::LocalMatrix<double>, rocalution::LocalVector<double>, double>rocalution::CG<rocalution::LocalMatrix<double>, rocalution::LocalVector<double>, double>rocalution::AIChebyshev<rocalution::LocalMatrix<double>, rocalution::LocalVector<double>, double>
rocalution::IterativeLinearSolver::SetOperatorrocalution::IterativeLinearSolver::SetPreconditionerrocalution::IterativeLinearSolver::Buildrocalution::IterativeLinearSolver::Solverocalution::IterativeLinearSolver::Clearrocalution::Chebyshev::Setrocalution::AIChebyshev::Set
rocalution::LocalMatrix<double>rocalution::LocalVector<double>