1#ifndef included_AMP_CSRMatrixData_h
2#define included_AMP_CSRMatrixData_h
4#include "AMP/matrices/MatrixParametersBase.h"
5#include "AMP/matrices/RawCSRMatrixParameters.h"
6#include "AMP/matrices/data/CSRLocalMatrixData.h"
7#include "AMP/matrices/data/MatrixData.h"
8#include "AMP/utils/Memory.h"
9#include "AMP/utils/Utilities.h"
27class CSRMatrixSpGEMMDefault;
29template<
typename Config>
38 using gidx_t =
typename Config::gidx_t;
39 using lidx_t =
typename Config::lidx_t;
42 static_assert( std::is_same_v<typename allocator_type::value_type, void> );
44 typename std::allocator_traits<allocator_type>::template rebind_alloc<gidx_t>;
46 typename std::allocator_traits<allocator_type>::template rebind_alloc<lidx_t>;
48 typename std::allocator_traits<allocator_type>::template rebind_alloc<scalar_t>;
70 template<
typename ConfigOut>
74 std::shared_ptr<MatrixData>
transpose()
const override;
77 std::string
type()
const override {
return "CSRMatrixData"; }
80 virtual std::uint16_t
mode()
const override
82 return static_cast<std::uint16_t
>( Config::mode );
91 std::vector<size_t> &cols,
92 std::vector<double> &values )
const override;
109 const typeID &
id )
override;
126 const typeID &
id )
override;
143 const typeID &
id )
const override;
211 constexpr auto type = getTypeID<scalar_t>();
295 std::cout <<
"CSRMatrixData stats:" << std::endl;
311 std::shared_ptr<localmatrixdata_t>
subsetRows(
const std::vector<gidx_t> &rows )
const;
322 std::shared_ptr<localmatrixdata_t>
350 std::shared_ptr<localmatrixdata_t>
354 const std::string &prefix,
355 const std::map<
gidx_t, std::map<gidx_t, scalar_t>> &data )
const;
358 const std::string &prefix,
359 std::map<
gidx_t, std::map<gidx_t, scalar_t>> &data );
406template<
typename Config>
410 AMP_INSIST( ptr,
"dynamic cast from const MatrixData to const CSRMatrixData failed" );
414template<
typename Config>
418 AMP_INSIST( ptr,
"dynamic cast from MatrixData to CSRMatrixData failed" );
Class to manage reading/writing restart data.
auto numberOfNonZeros() const
Get total number of nonzeros in both blocks.
std::map< gidx_t, std::map< gidx_t, scalar_t > > d_ghost_data
storage of off core matrix data to set
lidxAllocator_t d_lidxAllocator
Allocator for lidx_t matched to template parameter.
typename Config::gidx_t gidx_t
void globalToLocalColumns()
Convert global columns in blocks to local columns and free global columns.
AMP::Utilities::MemoryType d_memory_location
Memory location, set by examining type of Allocator.
gidx_t d_last_col
Global index of last column of diagonal block.
std::shared_ptr< localmatrixdata_t > d_offd_matrix
Diagonal matrix block [d_first_row,d_last_row] x ]d_first_col,d_last_col[.
typename Config::lidx_t lidx_t
std::shared_ptr< localmatrixdata_t > transposeOffd(std::shared_ptr< MatrixParametersBase > params) const
auto numberOfNonZerosOffDiag() const
Get total number of nonzeros in off-diagonal block.
void setNNZ(lidx_t tot_nnz_diag, lidx_t tot_nnz_offd)
Set the number of nonzeros in each block and allocate space internally.
std::shared_ptr< localmatrixdata_t > getDiagMatrix()
Get pointer to diagonal block.
void registerChildObjects(AMP::IO::RestartManager *manager) const override
Register any child objects.
std::shared_ptr< const localmatrixdata_t > getOffdMatrix() const
std::shared_ptr< CommunicationList > d_rightCommList
CommunicationList for right vectors.
typeID getCoeffType() const override
Return the typeid of the matrix coeffs.
typename std::allocator_traits< allocator_type >::template rebind_alloc< gidx_t > gidxAllocator_t
lidx_t * getDiagRowStarts()
Get row pointers from diagonal block.
std::shared_ptr< MatrixData > transpose() const override
Transpose.
void writeRestart(int64_t fid) const override
Write restart data to file.
CSRMatrixData(std::shared_ptr< MatrixParametersBase > params)
Constructor.
void readRestartMapData(const int64_t fid, const std::string &prefix, std::map< gidx_t, std::map< gidx_t, scalar_t > > &data)
gidxAllocator_t d_gidxAllocator
Allocator for gidx_t matched to template parameter.
gidx_t d_last_row
Global index of last row of this block.
std::map< gidx_t, std::map< gidx_t, scalar_t > > d_other_data
storage of off core matrix data
typename std::allocator_traits< allocator_type >::template rebind_alloc< scalar_t > scalarAllocator_t
virtual ~CSRMatrixData()
Destructor.
size_t numLocalColumns() const override
Get the number of local columns in the matrix.
void writeRestartMapData(const int64_t fid, const std::string &prefix, const std::map< gidx_t, std::map< gidx_t, scalar_t > > &data) const
bool d_is_square
Matrix is square if true.
CSRMatrixData()
Empty constructor.
std::shared_ptr< localmatrixdata_t > subsetCols(const gidx_t idx_lo, const gidx_t idx_up, const bool is_diag) const
Extract subset of each row containing global columns in some range.
std::shared_ptr< CommunicationList > d_leftCommList
CommunicationList for left vectors.
void assemble(bool force_dm_reset=false)
Convenience function to triger internal setup.
size_t beginCol() const override
Get the global id of the first column in diagonal block (inclusive)
CSRMatrixData(int64_t fid, AMP::IO::RestartManager *manager)
Constructor from restart data.
bool isEmpty() const noexcept
Check if matrix is globally square.
void setValuesByGlobalID(size_t num_rows, size_t num_cols, const size_t *rows, const size_t *cols, const void *values, const typeID &id) override
Set values in the matrix.
std::shared_ptr< localmatrixdata_t > subsetRows(const std::vector< gidx_t > &rows) const
Extract subset of locally owned rows into new local matrix.
std::string type() const override
Return the type of the matrix.
gidx_t d_first_row
Global index of first row of this block.
size_t beginRow() const override
Get the global id of the first stored row (inclusive)
std::shared_ptr< localmatrixdata_t > d_diag_matrix
Diagonal matrix block [d_first_row,d_last_row] x [d_first_col,d_last_col].
typename localmatrixdata_t::mask_t mask_t
void removeRange(AMP::Scalar bnd_lo, AMP::Scalar bnd_up) override
Remove matrix entries within given range.
size_t numberColumnIDs(size_t row) const override
Given a row, retrieve the number of non-zero column indices of the matrix.
virtual std::uint16_t mode() const override
Return CSR mode of the matrix.
std::shared_ptr< const localmatrixdata_t > getDiagMatrix() const
bool isSquare() const noexcept
Check if matrix is globally square.
void getValuesByGlobalID(size_t num_rows, size_t num_cols, const size_t *rows, const size_t *cols, void *values, const typeID &id) const override
Get values from the matrix.
std::shared_ptr< localmatrixdata_t > getOffdMatrix()
Get pointer to off-diagonal block.
typename std::allocator_traits< allocator_type >::template rebind_alloc< lidx_t > lidxAllocator_t
std::shared_ptr< MatrixData > cloneMatrixData() const override
Clone the data.
std::shared_ptr< Discretization::DOFManager > d_rightDOFManager
DOFManager for right vectors.
std::shared_ptr< Discretization::DOFManager > d_leftDOFManager
DOFManager for left vectors.
typename Config::scalar_t scalar_t
void resetDOFManagers(bool force_dm_reset=false)
Replace left/right DOFManagers and CommunicationLists to match NNZ structure.
std::shared_ptr< CommunicationList > getRightCommList() const
Get the CommList associated with a right vector ( For , is a right vector )
size_t numGlobalColumns() const override
Get the number of global columns in the matrix.
size_t endRow() const override
Get the global id of the last stored row (exclusive)
size_t numGlobalRows() const override
Get the number of global rows in the matrix.
auto numberOfNonZerosDiag() const
Get total number of nonzeros in diagonal block.
size_t numLocalRows() const override
Get the number of local rows in the matrix.
scalarAllocator_t d_scalarAllocator
Allocator for scalar_t matched to template parameter.
void setNNZ(const lidx_t *nnz_diag, const lidx_t *nnz_offd)
Set the number of nonzeros in each block and allocate space internally.
gidx_t d_first_col
Global index of first column of diagonal block.
bool hasOffDiag() const
Check if off-diagonal block is non-empty.
CSRMatrixData(const CSRMatrixData &)=delete
Copy constructor.
std::vector< size_t > getColumnIDs(size_t row) const override
Get the global indices of nonzeros in a given row.
std::shared_ptr< Discretization::DOFManager > getRightDOFManager() const override
Get the DOFManager associated with a right vector ( For , is a right vector )
void makeConsistent(AMP::LinearAlgebra::ScatterType t) override
Perform communication to ensure values in the matrix are the same across cores.
std::shared_ptr< Discretization::DOFManager > getLeftDOFManager() const override
Get the DOFManager associated with a left vector ( For , is a left vector )
auto getMemoryLocation() const
Get the memory space where data is stored.
void getRowByGlobalID(size_t row, std::vector< size_t > &cols, std::vector< double > &values) const override
Retrieve a row of the matrix in compressed format.
std::shared_ptr< CSRMatrixData< ConfigOut > > migrate(AMP::Utilities::Backend backend) const
Migrate data to different configuration, mostly for moving memory spaces.
void printStats(bool verbose, bool show_zeros) const
Print information about matrix blocks.
lidx_t * getOffDiagRowStarts()
Get row pointers from off-diagonal block.
void setNNZ(bool do_accum)
Set the number of nonzeros in each block and allocate space internally.
typename Config::allocator_type allocator_type
std::shared_ptr< CommunicationList > getLeftCommList() const
Get the CommList associated with a left vector ( For , is a left vector )
void setOtherData(std::map< gidx_t, std::map< gidx_t, scalar_t > > &, AMP::LinearAlgebra::ScatterType)
Update matrix data off-core.
size_t endCol() const override
Get the global id of the last column in diagonal block (exclusive)
void addValuesByGlobalID(size_t num_rows, size_t num_cols, const size_t *rows, const size_t *cols, const void *values, const typeID &id) override
Add values to those in the matrix.
Scalar is a class used to store a scalar variable that may be different types/precision.
#define AMP_INSIST(EXP, MSG)
Insist error.
static CSRMatrixData< Config > const * getCSRMatrixData(MatrixData const &A)
ScatterType
Flag to choose algorithm for makeConsistent.
Backend
Enum to store the backend used for gpu acceleration.
std::string_view getString(const ExecutionSpace exec_space)
MemoryType
Enum to store pointer type.
Class to store type info.