Gyselalib++
 
Loading...
Searching...
No Matches
MatrixBatchCsr< ExecSpace, Solver > Class Template Reference

Matrix class which is able to manage and solve a batch of sparse linear systems. More...

Inheritance diagram for MatrixBatchCsr< ExecSpace, Solver >:
MatrixBatch< ExecSpace >

Public Member Functions

 MatrixBatchCsr (const int batch_size, const int mat_size, const int nnz_per_system, std::optional< int > max_iter=std::nullopt, std::optional< double > res_tol=std::nullopt, std::optional< bool > logger=std::nullopt, std::optional< int > preconditionner_max_block_size=1u)
 The constructor for MatrixBatchCsr class.
 
 MatrixBatchCsr (Kokkos::View< double **, Kokkos::LayoutRight, ExecSpace > batch_values, Kokkos::View< int *, Kokkos::LayoutRight, ExecSpace > cols_idx, Kokkos::View< int *, Kokkos::LayoutRight, ExecSpace > nnz_per_row, std::optional< int > max_iter=std::nullopt, std::optional< double > res_tol=std::nullopt, std::optional< bool > logger=std::nullopt, std::optional< int > preconditionner_max_block_size=1u)
 Constructor for MatrixBatchCsr class.
 
std::tuple< Kokkos::View< double **, Kokkos::LayoutRight, ExecSpace >, Kokkos::View< int *, Kokkos::LayoutRight, ExecSpace >, Kokkos::View< int *, Kokkos::LayoutRight, ExecSpace > > get_batch_csr ()
 A function to update information about values,indices and the number of non-zero per row for the whole batch.
 
void setup_solver () final
 Perform a pre-process operation on the solver.
 
void solve (BatchedRHS const b) const final
 Solve the batched linear problem Ax=b.
 
void solve (BatchedRHS const x, BatchedRHS const b) const
 Solve the batched linear problem Ax=b.
 
double norm (int batch_idx) const
 A function returning the norm of a matrix located at batch_idx.
 
- Public Member Functions inherited from MatrixBatch< ExecSpace >
virtual ~MatrixBatch ()=default
 Destruct.
 
std::size_t size () const
 Get the size of the square matrix corresponding to a single batch in one of its dimensions.
 
std::size_t batch_size () const
 Get the batch size of the linear problem.
 

Additional Inherited Members

- Public Types inherited from MatrixBatch< ExecSpace >
using BatchedRHS = Kokkos::View< double **, Kokkos::LayoutRight, ExecSpace >
 The type of a Kokkos::View storing batched right-hand sides. Second dimenion is batch dimension.
 
- Protected Member Functions inherited from MatrixBatch< ExecSpace >
 MatrixBatch (const std::size_t batch_size, const std::size_t mat_size)
 The constructor for MatrixBatch class.
 

Detailed Description

template<class ExecSpace, MatrixBatchCsrSolver Solver = MatrixBatchCsrSolver::BICGSTAB>
class MatrixBatchCsr< ExecSpace, Solver >

Matrix class which is able to manage and solve a batch of sparse linear systems.

Executes on either CPU or GPU. It takes advantage of the sparse structure, and the only batched solver available in Ginkgo : Stabilized Bicg. This class uses the CSR storage format which needs three arrays, one stores values, the other column indices. The third array contains the count of non-zero inside the matrix lines.(eg:for a given line index i nn_per_row[i]= sum of non-zeros until line i) The class returns these arrays (as Kokkos views) with the get_csr_views function, it is then possible to fill them outside the class. The sparsity pattern is the same for all matrices, hence column indices are stored only for one system. Tolerance and maximal number of iterations, which are parameters for the iterative solver, are set in the constructor. It is possibile to get convergence information by activating the logger at constructor call.

Template Parameters
ExecSpaceExecution space,needed by Kokkos for allocations and parallelism. The simplest choice is to follow Kokkos, for that: specify Kokkos::DefaultExecutionSpace
SolverRefers to the solver type, default value is the Bicgstab which is more general. The use of a CG solver is also possible, in this case, please make sure that matrices structure fulfils CG requirements.

Constructor & Destructor Documentation

◆ MatrixBatchCsr() [1/2]

template<class ExecSpace , MatrixBatchCsrSolver Solver = MatrixBatchCsrSolver::BICGSTAB>
MatrixBatchCsr< ExecSpace, Solver >::MatrixBatchCsr ( const int  batch_size,
const int  mat_size,
const int  nnz_per_system,
std::optional< int >  max_iter = std::nullopt,
std::optional< double >  res_tol = std::nullopt,
std::optional< bool >  logger = std::nullopt,
std::optional< int >  preconditionner_max_block_size = 1u 
)
inlineexplicit

The constructor for MatrixBatchCsr class.

Parameters
[in]batch_sizeNumber of linear systems to solve.
[in]mat_sizeCommon matrix size for all the systems.
[in]nnz_per_systemNumber of non-zero components per matrix.
[in]max_itermaximal number of iterations for the solver, default 1000.
[in]res_tolresidual tolerance parameter, to ensure convergence. Be careful! the relative residual provided here, will be used as "implicit residual" in ginkgo solver.
[in]loggerboolean parameter for saving log informations such residual and interations count.
[in]preconditionner_max_block_sizeAn optional parameter used to define the maximum size of a block

