Block-Structured AMR Software Framework
Loading...
Searching...
No Matches
amrex::SpMatrix< T, Allocator > Class Template Reference

#include <AMReX_SpMatrix.H>

Classes

struct  CommMV
 
struct  CommTR
 

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
 
SpMatrixoperator= (SpMatrix const &)=delete
 
 SpMatrix (SpMatrix &&)=default
 
SpMatrixoperator= (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
 
AlgPartition const & columnPartition () const
 Return the column partition used for matrix-vector and matrix-matrix multiplications.
 
Long numLocalRows () const
 
Long numGlobalRows () const
 
Long numLocalNonZeros () const
 
Long globalRowBegin () const
 Inclusive global index begin.
 
Long globalRowEnd () const
 Exclusive global index end.
 
T * data ()
 Don't use this beyond initial setup.
 
LongcolumnIndex ()
 Don't use this beyond initial setup.
 
LongrowOffset ()
 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 ()
 
AlgVector< T, AllocT > const & diagonalVector () const
 Return diagonal elements in a square matrix.
 
AlgVector< T, AllocTrowSum () const
 Return row-sum vector.
 
ParCsr< T > parcsr ()
 
ParCsr< T const > parcsr () const
 
ParCsr< T const > const_parcsr () const
 
void define_doit (int nnz_per_row)
 Private function, but public for cuda.
 
template<typename I >
void define_and_filter_doit (T const *mat, Long const *col_index, Long nentries, Long const *row_offset)
 Private function, but public for cuda.
 
void startComm_mv (AlgVector< T, AllocT > const &x)
 
void finishComm_mv (AlgVector< T, AllocT > &y)
 
void startComm_tr (AlgPartition const &col_partition)
 
void finishComm_tr (SpMatrix< T, Allocator > &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 unpack_buffer_tr (CommTR const &ctr, AlgPartition const &col_partition)
 

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 col_partition)
 

Member Typedef Documentation

◆ allocator_type

template<typename T , template< typename > class Allocator = DefaultAllocator>
template<class U >
using amrex::SpMatrix< T, Allocator >::allocator_type = Allocator<U>

◆ AllocT

template<typename T , template< typename > class Allocator = DefaultAllocator>
using amrex::SpMatrix< T, Allocator >::AllocT = Allocator<T>

◆ container_type

template<typename T , template< typename > class Allocator = DefaultAllocator>
template<class U >
using amrex::SpMatrix< T, Allocator >::container_type = PODVector<U,Allocator<U> >

◆ csr_type

template<typename T , template< typename > class Allocator = DefaultAllocator>
using amrex::SpMatrix< T, Allocator >::csr_type = CSR<T,container_type>

◆ value_type

template<typename T , template< typename > class Allocator = DefaultAllocator>
using amrex::SpMatrix< T, Allocator >::value_type = T

Constructor & Destructor Documentation

◆ SpMatrix() [1/5]

template<typename T , template< typename > class Allocator = DefaultAllocator>
amrex::SpMatrix< T, Allocator >::SpMatrix ( )
default

◆ SpMatrix() [2/5]

template<typename T , template< typename > class Allocator>
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.

Parameters
partitionParallel partition information.
nnz_per_rowNumber of nonzeros per row.

◆ SpMatrix() [3/5]

template<typename T , template< typename > class Allocator>
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 duplicagted entries.

Parameters
partitionParallel partition information.
csrCSR represents of the matrix local to this process.

◆ SpMatrix() [4/5]

template<typename T , template< typename > class Allocator = DefaultAllocator>
amrex::SpMatrix< T, Allocator >::SpMatrix ( SpMatrix< T, Allocator > const &  )
delete

◆ SpMatrix() [5/5]

template<typename T , template< typename > class Allocator = DefaultAllocator>
amrex::SpMatrix< T, Allocator >::SpMatrix ( SpMatrix< T, Allocator > &&  )
default

◆ ~SpMatrix()

template<typename T , template< typename > class Allocator = DefaultAllocator>
amrex::SpMatrix< T, Allocator >::~SpMatrix ( )
default

Member Function Documentation

◆ columnIndex()

template<typename T , template< typename > class Allocator = DefaultAllocator>
Long * amrex::SpMatrix< T, Allocator >::columnIndex ( )
inline

Don't use this beyond initial setup.

◆ columnPartition()

template<typename T , template< typename > class Allocator = DefaultAllocator>
AlgPartition const & amrex::SpMatrix< T, Allocator >::columnPartition ( ) const
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.

◆ const_parcsr()

template<typename T , template< typename > class Allocator>
ParCsr< T const > amrex::SpMatrix< T, Allocator >::const_parcsr ( ) const

◆ data()

template<typename T , template< typename > class Allocator = DefaultAllocator>
T * amrex::SpMatrix< T, Allocator >::data ( )
inline

Don't use this beyond initial setup.

◆ define() [1/3]

template<typename T , template< typename > class Allocator>
void amrex::SpMatrix< T, Allocator >::define ( AlgPartition  partition,
csr_type  csr,
CsrSorted  is_sorted 
)

Define a default-constructed matrix from a given CSR.

The input CSR represents the portion of the matrix local to this process. It must be valid. Moreover, it should not have duplicagted entries.

Parameters
partitionParallel partition information.
csrCSR represents of the matrix local to this process.
is_sortedIndicates whether the CSR entries are sorted (within each row).

◆ define() [2/3]

template<typename T , template< typename > class Allocator>
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().

Parameters
partitionParallel partition information.
nnz_per_rowNumber of nonzeros per row.

◆ define() [3/3]

template<typename T , template< typename > class Allocator>
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.

Parameters
partitionParallel partition information.
matCSR values array (length nentries).
col_indexCSR column indices array (length nentries).
nentriesNumber of entries.
row_offsetCSR row offsets array (length num_local_rows + 1).
is_sortedIndicates whether the CSR entries are sorted (within each row).
is_validIndicates whether the input CSR is guaranteed to be valid (i.e., contains no negative column indices).

◆ define_and_filter_doit()

template<typename T , template< typename > class Allocator>
template<typename I >
void amrex::SpMatrix< T, Allocator >::define_and_filter_doit ( T const *  mat,
Long const *  col_index,
Long  nentries,
Long const *  row_offset 
)

Private function, but public for cuda.

◆ define_doit()

template<typename T , template< typename > class Allocator>
void amrex::SpMatrix< T, Allocator >::define_doit ( int  nnz_per_row)

Private function, but public for cuda.

◆ diagonalVector()

template<typename T , template< typename > class Allocator>
AlgVector< T, Allocator< T > > const & amrex::SpMatrix< T, Allocator >::diagonalVector ( ) const

Return diagonal elements in a square matrix.

◆ finishComm_mv()

template<typename T , template< typename > class Allocator>
void amrex::SpMatrix< T, Allocator >::finishComm_mv ( AlgVector< T, AllocT > &  y)

◆ finishComm_tr()

template<typename T , template< typename > class Allocator>
void amrex::SpMatrix< T, Allocator >::finishComm_tr ( SpMatrix< T, Allocator > &  AT)

◆ globalRowBegin()

template<typename T , template< typename > class Allocator = DefaultAllocator>
Long amrex::SpMatrix< T, Allocator >::globalRowBegin ( ) const
inline

Inclusive global index begin.

◆ globalRowEnd()

template<typename T , template< typename > class Allocator = DefaultAllocator>
Long amrex::SpMatrix< T, Allocator >::globalRowEnd ( ) const
inline

Exclusive global index end.

◆ numGlobalRows()

template<typename T , template< typename > class Allocator = DefaultAllocator>
Long amrex::SpMatrix< T, Allocator >::numGlobalRows ( ) const
inline

◆ numLocalNonZeros()

template<typename T , template< typename > class Allocator = DefaultAllocator>
Long amrex::SpMatrix< T, Allocator >::numLocalNonZeros ( ) const
inline

◆ numLocalRows()

template<typename T , template< typename > class Allocator = DefaultAllocator>
Long amrex::SpMatrix< T, Allocator >::numLocalRows ( ) const
inline

◆ operator=() [1/2]

template<typename T , template< typename > class Allocator = DefaultAllocator>
SpMatrix & amrex::SpMatrix< T, Allocator >::operator= ( SpMatrix< T, Allocator > &&  )
default

◆ operator=() [2/2]

template<typename T , template< typename > class Allocator = DefaultAllocator>
SpMatrix & amrex::SpMatrix< T, Allocator >::operator= ( SpMatrix< T, Allocator > const &  )
delete

◆ pack_buffer_mv()

template<typename T , template< typename > class Allocator>
void amrex::SpMatrix< T, Allocator >::pack_buffer_mv ( AlgVector< T, AllocT > const &  v)

◆ parcsr() [1/2]

template<typename T , template< typename > class Allocator>
ParCsr< T > amrex::SpMatrix< T, Allocator >::parcsr ( )

◆ parcsr() [2/2]

template<typename T , template< typename > class Allocator>
ParCsr< T const > amrex::SpMatrix< T, Allocator >::parcsr ( ) const

◆ partition()

template<typename T , template< typename > class Allocator = DefaultAllocator>
AlgPartition const & amrex::SpMatrix< T, Allocator >::partition ( ) const
inline

◆ prepare_comm_mv()

template<typename T , template< typename > class Allocator>
void amrex::SpMatrix< T, Allocator >::prepare_comm_mv ( AlgPartition const &  col_partition)

◆ printToFile()

template<typename T , template< typename > class Allocator>
void amrex::SpMatrix< T, Allocator >::printToFile ( std::string const &  file) const

◆ rowOffset()

template<typename T , template< typename > class Allocator = DefaultAllocator>
Long * amrex::SpMatrix< T, Allocator >::rowOffset ( )
inline

Don't use this beyond initial setup.

◆ rowSum()

template<typename T , template< typename > class Allocator>
AlgVector< T, Allocator< T > > amrex::SpMatrix< T, Allocator >::rowSum ( ) const

Return row-sum vector.

◆ setVal()

template<typename T , template< typename > class Allocator>
template<typename F >
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

void(Long row, Long* col, T* val)
amrex_long Long
Definition AMReX_INT.H:30

and is responsible for setting the global column indices and values for the row specified by the global row index.

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).

