An abstract interface for using and manipulating matrices. More...
#include <Matrix.h>

Public Types | |
| using | const_shared_ptr = std::shared_ptr< const Matrix > |
| using | shared_ptr = std::shared_ptr< Matrix > |
| Convenience typedef. | |
Public Member Functions | |
| template<typename T = double> | |
| void | addValueByGlobalID (size_t row, size_t col, T value) |
| Add values to those in the matrix. | |
| template<typename T > | |
| 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 | axpy (AMP::Scalar alpha, const Matrix &X) |
| Compute the linear combination of two matrices. | |
| void | axpy (AMP::Scalar alpha, std::shared_ptr< const Matrix > X) |
| Compute the linear combination of two matrices. | |
| size_t | beginRow () const |
| Get the global id of the beginning row. | |
| virtual shared_ptr | clone () const =0 |
| Return a matrix with the same non-zero and distributed structure. | |
| 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. | |
| 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 up/down casting. | |
| virtual Vector::shared_ptr | createInputVector () const =0 |
| Get a right vector ( For \(\mathbf{y}^T\mathbf{Ax}\), \(\mathbf{x}\) is a right vector ) | |
| virtual Vector::shared_ptr | createOutputVector () const =0 |
| Get a left vector ( For \(\mathbf{y}^T\mathbf{Ax}\), \(\mathbf{y}\) is a left vector ) | |
| size_t | endRow () const |
| Get the global id of the ending row. | |
| virtual Vector::shared_ptr | extractDiagonal (Vector::shared_ptr buf=Vector::shared_ptr()) const =0 |
| Extract the diagonal from a 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. | |
| AMP_MPI | getComm () const |
| Get the comm. | |
| uint64_t | getID () const |
| Get a unique id hash for the matrix. | |
| virtual std::shared_ptr< Discretization::DOFManager > | getLeftDOFManager () const |
| Get the DOFManager associated with a left vector. For \(\mathbf{y}^T\mathbf{Ax}\), \(\mathbf{y}\) is a left vector. | |
| std::shared_ptr< MatrixData > | getMatrixData () |
| Return the pointer to the MatrixData. | |
| std::shared_ptr< const MatrixData > | getMatrixData () const |
| Return the pointer to the MatrixData. | |
| virtual std::shared_ptr< Discretization::DOFManager > | getRightDOFManager () const |
| Get the DOFManager associated with a right vector. For \(\mathbf{y}^T\mathbf{Ax}\), \(\mathbf{x}\) is a right vector. | |
| template<typename T = double> | |
| void | getRowByGlobalID (size_t row, std::vector< size_t > &cols, std::vector< T > &values) const |
| Retrieve a row of the matrix in compressed format. | |
| Vector::shared_ptr | getRowSums (Vector::shared_ptr buf=Vector::shared_ptr()) const |
| Get sum of each row in matrix. | |
| 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. | |
| template<typename T = double> | |
| T | getValueByGlobalID (size_t row, size_t col) const |
| Get values in the matrix. | |
| template<typename T > | |
| 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. | |
| AMP::Scalar | LinfNorm () const |
| Compute the maximum row sum. | |
| void | makeConsistent (AMP::LinearAlgebra::ScatterType t) |
| Perform communication to ensure values in the matrix are the same across cores. | |
| Matrix (int64_t fid, AMP::IO::RestartManager *manager) | |
| Read restart data to file. | |
| Matrix (std::shared_ptr< MatrixData > data) | |
| Constructor. | |
| Matrix (std::shared_ptr< MatrixParametersBase > params) | |
| Constructor. | |
| virtual std::uint16_t | mode () const |
| Return CSR mode of the matrix. | |
| void | mult (std::shared_ptr< const Vector > in, std::shared_ptr< Vector > out) |
| Matrix-vector multiplication. | |
| void | multTranspose (std::shared_ptr< const Vector > in, std::shared_ptr< Vector > out) |
| Matrix transpose-vector multiplication. | |
| size_t | numberColumnIDs (size_t row) const |
| Given a row, retrieve the number of non-zero column indices of the matrix. | |
| size_t | numGlobalColumns () const |
| Get the number of global columns in the matrix. | |
| size_t | numGlobalRows () const |
| Get the number of global rows in the matrix. | |
| size_t | numLocalColumns () const |
| Get the number of local columns in the matrix. | |
| size_t | numLocalRows () const |
| Get the number of local rows in the matrix. | |
| virtual void | registerChildObjects (AMP::IO::RestartManager *manager) const |
| Register any child objects. | |
| void | scale (AMP::Scalar alpha) |
| Scale the matrix by a scalar. | |
| void | scale (AMP::Scalar alpha, Vector::const_shared_ptr D) |
| Diagonally scale matrix. | |
| void | scaleInv (AMP::Scalar alpha, Vector::const_shared_ptr D) |
| Scale matrix by inverse of diagonal matrix. | |
| virtual void | setBackend (AMP::Utilities::Backend) |
| Replace current backend with different one, no-op if same, no-op if not a CSRMatrix. | |
| void | setDiagonal (Vector::const_shared_ptr in) |
| Set the diagonal to the values in a vector. | |
| void | setIdentity () |
| Set the matrix to the identity matrix. | |
| template<typename T = double> | |
| void | setRowByGlobalID (size_t row, const std::vector< size_t > &cols, const std::vector< T > &values) |
| Set values for a row in the matrix. | |
| void | setScalar (AMP::Scalar alpha) |
| Set the non-zeros of the matrix to a scalar. | |
| template<typename T = double> | |
| void | setValueByGlobalID (size_t row, size_t col, T value) |
| Set values in the matrix. | |
| template<typename T > | |
| 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 std::shared_ptr< Matrix > | transpose () const |
| Return a new matrix that is the transpose of this one. | |
| virtual std::string | type () const =0 |
| Return the type of the matrix. | |
| virtual void | writeRestart (int64_t fid) const |
| Write restart data to file. | |
| void | zero () |
| Set the non-zeros of the matrix to zero. | |
| virtual | ~Matrix () |
| Destructor. | |
Static Public Member Functions | |
| static shared_ptr | matMatMult (shared_ptr A, shared_ptr B) |
| Compute the product of two matrices. | |
| static void | matMatMult (shared_ptr A, shared_ptr B, shared_ptr C) |
| Compute the product of two matrices. | |
Protected Member Functions | |
| Matrix () | |
| Protected constructor. | |
| Matrix (const Matrix &) | |
| Protected copy constructor. | |
| virtual void | multiply (shared_ptr other_op, shared_ptr &result)=0 |
| Multiply two matrices and store in a third result = this * other_op. | |
| Matrix & | operator= (const Matrix &)=delete |
| Protected assignment operator. | |
Protected Attributes | |
| std::shared_ptr< MatrixData > | d_matrixData |
| Pointer to data. | |
| std::shared_ptr< MatrixOperations > | d_matrixOps |
An abstract interface for using and manipulating matrices.
There are several different varieties of distributed memory matrices. While most operations between the varieties can be abstracted away from the user, some cannot. For this reason, most of the time, this class will suffice as the way to interact with a matrix. Matrix creation may require use of one of the derived classes.
| using AMP::LinearAlgebra::Matrix::const_shared_ptr = std::shared_ptr<const Matrix> |
| using AMP::LinearAlgebra::Matrix::shared_ptr = std::shared_ptr<Matrix> |
|
explicit |
Constructor.
| [in] | params | Description of the matrix |
|
explicit |
Constructor.
| [in] | data | MatrixData object associated with matrix |
|
virtual |
Destructor.
| AMP::LinearAlgebra::Matrix::Matrix | ( | int64_t | fid, |
| AMP::IO::RestartManager * | manager | ||
| ) |
Read restart data to file.
This function will create a variable from the restart file
| fid | File identifier to write |
| manager | Restart manager |
|
protected |
Protected constructor.
Add values to those in the matrix.
| [in] | row | The row id of value |
| [in] | col | The column id of value |
| [in] | value | The value to add to the matrix |
This method may fail if the matrix has not allocated a particular (row,col) specified, depending on the actual subclass of matrix used.
Definition at line 355 of file Matrix.h.
References addValuesByGlobalID().
|
inline |
Add values to those in the matrix.
| [in] | num_rows | The number of rows represented in values |
| [in] | num_cols | The number of cols represented in values |
| [in] | rows | The row ids of values |
| [in] | cols | The column ids of values |
| [in] | values | The values to add to the matrix (row-major ordering) |
This method may fail if the matrix has not allocated a particular (row,col) specified, depending on the actual subclass of matrix used.
Definition at line 210 of file Matrix.h.
References d_matrixData.
Referenced by addValueByGlobalID().
| void AMP::LinearAlgebra::Matrix::axpy | ( | AMP::Scalar | alpha, |
| const Matrix & | X | ||
| ) |
Compute the linear combination of two matrices.
| [in] | alpha | scalar |
| [in] | X | matrix |
Compute \(\mathbf{THIS} = \alpha\mathbf{X} + \mathbf{THIS}\)
| void AMP::LinearAlgebra::Matrix::axpy | ( | AMP::Scalar | alpha, |
| std::shared_ptr< const Matrix > | X | ||
| ) |
Compute the linear combination of two matrices.
| [in] | alpha | scalar |
| [in] | X | matrix |
Compute \(\mathbf{THIS} = \alpha\mathbf{X} + \mathbf{THIS}\)
|
inline |
Get the global id of the beginning row.
Definition at line 317 of file Matrix.h.
References d_matrixData.
|
pure virtual |
Return a matrix with the same non-zero and distributed structure.
Implemented in AMP::LinearAlgebra::CSRMatrix< Config >, AMP::LinearAlgebra::DenseSerialMatrix, AMP::LinearAlgebra::NativePetscMatrix, and AMP::LinearAlgebra::ManagedEpetraMatrix.
Set this matrix with the same non-zero and distributed structure as x and copy the coefficients.
Reimplemented in AMP::LinearAlgebra::NativePetscMatrix.
Set this matrix with the same non-zero and distributed structure as x and copy the coefficients after up/down casting.
|
pure virtual |
Get a right vector ( For \(\mathbf{y}^T\mathbf{Ax}\), \(\mathbf{x}\) is a right vector )
Implemented in AMP::LinearAlgebra::CSRMatrix< Config >, AMP::LinearAlgebra::DenseSerialMatrix, AMP::LinearAlgebra::NativePetscMatrix, and AMP::LinearAlgebra::ManagedEpetraMatrix.
|
pure virtual |
Get a left vector ( For \(\mathbf{y}^T\mathbf{Ax}\), \(\mathbf{y}\) is a left vector )
Implemented in AMP::LinearAlgebra::CSRMatrix< Config >, AMP::LinearAlgebra::DenseSerialMatrix, AMP::LinearAlgebra::NativePetscMatrix, and AMP::LinearAlgebra::ManagedEpetraMatrix.
|
inline |
Get the global id of the ending row.
Definition at line 322 of file Matrix.h.
References d_matrixData.
|
pure virtual |
Extract the diagonal from a matrix.
| [in] | buf | An optional vector to use as a buffer |
Implemented in AMP::LinearAlgebra::CSRMatrix< Config >, AMP::LinearAlgebra::DenseSerialMatrix, AMP::LinearAlgebra::ManagedEpetraMatrix, and AMP::LinearAlgebra::NativePetscMatrix.
Given a row, retrieve the non-zero column indices of the matrix in compressed format.
| [in] | row | Which row |
Definition at line 281 of file Matrix.h.
References d_matrixData.
|
inline |
| uint64_t AMP::LinearAlgebra::Matrix::getID | ( | ) | const |
Get a unique id hash for the matrix.
|
inlinevirtual |
Get the DOFManager associated with a left vector. For \(\mathbf{y}^T\mathbf{Ax}\), \(\mathbf{y}\) is a left vector.
Reimplemented in AMP::LinearAlgebra::NativePetscMatrix.
Definition at line 340 of file Matrix.h.
References d_matrixData.
|
inline |
Return the pointer to the MatrixData.
Definition at line 388 of file Matrix.h.
References d_matrixData.
|
inline |
Return the pointer to the MatrixData.
Definition at line 391 of file Matrix.h.
References d_matrixData.
|
inlinevirtual |
Get the DOFManager associated with a right vector. For \(\mathbf{y}^T\mathbf{Ax}\), \(\mathbf{x}\) is a right vector.
Reimplemented in AMP::LinearAlgebra::NativePetscMatrix.
Definition at line 331 of file Matrix.h.
References d_matrixData.
|
inline |
Retrieve a row of the matrix in compressed format.
| [in] | row | Which row |
| [out] | cols | The column ids of the returned values |
| [out] | values | The values in the row |
Definition at line 267 of file Matrix.h.
References d_matrixData.
| Vector::shared_ptr AMP::LinearAlgebra::Matrix::getRowSums | ( | Vector::shared_ptr | buf = Vector::shared_ptr() | ) | const |
Get sum of each row in matrix.
| [in] | buf | An optional vector to use as a buffer |
| Vector::shared_ptr AMP::LinearAlgebra::Matrix::getRowSumsAbsolute | ( | Vector::shared_ptr | buf = Vector::shared_ptr(), |
| const bool | remove_zeros = false |
||
| ) | const |
Get absolute sum of each row in matrix.
| [in] | buf | An optional vector to use as a buffer |
| [in] | remove_zeros | Do we want to remove zeros |
Get values in the matrix.
| [in] | row | The row id of value |
| [in] | col | The column id of value |
This method will return zero for any values that have not been allocated.
Definition at line 380 of file Matrix.h.
References getValuesByGlobalID().
|
inline |
Get values in the matrix.
| [in] | num_rows | The number of rows represented in values |
| [in] | num_cols | The number of cols represented in values |
| [in] | rows | The row ids of values |
| [in] | cols | The column ids of values |
| [out] | values | The values to get from the matrix (row-major ordering) |
This method will return zero for any entries that have not been allocated or are not ghosts on the current processor.
Definition at line 255 of file Matrix.h.
References d_matrixData.
Referenced by getValueByGlobalID().
| AMP::Scalar AMP::LinearAlgebra::Matrix::LinfNorm | ( | ) | const |
Compute the maximum row sum.
|
inline |
Perform communication to ensure values in the matrix are the same across cores.
Definition at line 289 of file Matrix.h.
References d_matrixData.
|
static |
Compute the product of two matrices.
| [in] | A | Left multiplicand |
| [in] | B | Right multiplicand |
|
static |
Compute the product of two matrices.
| [in] | A | Left multiplicand |
| [in] | B | Right multiplicand |
| [in,out] | C | Result matrix |
|
virtual |
Return CSR mode of the matrix.
Reimplemented in AMP::LinearAlgebra::CSRMatrix< Config >.
| void AMP::LinearAlgebra::Matrix::mult | ( | std::shared_ptr< const Vector > | in, |
| std::shared_ptr< Vector > | out | ||
| ) |
Matrix-vector multiplication.
| [in] | in | The vector to multiply |
| [out] | out | The resulting vectory |
Compute \(\mathbf{Ain} = \mathbf{out}\).
|
protectedpure virtual |
Multiply two matrices and store in a third result = this * other_op.
| [in] | other_op | The other matrix to multiply |
| [out] | result | The matrix to store the result |
Implemented in AMP::LinearAlgebra::CSRMatrix< Config >, AMP::LinearAlgebra::DenseSerialMatrix, and AMP::LinearAlgebra::ManagedEpetraMatrix.
| void AMP::LinearAlgebra::Matrix::multTranspose | ( | std::shared_ptr< const Vector > | in, |
| std::shared_ptr< Vector > | out | ||
| ) |
Matrix transpose-vector multiplication.
| [in] | in | The vector to multiply |
| [out] | out | The resulting vectory |
Compute \(\mathbf{A}^T\mathbf{in} = \mathbf{out}\).
Given a row, retrieve the number of non-zero column indices of the matrix.
| [in] | row | Which row |
Definition at line 276 of file Matrix.h.
References d_matrixData.
|
inline |
Get the number of global columns in the matrix.
Definition at line 312 of file Matrix.h.
References d_matrixData.
|
inline |
Get the number of global rows in the matrix.
Definition at line 302 of file Matrix.h.
References d_matrixData.
|
inline |
Get the number of local columns in the matrix.
Definition at line 307 of file Matrix.h.
References d_matrixData.
|
inline |
Get the number of local rows in the matrix.
Definition at line 297 of file Matrix.h.
References d_matrixData.
|
protecteddelete |
Protected assignment operator.
|
virtual |
Register any child objects.
This function will register child objects with the manager
| manager | Restart manager |
| void AMP::LinearAlgebra::Matrix::scale | ( | AMP::Scalar | alpha | ) |
Scale the matrix by a scalar.
| [in] | alpha | The value to scale by |
Compute \(\mathbf{A} = \alpha\mathbf{A}\)
| void AMP::LinearAlgebra::Matrix::scale | ( | AMP::Scalar | alpha, |
| Vector::const_shared_ptr | D | ||
| ) |
Diagonally scale matrix.
| [in] | alpha | Scaling applied to all rows |
| [in] | D | Vector of scales, one for each row |
Compute \(\mathbf{A} = \alpha\mathbf{D}\mathbf{A}\)
| void AMP::LinearAlgebra::Matrix::scaleInv | ( | AMP::Scalar | alpha, |
| Vector::const_shared_ptr | D | ||
| ) |
Scale matrix by inverse of diagonal matrix.
| [in] | alpha | Scaling applied to all rows |
| [in] | D | Array of inverse scales, one for each row |
Compute \(\mathbf{A} = \alpha\mathbf{D}^{-1}\mathbf{A}\)
|
virtual |
Replace current backend with different one, no-op if same, no-op if not a CSRMatrix.
Reimplemented in AMP::LinearAlgebra::CSRMatrix< Config >.
| void AMP::LinearAlgebra::Matrix::setDiagonal | ( | Vector::const_shared_ptr | in | ) |
Set the diagonal to the values in a vector.
| [in] | in | The values to set the diagonal to |
| void AMP::LinearAlgebra::Matrix::setIdentity | ( | ) |
Set the matrix to the identity matrix.
|
inline |
Set values for a row in the matrix.
| [in] | row | Which row |
| [in] | cols | The column ids to set |
| [in] | values | The values to set |
Definition at line 239 of file Matrix.h.
References AMP_ASSERT, and d_matrixData.
| void AMP::LinearAlgebra::Matrix::setScalar | ( | AMP::Scalar | alpha | ) |
Set the non-zeros of the matrix to a scalar.
| [in] | alpha | The value to set the non-zeros to |
Set values in the matrix.
| [in] | row | The row id of value |
| [in] | col | The column id of value |
| [in] | value | The value to set to the matrix |
This method may fail if the matrix has not allocated a particular (row,col) specified, depending on the actual subclass of matrix used.
Definition at line 369 of file Matrix.h.
References setValuesByGlobalID().
|
inline |
Set values in the matrix.
| [in] | num_rows | The number of rows represented in values |
| [in] | num_cols | The number of cols represented in values |
| [in] | rows | The row ids of values |
| [in] | cols | The column ids of values |
| [in] | values | The values to set to the matrix (row-major ordering) |
This method may fail if the matrix has not allocated a particular (row,col) specified, depending on the actual subclass of matrix used.
Definition at line 226 of file Matrix.h.
References d_matrixData.
Referenced by setValueByGlobalID().
|
inlinevirtual |
Return a new matrix that is the transpose of this one.
Reimplemented in AMP::LinearAlgebra::CSRMatrix< Config >, AMP::LinearAlgebra::DenseSerialMatrix, and AMP::LinearAlgebra::ManagedEpetraMatrix.
Definition at line 443 of file Matrix.h.
References AMP_ERROR.
|
pure virtual |
Return the type of the matrix.
Implemented in AMP::LinearAlgebra::CSRMatrix< Config >, AMP::LinearAlgebra::DenseSerialMatrix, AMP::LinearAlgebra::NativePetscMatrix, and AMP::LinearAlgebra::ManagedEpetraMatrix.
Write restart data to file.
This function will write the mesh to an HDF5 file
| fid | File identifier to write |
| void AMP::LinearAlgebra::Matrix::zero | ( | ) |
Set the non-zeros of the matrix to zero.
May not deallocate space.
|
protected |
Pointer to data.
Definition at line 439 of file Matrix.h.
Referenced by addValuesByGlobalID(), beginRow(), endRow(), getColumnIDs(), getComm(), getLeftDOFManager(), getMatrixData(), getMatrixData(), getRightDOFManager(), getRowByGlobalID(), getValuesByGlobalID(), makeConsistent(), numberColumnIDs(), numGlobalColumns(), numGlobalRows(), numLocalColumns(), numLocalRows(), setRowByGlobalID(), and setValuesByGlobalID().
|
protected |
|
Advanced Multi-Physics (AMP) Oak Ridge National Laboratory Idaho National Laboratory Los Alamos National Laboratory |
This page automatically produced from the source code by Last updated: Tue Mar 10 2026 13:06:42. Comments on this page |