◆ MatrixBatchCsr() [2/2]

template<class ExecSpace , MatrixBatchCsrSolver Solver = MatrixBatchCsrSolver::BICGSTAB>
MatrixBatchCsr< ExecSpace, Solver >::MatrixBatchCsr ( Kokkos::View< double **, Kokkos::LayoutRight, ExecSpace >  batch_values,
Kokkos::View< int *, Kokkos::LayoutRight, ExecSpace >  cols_idx,
Kokkos::View< int *, Kokkos::LayoutRight, ExecSpace >  nnz_per_row,
std::optional< int >  max_iter = std::nullopt,
std::optional< double >  res_tol = std::nullopt,
std::optional< bool >  logger = std::nullopt,
std::optional< int >  preconditionner_max_block_size = 1u 
)
inlineexplicit

Constructor for MatrixBatchCsr class.

Parameters
[in]batch_valuesA 2D Kokkos view which stores the values of non-zero elements for the whole batch.
[in]cols_idxA 1D Kokkos view which stores the column indices for each non-zero component.(only for one matrix)
[in]nnz_per_rowA 1D Kokkos view of length matrix_size+1 which stores the count of the non-zeros along the lines of the matrix. It is defined as: nnz_per_row[0] = 0. nnz_per_row[matrix_size] = total_number_of_nonzero. To get the number of non-zero for a line i,one have to compute : n_non_zeros_at_line_in = nnz_per_row[i+1]-nnz_per_row[i].
[in]max_itermaximal number of iterations for the solver, default 1000.
[in]res_tolresidual tolerance parameter, to ensure convergence. Be careful! The residual provided here, set as relative residual, will be used as "implicit residual" in ginkgo solver. Default value is set to 1e-15.
[in]loggerbolean parameter to save logger information. Default value false.
[in]preconditionner_max_block_sizeAn optional parameter used to define the maximum size of a block

Member Function Documentation

◆ get_batch_csr()

template<class ExecSpace , MatrixBatchCsrSolver Solver = MatrixBatchCsrSolver::BICGSTAB>
std::tuple< Kokkos::View< double **, Kokkos::LayoutRight, ExecSpace >, Kokkos::View< int *, Kokkos::LayoutRight, ExecSpace >, Kokkos::View< int *, Kokkos::LayoutRight, ExecSpace > > MatrixBatchCsr< ExecSpace, Solver >::get_batch_csr ( )
inline

A function to update information about values,indices and the number of non-zero per row for the whole batch.

Data is managed by Kokkos Views stored on the host.

Returns
vals_view A 2D Kokkos view which stores the values of non-zero elements for the whole batch.
col_idx_view A 1D Kokkos view which stores the column indices for each non-zero component.(only for one matrix)
nnz_per_row_view A 1D Kokkos view which stores the count of non-zero per line, in an additive way. see nnz_per_row parameter in constructor.

◆ setup_solver()

template<class ExecSpace , MatrixBatchCsrSolver Solver = MatrixBatchCsrSolver::BICGSTAB>
void MatrixBatchCsr< ExecSpace, Solver >::setup_solver ( )
inlinefinalvirtual

Perform a pre-process operation on the solver.

Must be called after filling the matrix.

It uses the batch of matrices to generate a batched Jacobi preconditioner. Other parameters like maximum number of iterations and tolerance are also used to instantiate a Ginkgo solver.

The stopping criterion is a reduction factor ||Ax-b||/||b||<tol with max_iter maximum iterations.

Implements MatrixBatch< ExecSpace >.

◆ solve() [1/2]

template<class ExecSpace , MatrixBatchCsrSolver Solver = MatrixBatchCsrSolver::BICGSTAB>
void MatrixBatchCsr< ExecSpace, Solver >::solve ( BatchedRHS const  b) const
inlinefinalvirtual

Solve the batched linear problem Ax=b.

Parameters
[in,out]bA 2D Kokkos::View storing the batched right-hand sides of the problem and receiving the corresponding solutions.

Implements MatrixBatch< ExecSpace >.

◆ solve() [2/2]

template<class ExecSpace , MatrixBatchCsrSolver Solver = MatrixBatchCsrSolver::BICGSTAB>
void MatrixBatchCsr< ExecSpace, Solver >::solve ( BatchedRHS const  x,
BatchedRHS const  b 
) const
inline

Solve the batched linear problem Ax=b.

Parameters
[in]xA 2D Kokkos::View storing the batched inital guests (useful for iterative solver) of the problems, and receiving the corresponding solutions.
[in]bA 2D Kokkos::View storing the batched right-hand side of the problems.

◆ norm()

template<class ExecSpace , MatrixBatchCsrSolver Solver = MatrixBatchCsrSolver::BICGSTAB>
double MatrixBatchCsr< ExecSpace, Solver >::norm ( int  batch_idx) const
inline

A function returning the norm of a matrix located at batch_idx.

Parameters
[in]batch_idxThe index of the matrix in the batch.
Returns
The value of the matrix infinite-norm.

The documentation for this class was generated from the following file: