1#ifndef included_AMP_Matrix
2#define included_AMP_Matrix
4#include "AMP/matrices/MatrixParametersBase.h"
5#include "AMP/matrices/data/MatrixData.h"
6#include "AMP/matrices/operations/MatrixOperations.h"
7#include "AMP/utils/ParameterBase.h"
8#include "AMP/utils/enable_shared_from_this.h"
9#include "AMP/utils/typeid.h"
10#include "AMP/vectors/Vector.h"
39 explicit Matrix( std::shared_ptr<MatrixParametersBase> params );
45 explicit Matrix( std::shared_ptr<MatrixData> data );
51 virtual std::string
type()
const = 0;
54 virtual std::uint16_t
mode()
const;
64 void mult( std::shared_ptr<const Vector> in, std::shared_ptr<Vector> out );
71 void multTranspose( std::shared_ptr<const Vector> in, std::shared_ptr<Vector> out );
148 virtual std::shared_ptr<Matrix>
transpose()
const;
158 virtual void copy( std::shared_ptr<const Matrix>
X );
237 template<
typename T =
double>
239 setRowByGlobalID(
size_t row,
const std::vector<size_t> &cols,
const std::vector<T> &values )
242 d_matrixData->setValuesByGlobalID<
T>( 1, cols.size(), &row, cols.data(), values.data() );
266 template<
typename T =
double>
267 void getRowByGlobalID(
size_t row, std::vector<size_t> &cols, std::vector<T> &values )
const
354 template<
typename T =
double>
368 template<
typename T =
double>
379 template<
typename T =
double>
446 return std::shared_ptr<Matrix>();
451inline std::ostream &
operator<<( std::ostream &out, std::shared_ptr<const Matrix> p )
Provides C++ wrapper around MPI routines.
Class to manage reading/writing restart data.
An abstract interface for using and manipulating matrices.
Vector::shared_ptr getRowSums(Vector::shared_ptr buf=Vector::shared_ptr()) const
Get sum of each row in matrix.
T getValueByGlobalID(size_t row, size_t col) const
Get values in the matrix.
std::vector< size_t > getColumnIDs(size_t row) const
Given a row, retrieve the non-zero column indices of the matrix in compressed format.
virtual ~Matrix()
Destructor.
virtual Vector::shared_ptr createOutputVector() const =0
Get a left vector ( For , is a left vector )
size_t numLocalRows() const
Get the number of local rows in the matrix.
size_t numGlobalRows() const
Get the number of global rows in the matrix.
void scaleInv(AMP::Scalar alpha, Vector::const_shared_ptr D)
Scale matrix by inverse of diagonal matrix.
size_t numLocalColumns() const
Get the number of local columns in the matrix.
virtual void multiply(shared_ptr other_op, shared_ptr &result)=0
Multiply two matrices and store in a third result = this * other_op.
Matrix(const Matrix &)
Protected copy constructor.
void getRowByGlobalID(size_t row, std::vector< size_t > &cols, std::vector< T > &values) const
Retrieve a row of the matrix in compressed format.
virtual std::uint16_t mode() const
Return CSR mode of the matrix.
void setRowByGlobalID(size_t row, const std::vector< size_t > &cols, const std::vector< T > &values)
Set values for a row in the matrix.
virtual void copy(std::shared_ptr< const Matrix > X)
Set this matrix with the same non-zero and distributed structure as x and copy the coefficients.
Matrix & operator=(const Matrix &)=delete
Protected assignment operator.
void mult(std::shared_ptr< const Vector > in, std::shared_ptr< Vector > out)
Matrix-vector multiplication.
static shared_ptr matMatMult(shared_ptr A, shared_ptr B)
Compute the product of two matrices.
virtual std::shared_ptr< Matrix > transpose() const
Return a new matrix that is the transpose of this one.
void makeConsistent(AMP::LinearAlgebra::ScatterType t)
Perform communication to ensure values in the matrix are the same across cores.
virtual std::shared_ptr< Discretization::DOFManager > getRightDOFManager() const
Get the DOFManager associated with a right vector. For , is a right vector.
void setDiagonal(Vector::const_shared_ptr in)
Set the diagonal to the values in a vector.
void setValueByGlobalID(size_t row, size_t col, T value)
Set values in the matrix.
void setValuesByGlobalID(size_t num_rows, size_t num_cols, const size_t *rows, const size_t *cols, const T *values)
Set values in the matrix.
virtual void registerChildObjects(AMP::IO::RestartManager *manager) const
Register any child objects.
virtual std::shared_ptr< Discretization::DOFManager > getLeftDOFManager() const
Get the DOFManager associated with a left vector. For , is a left vector.
size_t numberColumnIDs(size_t row) const
Given a row, retrieve the number of non-zero column indices of the matrix.
void addValueByGlobalID(size_t row, size_t col, T value)
Add values to those in the matrix.
std::shared_ptr< Matrix > shared_ptr
Convenience typedef.
void multTranspose(std::shared_ptr< const Vector > in, std::shared_ptr< Vector > out)
Matrix transpose-vector multiplication.
size_t beginRow() const
Get the global id of the beginning row.
AMP_MPI getComm() const
Get the comm.
AMP::Scalar LinfNorm() const
Compute the maximum row sum.
void setIdentity()
Set the matrix to the identity matrix.
virtual Vector::shared_ptr createInputVector() const =0
Get a right vector ( For , is a right vector )
void scale(AMP::Scalar alpha, Vector::const_shared_ptr D)
Diagonally scale matrix.
virtual std::string type() const =0
Return the type of the matrix.
Matrix(std::shared_ptr< MatrixData > data)
Constructor.
void addValuesByGlobalID(size_t num_rows, size_t num_cols, size_t *rows, size_t *cols, T *values)
Add values to those in the matrix.
void getValuesByGlobalID(size_t num_rows, size_t num_cols, const size_t *rows, const size_t *cols, T *values) const
Get values in the matrix.
static void matMatMult(shared_ptr A, shared_ptr B, shared_ptr C)
Compute the product of two matrices.
std::shared_ptr< MatrixOperations > d_matrixOps
void scale(AMP::Scalar alpha)
Scale the matrix by a scalar.
void copyCast(std::shared_ptr< const Matrix > X)
Set this matrix with the same non-zero and distributed structure as x and copy the coefficients after...
Matrix(std::shared_ptr< MatrixParametersBase > params)
Constructor.
Matrix(int64_t fid, AMP::IO::RestartManager *manager)
Read restart data to file.
void zero()
Set the non-zeros of the matrix to zero.
std::shared_ptr< MatrixData > getMatrixData()
Return the pointer to the MatrixData.
virtual shared_ptr clone() const =0
Return a matrix with the same non-zero and distributed structure.
size_t endRow() const
Get the global id of the ending row.
virtual void setBackend(AMP::Utilities::Backend)
Replace current backend with different one, no-op if same, no-op if not a CSRMatrix.
virtual Vector::shared_ptr extractDiagonal(Vector::shared_ptr buf=Vector::shared_ptr()) const =0
Extract the diagonal from a matrix.
std::shared_ptr< MatrixData > d_matrixData
Pointer to data.
virtual void writeRestart(int64_t fid) const
Write restart data to file.
Vector::shared_ptr getRowSumsAbsolute(Vector::shared_ptr buf=Vector::shared_ptr(), const bool remove_zeros=false) const
Get absolute sum of each row in matrix.
std::shared_ptr< const Matrix > const_shared_ptr
Matrix()
Protected constructor.
void axpy(AMP::Scalar alpha, std::shared_ptr< const Matrix > X)
Compute the linear combination of two matrices.
size_t numGlobalColumns() const
Get the number of global columns in the matrix.
uint64_t getID() const
Get a unique id hash for the matrix.
void axpy(AMP::Scalar alpha, const Matrix &X)
Compute the linear combination of two matrices.
std::shared_ptr< const MatrixData > getMatrixData() const
Return the pointer to the MatrixData.
void setScalar(AMP::Scalar alpha)
Set the non-zeros of the matrix to a scalar.
std::shared_ptr< Vector > shared_ptr
Shorthand for shared pointer to Vector.
std::shared_ptr< const Vector > const_shared_ptr
Scalar is a class used to store a scalar variable that may be different types/precision.
#define AMP_ASSERT(EXP)
Assert error.
#define AMP_ERROR(MSG)
Throw error.
ScatterType
Flag to choose algorithm for makeConsistent.
std::ostream & operator<<(std::ostream &out, const Matrix &p)
Backend
Enum to store the backend used for gpu acceleration.