Gyselalib++
 
Loading...
Searching...
No Matches
MatrixBatchEll< ExecSpace > Class Template Reference

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

Inheritance diagram for MatrixBatchEll< ExecSpace >:
MatrixBatch< ExecSpace >

Public Member Functions

 MatrixBatchEll (const int batch_size, const int mat_size, const int non_zeros_per_row, std::optional< int > max_iter=std::nullopt, std::optional< double > res_tol=std::nullopt, std::optional< bool > logger=std::nullopt)
 The constructor for MatrixBatchEll class.
 
 MatrixBatchEll (Kokkos::View< int **, Kokkos::LayoutLeft, ExecSpace > cols_idx, Kokkos::View< double ***, Kokkos::LayoutStride, ExecSpace > batch_values, std::optional< int > max_iter=std::nullopt, std::optional< double > res_tol=std::nullopt, std::optional< bool > logger=std::nullopt)
 Constructor for MatrixBatchEll class.
 
std::pair< Kokkos::View< int **, Kokkos::LayoutLeft, ExecSpace >, Kokkos::View< double ***, Kokkos::LayoutStride, ExecSpace > > get_batch_ell ()
 A function to get information about values and indices for the whole batch.
 
double get_ell_element (int batch_idx, int line_idx, int non_zero_col_idx) const
 A getter function for a value located at a specified place.
 
void set_ell_element (int batch_idx, int line_idx, int non_zero_col_idx, double aij)
 A setter function to modify a value located at a specified place.
 
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.
 
double norm (int batch_idx) const
 A function returns 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>
class MatrixBatchEll< ExecSpace >

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. The sparsity pattern is assumed to be the same for all matrices. ie the non-zero components are located at the same places for all matrices. This class uses the ELL storage format which needs two 1D arrays, one stores values the other column indices. The class returns these arrays (as Kokkos views) with the get_batch_idx_and_vals function, it is then possible to fill them outside the class. 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

Constructor & Destructor Documentation

◆ MatrixBatchEll() [1/2]

template<class ExecSpace >
MatrixBatchEll< ExecSpace >::MatrixBatchEll ( const int  batch_size,
const int  mat_size,
const int  non_zeros_per_row,
std::optional< int >  max_iter = std::nullopt,
std::optional< double >  res_tol = std::nullopt,
std::optional< bool >  logger = std::nullopt 
)
inlineexplicit

The constructor for MatrixBatchEll class.

Parameters
[in]batch_sizeNumber of linear systems to solve.
[in]mat_sizeCommon matrix size for all the systems.
[in]non_zeros_per_rownumber of non zero components per line.
[in]max_itermaximal number of iterations for the solver
[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.

◆ MatrixBatchEll() [2/2]

template<class ExecSpace >
MatrixBatchEll< ExecSpace >::MatrixBatchEll ( Kokkos::View< int **, Kokkos::LayoutLeft, ExecSpace >  cols_idx,
Kokkos::View< double ***, Kokkos::LayoutStride, ExecSpace >  batch_values,
std::optional< int >  max_iter = std::nullopt,
std::optional< double >  res_tol = std::nullopt,
std::optional< bool >  logger = std::nullopt 
)
inlineexplicit

Constructor for MatrixBatchEll class.

Parameters
[in]cols_idxA Kokkos view which stores the column indices of non-zero components.
[in]batch_valuesA Kokkos view which stores the values of non-zero elements.
[in]max_itermaximal number of iterations for the solver, default 500.
[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.

Member Function Documentation

◆ get_batch_ell()

template<class ExecSpace >
std::pair< Kokkos::View< int **, Kokkos::LayoutLeft, ExecSpace >, Kokkos::View< double ***, Kokkos::LayoutStride, ExecSpace > > MatrixBatchEll< ExecSpace >::get_batch_ell ( )
inline

A function to get information about values and indices for the whole batch.

Data is managed by two Kokkos Views stored on the host.

Returns
idx_view Column indices for the non-zero values.
vals_view The non-zero values.

◆ get_ell_element()

template<class ExecSpace >
double MatrixBatchEll< ExecSpace >::get_ell_element ( int  batch_idx,
int  line_idx,
int  non_zero_col_idx 
) const
inline

A getter function for a value located at a specified place.

Parameters
[in]batch_idxIndex in the batch.
[in]line_idxLine index inside the matrix.
[in]non_zero_col_idxNon-zero index element in the line.
Returns
value of the component.

◆ set_ell_element()

template<class ExecSpace >
void MatrixBatchEll< ExecSpace >::set_ell_element ( int  batch_idx,
int  line_idx,
int  non_zero_col_idx,
double  aij 
)
inline

A setter function to modify a value located at a specified place.

Parameters
[in]batch_idxIndex in the batch.
[in]line_idxLine index inside the matrix.
[in]non_zero_col_idxNon-zero index element in the line.
[in]aijNew value.

◆ setup_solver()

template<class ExecSpace >
void MatrixBatchEll< ExecSpace >::setup_solver ( )
inlinefinalvirtual

Perform a pre-process operation on the solver.

Must be called after filling the matrix.

It uses parameters like maximum number of iterations and tolerance are 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()

template<class ExecSpace >
void MatrixBatchEll< ExecSpace >::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 >.

◆ norm()

template<class ExecSpace >
double MatrixBatchEll< ExecSpace >::norm ( int  batch_idx) const
inline

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

Parameters
[in]batch_idxinteger, index of the matrix in the batch.
Returns
value of the matrix infinite-norm.

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