![]() |
Block-Structured AMR Software Framework
|
Distributed CSR matrix that manages storage and GPU-friendly partitions. More...
#include <AMReX_SpMatrix.H>
Classes | |
| struct | CommMV |
| struct | CommTR |
| struct | RemoteRowsMM |
| Rows of another matrix fetched for SpGEMM. Column indices are global. More... | |
Public Types | |
| using | value_type = T |
| template<class U > | |
| using | allocator_type = Allocator< U > |
| template<class U > | |
| using | container_type = PODVector< U, Allocator< U > > |
| using | csr_type = CSR< T, container_type > |
| using | AllocT = Allocator< T > |
Public Member Functions | |
| SpMatrix ()=default | |
| SpMatrix (AlgPartition partition, int nnz_per_row) | |
| Construct a sparse matrix with a fixed number of nonzeros per row. | |
| SpMatrix (AlgPartition partition, csr_type csr) | |
| Construct a sparse matrix from a given Partition and CSR. | |
| SpMatrix (SpMatrix const &)=delete | |
| SpMatrix & | operator= (SpMatrix const &)=delete |
| SpMatrix (SpMatrix &&)=default | |
| SpMatrix & | operator= (SpMatrix &&)=default |
| ~SpMatrix ()=default | |
| void | define (AlgPartition partition, int nnz_per_row) |
| Allocate storage for a default-constructed matrix with a fixed number of nonzeros per row. | |
| void | define (AlgPartition partition, T const *mat, Long const *col_index, Long nentries, Long const *row_offset, CsrSorted is_sorted, CsrValid is_valid) |
| Define a default-constructed matrix from given CSR arrays. | |
| void | define (AlgPartition partition, csr_type csr, CsrSorted is_sorted) |
| Define a default-constructed matrix from a given CSR. | |
| AlgPartition const & | partition () const |
| Row partition describing how matrix rows are distributed across ranks. | |
| AlgPartition const & | columnPartition () const |
| Return the column partition used for matrix-vector and matrix-matrix multiplications. | |
| Long | numLocalRows () const |
| Number of rows owned by this rank. | |
| Long | numGlobalRows () const |
| Global row count. | |
| Long | numLocalNonZeros () const |
| Number of nonzeros stored locally. | |
| Long | globalRowBegin () const |
| Inclusive global index begin on this process. | |
| Long | globalRowEnd () const |
| Exclusive global index end on this process. | |
| T * | data () |
| Don't use this beyond initial setup. | |
| Long * | columnIndex () |
| Don't use this beyond initial setup. | |
| Long * | rowOffset () |
| Don't use this beyond initial setup. | |
| void | printToFile (std::string const &file) const |
| template<typename F > | |
| void | setVal (F const &f, CsrSorted is_sorted) |
| Initialize matrix entries using a row-wise functor. | |
| void | sortCSR () |
| void | setColumnPartition (AlgPartition const &col_partition) |
| AlgVector< T, AllocT > const & | diagonalVector () const |
| Return diagonal elements in a square matrix. | |
| AlgVector< T, AllocT > | rowSum () const |
| Sum the values in each local row and return the result as an AlgVector. | |
| ParCsr< T > | parcsr () |
| Build GPU-friendly CSR views split into diagonal/off-diagonal blocks. | |
| ParCsr< T const > | parcsr () const |
| Const variant of parcsr(). | |
| ParCsr< T const > | const_parcsr () const |
| Const-qualified alias of parcsr() for convenience. | |
| void | define_doit (int nnz_per_row) |
Private helper (exposed for CUDA) that allocates fixed-connectivity matrices with nnz_per_row entries. | |
| template<typename I > | |
| void | define_and_filter_doit (T const *mat, Long const *col_index, Long nentries, Long const *row_offset) |
| Private helper (exposed for CUDA) that copies/filters CSR arrays into device storage. | |
| void | startComm_mv (AlgVector< T, AllocT > const &x) |
Prepare halo exchanges for a subsequent SpMV using x as the source vector. | |
| void | finishComm_mv (AlgVector< T, AllocT > &y) |
Finish halo exchanges and accumulate contributions into y. | |
| void | startComm_tr (AlgPartition const &col_partition) |
Initiate communication required to build the transpose with column partition col_partition. | |
| void | finishComm_tr (SpMatrix< T, Allocator > &AT) |
Complete transpose communication, writing the assembled matrix into AT. | |
| void | split_csr (AlgPartition const &col_partition) |
| template<typename C > | |
| void | update_remote_col_index (C &csrr, bool in_device_memory) |
| void | prepare_comm_mv (AlgPartition const &col_partition) |
| void | pack_buffer_mv (AlgVector< T, AllocT > const &v) |
| void | unpack_buffer_mv (AlgVector< T, AllocT > &v) |
| void | comm_tr_recv_wait () |
| void | comm_tr_clear () |
| void | unpack_buffer_tr (CommTR const &ctr, AlgPartition const &col_partition) |
| void | expand_remote_row_offset () const |
| CsrView< T const > | remote_full_const_view () const |
| Off-diagonal part with the full (untrimmed) row offsets. | |
| RemoteRowsMM | fetch_remote_rows_mm (SpMatrix< T, Allocator > const &B) |
Public Attributes | |
| struct amrex::SpMatrix::CommMV | m_comm_mv |
| struct amrex::SpMatrix::CommTR | m_comm_tr |
Friends | |
| template<typename U > | |
| class | AMG |
| template<typename U , template< typename > class M, typename N > | |
| void | SpMV (AlgVector< U, N > &y, SpMatrix< U, M > const &A, AlgVector< U, N > const &x) |
| template<typename U , template< typename > class M> | |
| SpMatrix< U, M > | transpose (SpMatrix< U, M > const &A, AlgPartition const &col_partition) |
| template<typename U , template< typename > class M> | |
| SpMatrix< U, M > | SpGEMM (SpMatrix< U, M > const &A, SpMatrix< U, M > const &B, AlgPartition const &col_partition) |
Distributed CSR matrix that manages storage and GPU-friendly partitions.
| using amrex::SpMatrix< T, Allocator >::allocator_type = Allocator<U> |
| using amrex::SpMatrix< T, Allocator >::AllocT = Allocator<T> |
| using amrex::SpMatrix< T, Allocator >::container_type = PODVector<U,Allocator<U> > |
| using amrex::SpMatrix< T, Allocator >::csr_type = CSR<T,container_type> |
| using amrex::SpMatrix< T, Allocator >::value_type = T |
|
default |
| amrex::SpMatrix< T, Allocator >::SpMatrix | ( | AlgPartition | partition, |
| int | nnz_per_row | ||
| ) |
Construct a sparse matrix with a fixed number of nonzeros per row.
This constructor allocates the required storage and initializes the row offsets. The matrix entries themselves are left uninitialized. Matrix values can be written through the pointer returned by data() and the corresponding column indices through the pointer returned by the columnIndex(). Alternatively, the matrix may be initialized using setVal(). In either case, the CSR data must not contain duplicated entries or invalid entries (i.e., negative column indices). If the matrix is set manually through pointers and the entries within each row are not sorted by column index, the user must call sortCSR after all data have been set.
| partition | Parallel partition information. |
| nnz_per_row | Number of nonzeros per row. |
| amrex::SpMatrix< T, Allocator >::SpMatrix | ( | AlgPartition | partition, |
| csr_type | csr | ||
| ) |
Construct a sparse matrix from a given Partition and CSR.
The input CSR represents the portion of the matrix local to this process. It must be both sorted and valid. Moreover, it should not have duplicated entries.
| partition | Parallel partition information. |
| csr | CSR represents of the matrix local to this process. |
|
delete |
|
default |
|
default |
|
inline |
Don't use this beyond initial setup.
|
inline |
Return the column partition used for matrix-vector and matrix-matrix multiplications.
This partition corresponds to the row partition of the vector or matrix appearing on the right-hand side of a multiplication.
| void amrex::SpMatrix< T, Allocator >::comm_tr_clear | ( | ) |
| void amrex::SpMatrix< T, Allocator >::comm_tr_recv_wait | ( | ) |
| ParCsr< T const > amrex::SpMatrix< T, Allocator >::const_parcsr | ( | ) | const |
Const-qualified alias of parcsr() for convenience.
|
inline |
Don't use this beyond initial setup.
| void amrex::SpMatrix< T, Allocator >::define | ( | AlgPartition | partition, |
| csr_type | csr, | ||
| CsrSorted | is_sorted | ||
| ) |
| void amrex::SpMatrix< T, Allocator >::define | ( | AlgPartition | partition, |
| int | nnz_per_row | ||
| ) |
Allocate storage for a default-constructed matrix with a fixed number of nonzeros per row.
This allocates the required storage and initializes the row offsets. The matrix entries themselves are left uninitialized. Matrix values can be written through the pointer returned by data() and the corresponding column indices through the pointer returned by the columnIndex(). Alternatively, the matrix may be initialized using setVal().
| partition | Parallel partition information. |
| nnz_per_row | Number of nonzeros per row. |
| void amrex::SpMatrix< T, Allocator >::define | ( | AlgPartition | partition, |
| T const * | mat, | ||
| Long const * | col_index, | ||
| Long | nentries, | ||
| Long const * | row_offset, | ||
| CsrSorted | is_sorted, | ||
| CsrValid | is_valid | ||
| ) |
Define a default-constructed matrix from given CSR arrays.
The CSR arrays describe the portion of the matrix local to this process.
If is_valid indicates that the input CSR may contain invalid entries, this function will filter the input and omit such entries from the resulting matrix. An entry is considered invalid if its column index is negative. In addition, when is_valid is false, this function also removes entries whose values are zero. The input CSR is not allowed to contain duplicated valid entries.
It is not an error to specify is_sorted = false when the input CSR is in fact sorted, nor to specify is_valid = false when the input CSR contains no invalid entries. In these cases, the result is correct, but the function may perform unnecessary work and therefore result in a performance penalty. If the input properties are not known, it is safe to set both flags to false.
The input data can be freed after this function call. For GPU builds, the data are expected to be in GPU memory.
| partition | Parallel partition information. |
| mat | CSR values array (length nentries). |
| col_index | CSR column indices array (length nentries). |
| nentries | Number of entries. |
| row_offset | CSR row offsets array (length num_local_rows + 1). |
| is_sorted | Indicates whether the CSR entries are sorted (within each row). |
| is_valid | Indicates whether the input CSR is guaranteed to be valid (i.e., contains no negative column indices). |
| void amrex::SpMatrix< T, Allocator >::define_and_filter_doit | ( | T const * | mat, |
| Long const * | col_index, | ||
| Long | nentries, | ||
| Long const * | row_offset | ||
| ) |
Private helper (exposed for CUDA) that copies/filters CSR arrays into device storage.
| I | Prefix-scan index type. |
| mat | Input values array. |
| col_index | Input column indices. |
| nentries | Number of candidate entries. |
| row_offset | Row offsets array. |
| void amrex::SpMatrix< T, Allocator >::define_doit | ( | int | nnz_per_row | ) |
Private helper (exposed for CUDA) that allocates fixed-connectivity matrices with nnz_per_row entries.
| AlgVector< T, Allocator< T > > const & amrex::SpMatrix< T, Allocator >::diagonalVector | ( | ) | const |
Return diagonal elements in a square matrix.
| void amrex::SpMatrix< T, Allocator >::expand_remote_row_offset | ( | ) | const |
| auto amrex::SpMatrix< T, Allocator >::fetch_remote_rows_mm | ( | SpMatrix< T, Allocator > const & | B | ) |
Fetch the rows of B listed in m_remote_cols_v. This matrix must already be split with B's row partition. Collective.
| void amrex::SpMatrix< T, Allocator >::finishComm_mv | ( | AlgVector< T, AllocT > & | y | ) |
Finish halo exchanges and accumulate contributions into y.
| void amrex::SpMatrix< T, Allocator >::finishComm_tr | ( | SpMatrix< T, Allocator > & | AT | ) |
Complete transpose communication, writing the assembled matrix into AT.
|
inline |
Inclusive global index begin on this process.
|
inline |
Exclusive global index end on this process.
|
inline |
Global row count.
|
inline |
Number of nonzeros stored locally.
|
inline |
Number of rows owned by this rank.
|
default |
|
delete |
| void amrex::SpMatrix< T, Allocator >::pack_buffer_mv | ( | AlgVector< T, AllocT > const & | v | ) |
| ParCsr< T > amrex::SpMatrix< T, Allocator >::parcsr | ( | ) |
Build GPU-friendly CSR views split into diagonal/off-diagonal blocks.
The returned structure aliases the underlying storage; do not outlive this matrix.
| ParCsr< T const > amrex::SpMatrix< T, Allocator >::parcsr | ( | ) | const |
Const variant of parcsr().
|
inline |
Row partition describing how matrix rows are distributed across ranks.
| void amrex::SpMatrix< T, Allocator >::prepare_comm_mv | ( | AlgPartition const & | col_partition | ) |
| void amrex::SpMatrix< T, Allocator >::printToFile | ( | std::string const & | file | ) | const |
| CsrView< T const > amrex::SpMatrix< T, Allocator >::remote_full_const_view | ( | ) | const |
Off-diagonal part with the full (untrimmed) row offsets.
|
inline |
Don't use this beyond initial setup.
| AlgVector< T, Allocator< T > > amrex::SpMatrix< T, Allocator >::rowSum | ( | ) | const |
Sum the values in each local row and return the result as an AlgVector.
Each MPI rank receives the row sums for the rows it owns; if further reductions are needed they should be performed on the returned vector.
| void amrex::SpMatrix< T, Allocator >::setColumnPartition | ( | AlgPartition const & | col_partition | ) |
Set column partition. This is usually not needed to be called by the user.
| void amrex::SpMatrix< T, Allocator >::setVal | ( | F const & | f, |
| CsrSorted | is_sorted | ||
| ) |
Initialize matrix entries using a row-wise functor.
The functor must have the signature
and is responsible for setting the global column indices and values for the row specified by the global row index. The two pointers point to the beginning of the specified row.
This function is intended to be used after define(AlgPartition,int), when the storage has been allocated. It should only be used during initial matrix setup and not for modifying an already assembled matrix.
The CSR data must not contain duplicated entries or invalid entries (i.e., negative column indices).
| f | Functor void(Long,Long*,T*) |
| is_sorted | Indicates whether the CSR entries are sorted (within each row). |
| void amrex::SpMatrix< T, Allocator >::sortCSR | ( | ) |
Sort CSR by column index withint each row. This is intended to be used after the user sets the matrix manually or with setVal.
| void amrex::SpMatrix< T, Allocator >::split_csr | ( | AlgPartition const & | col_partition | ) |
| void amrex::SpMatrix< T, Allocator >::startComm_mv | ( | AlgVector< T, AllocT > const & | x | ) |
Prepare halo exchanges for a subsequent SpMV using x as the source vector.
Must be paired with finishComm_mv(); only available when MPI is enabled.
| void amrex::SpMatrix< T, Allocator >::startComm_tr | ( | AlgPartition const & | col_partition | ) |
Initiate communication required to build the transpose with column partition col_partition.
| void amrex::SpMatrix< T, Allocator >::unpack_buffer_mv | ( | AlgVector< T, AllocT > & | v | ) |
| void amrex::SpMatrix< T, Allocator >::unpack_buffer_tr | ( | CommTR const & | ctr, |
| AlgPartition const & | col_partition | ||
| ) |
| void amrex::SpMatrix< T, Allocator >::update_remote_col_index | ( | C & | csrr, |
| bool | in_device_memory | ||
| ) |
|
friend |
|
friend |
|
friend |
|
friend |
| struct amrex::SpMatrix::CommMV amrex::SpMatrix< T, Allocator >::m_comm_mv |
| struct amrex::SpMatrix::CommTR amrex::SpMatrix< T, Allocator >::m_comm_tr |