41 using PetscMatrix = Mat;
44 #include <Eigen/Dense>
552 using DMatPtr = std::shared_ptr<DistributedMatrix>;
std::basic_string< CepsChar > CepsString
C++ format string.
CepsScalar CepsMathScalar
Real numbers.
std::vector< _Type, _Alloc > CepsVector
C++ vector.
CepsIndex CepsGlobalIndex
Many uses. Has to be signed for PETSc.
float CepsReal
Need single precision floating point.
int32_t CepsInt
Need 32 bit integer.
Eigen::Matrix< CepsScalar, Eigen::Dynamic, Eigen::Dynamic > CepsMathDynamic2D
Dynamic 2D array, eigen format.
std::shared_ptr< DistributedMatrix > DMatPtr
Short typedef for pointer on dist matrix.
Sparse matrix distributed between process.
void zero()
Zeroes all entries.
CepsMathScalar lInfNorm() const
-norm of matrix
CepsMathScalar l2Norm() const
-norm of matrix
void add(DistributedMatrix &X, CepsMathScalar a, CepsBool sameNonZeroStructure=true)
Adds a*X to this.
void getEntireLocalRow(CepsVector< CepsMathScalar > &rowValues, CepsGlobalIndex row) const
Get a copy of all values stored in a local row, including zeros.
void zeroRows(CepsInt nbRows, CepsGlobalIndex *rows, CepsMathScalar diagonalValue=1.0)
Sets the indicated rows to zero.
void releaseLocalRow(const CepsMathScalar **values, CepsGlobalIndex row, CepsInt *nbNonZero, const CepsGlobalIndex **nonZeroCols)
Release access to the values of matrix row after reading.
CepsBool isSymmetric() const
True if matrix is symmetric.
void setValue(CepsMathScalar value, CepsGlobalIndex i, CepsGlobalIndex j)
Sets A(i,j) (replace if existing)
void identity()
Sets to identity matrix. Fails if matrix is not square.
void setSymmetric(CepsBool flag=true)
Set whether this matrix is symmetric or not.
void getLocalSize(CepsInt *m, CepsInt *n) const
Get the local size of the matrix.
CepsGlobalIndex m_lo
Index of first local row.
void ignoreOffProcEntries(CepsBool flag)
Choose to ignore entries destined to other processes when setting or adding values in the matrix.
void setNonZeroStructure(const CepsInt d_nnz[], const CepsInt o_nnz[])
Set the matrix non-zero structure.
void getDiagonalAsDistributedVector(DistributedVector &v) const
Fills a DistributedVector with values of diagonal.
void flush()
Use when switching between calls to adding and setting values.
void beginAssembly()
Begin matrix assembly.
friend class TestDistributedMatrix
CepsBool isAssembled() const
Safety check.
void addValue(CepsMathScalar value, CepsGlobalIndex i, CepsGlobalIndex j)
Adds value to A(i,j) (sets if not existing already)
void checkProperlySet() const
Will fail if matrix is not properly set (correct sizes and memory preallocation).
void setDiagonalAsDistributedVector(DistributedVector &v)
Sets the values of a distributed vector in matrix diagonal.
DistributedMatrix & operator*=(const CepsMathScalar &scalar)
Short mult by scalar.
void copy(DistributedMatrix &A) const
Copy values from this matrix to matrix A of same non-zero structure.
void getLocalRow(const CepsMathScalar **values, CepsGlobalIndex row, CepsInt *nbNonZero, const CepsGlobalIndex **nonZeroCols) const
Read-only access to the values of matrix row.
void assertAssembled(CepsString info="") const
Safetier check.
DistributedMatrix()
Empty constructor.
void setSize(CepsInt M, CepsInt N, CepsInt m, CepsInt n)
Set distributed matrix global and local size.
void setValues(const CepsMathScalar *values, CepsInt nbRows, CepsInt nbColumns, const CepsGlobalIndex *rowIndices, const CepsGlobalIndex *columnIndices)
Set multiple values in the matrix at once.
void getDiagonalFootPrintAsDistributedVector(DistributedVector &v, CepsReal epsilon=1E-12) const
Fills a DistributedVector with the footprint (zero or non-zero) of diagonal.
void getSubMatrix(const CepsVector< CepsGlobalIndex > &indicesI, const CepsVector< CepsGlobalIndex > &indicesJ, CepsMathDynamic2D &subMat)
Insert each element of a distributed matrix in a small Eigen submatrix.
void setColumnAsDistributedVector(DistributedVector &v, CepsGlobalIndex column)
Sets the values of a distributed vector in matrix column.
const PetscMatrix & getMatrix() const
The underlying matrix.
void getLocalRange(CepsGlobalIndex *lo, CepsGlobalIndex *hi) const
Get the range of rows owned by current process.
CepsGlobalIndex m_hi
Index of last local row +1.
void addSubMatrix(const CepsMathDynamic2D &subMat, const CepsVector< CepsGlobalIndex > &indicesI, const CepsVector< CepsGlobalIndex > &indicesJ)
Add each element of a small square matrix in a distributed matrix.
void addValues(const CepsMathScalar *values, CepsInt nbRows, CepsInt nbColumns, const CepsGlobalIndex *rowIndices, const CepsGlobalIndex *columnIndices)
Add multiple values in the matrix at once.
void duplicate(DistributedMatrix &dest, CepsBool copyValues) const
Copy non-zero structure to dest matrix. Optionally values.
CepsBool m_properlySet
Safety flag to check for sizes and memory preallocation.
PetscMatrix m_A
The main object.
void getColumnAsDistributedVector(DistributedVector &v, CepsGlobalIndex column) const
Fills a DistributedVector with values of column.
void save(const CepsString &filename)
Matrix is saved in binary format.
void getSize(CepsInt *M, CepsInt *N) const
Get the global size of the matrix.
void load(const CepsString &filename)
Matrix is loaded from specified file in binary format.
void endAssembly()
Wait for the end of matrix assembly.
~DistributedMatrix()
Destructor. The underlying object is cleaned.
void zeroRowsAndColumns(CepsInt nbRows, CepsGlobalIndex *rows, CepsMathScalar diagonalValue=1.0)
Sets the indicated rows and columns values to zero for symmetric matrices.
void finalize()
Performs assembly.
CepsMathScalar l1Norm() const
-norm of matrix
void getValues(CepsMathScalar *values, CepsInt nbRows, CepsInt nbColumns, const CepsGlobalIndex *rowIndices, const CepsGlobalIndex *columnIndices)
Get multiple values in the matrix.
void view() const
Displays the matrix on standard output.
Structure to hold spatially dependant data and distribute it between process.