Parameters
fFunctor void(Long,Long*,T*)
is_sortedIndicates whether the CSR entries are sorted (within each row).

◆ sortCSR()

template<typename T , template< typename > class Allocator>
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.

◆ split_csr()

template<typename T , template< typename > class Allocator>
void amrex::SpMatrix< T, Allocator >::split_csr ( AlgPartition const &  col_partition)

◆ startComm_mv()

template<typename T , template< typename > class Allocator>
void amrex::SpMatrix< T, Allocator >::startComm_mv ( AlgVector< T, AllocT > const &  x)

◆ startComm_tr()

template<typename T , template< typename > class Allocator>
void amrex::SpMatrix< T, Allocator >::startComm_tr ( AlgPartition const &  col_partition)

◆ unpack_buffer_mv()

template<typename T , template< typename > class Allocator>
void amrex::SpMatrix< T, Allocator >::unpack_buffer_mv ( AlgVector< T, AllocT > &  v)

◆ unpack_buffer_tr()

template<typename T , template< typename > class Allocator>
void amrex::SpMatrix< T, Allocator >::unpack_buffer_tr ( CommTR const &  ctr,
AlgPartition const &  col_partition 
)

◆ update_remote_col_index()

template<typename T , template< typename > class Allocator>
template<typename C >
void amrex::SpMatrix< T, Allocator >::update_remote_col_index ( C csrr,
bool  in_device_memory 
)

Friends And Related Symbol Documentation

◆ AMG

template<typename T , template< typename > class Allocator = DefaultAllocator>
template<typename U >
friend class AMG
friend

◆ SpMV

template<typename T , template< typename > class Allocator = DefaultAllocator>
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 
)
friend

◆ transpose

template<typename T , template< typename > class Allocator = DefaultAllocator>
template<typename U , template< typename > class M>
SpMatrix< U, M > transpose ( SpMatrix< U, M > const &  A,
AlgPartition  col_partition 
)
friend

Member Data Documentation

◆ m_comm_mv

template<typename T , template< typename > class Allocator = DefaultAllocator>
struct amrex::SpMatrix::CommMV amrex::SpMatrix< T, Allocator >::m_comm_mv

◆ m_comm_tr

template<typename T , template< typename > class Allocator = DefaultAllocator>
struct amrex::SpMatrix::CommTR amrex::SpMatrix< T, Allocator >::m_comm_tr

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