Sparse matrix. More...
Public Member Functions | |
SparseMatrix () | |
SparseMatrix (const SparseMatrix &other) | |
SparseMatrix (int blockSize, long nRows, long nCols, long nNZ) | |
SparseMatrix (long nRows, long nCols, long nNZ) | |
SparseMatrix (MPI_Comm communicator) | |
SparseMatrix (MPI_Comm communicator, bool partitioned, int blockSize, long nRows, long nCols, long nNZ) | |
SparseMatrix (MPI_Comm communicator, bool partitioned, long nRows, long nCols, long nNZ) | |
SparseMatrix (SparseMatrix &&other)=default | |
~SparseMatrix () | |
void | addRow (const std::vector< long > &rowPattern, const std::vector< double > &rowValues) |
void | addRow (long nRowNZ, const long *rowPattern, const double *rowValues) |
void | assembly () |
void | clear (bool release=false) |
std::unique_ptr< SparseMatrix > | computeTranspose () const |
long | countAddedRows () const |
long | countMissingRows () const |
virtual void | display (std::ostream &stream, double negligiblity, int indent=0) const |
std::vector< long > | extractGhostGlobalCols () const |
std::vector< long > | extractGhostGlobalRows () const |
std::vector< long > | extractLocalGlobalCols () const |
std::vector< long > | extractLocalGlobalRows () const |
int | getBlockSize () const |
long | getColCount () const |
long | getColElementCount () const |
long | getColGlobalCount () const |
long | getColGlobalElementCount () const |
long | getColGlobalElementOffset () const |
long | getColGlobalOffset () const |
const MPI_Comm & | getCommunicator () const |
long | getMaxRowNZCount () const |
long | getMaxRowNZElementCount () const |
long | getMaxRowNZGlobalCount () const |
long | getMaxRowNZGlobalElementCount () const |
long | getNZCount () const |
long | getNZElementCount () const |
long | getNZGlobalCount () const |
long | getNZGlobalElementCount () const |
long | getRowCount () const |
long | getRowElementCount () const |
long | getRowGlobalCount () const |
long | getRowGlobalElementCount () const |
long | getRowGlobalElementOffset () const |
long | getRowGlobalOffset () const |
long | getRowNZCount (long row) const |
long | getRowNZElementCount (long row) const |
ConstProxyVector< long > | getRowPattern (long row) const |
void | getRowPattern (long row, ConstProxyVector< long > *pattern) const |
ConstProxyVector< double > | getRowValues (long row) const |
void | getRowValues (long row, ConstProxyVector< double > *values) const |
void | initialize (bool partitioned, int blockSize, long nRows, long nCols, long nNZ) |
void | initialize (bool partitioned, long nRows, long nCols, long nNZ) |
void | initialize (int blockSize, long nRows, long nCols, long nNZ) |
void | initialize (long nRows, long nCols, long nNZ) |
bool | isAssembled () const |
bool | isPartitioned () const |
void | squeeze () |
Protected Member Functions | |
void | clearPatternStorage (bool release) |
void | clearValueStorage (bool release) |
long * | getRowPatternData (long row) |
const long * | getRowPatternData (long row) const |
double * | getRowValuesData (long row) |
const double * | getRowValuesData (long row) const |
void | initializePatternStorage () |
void | initializeValueStorage () |
void | squeezePatternStorage () |
void | squeezeValueStorage () |
Protected Attributes | |
bool | m_assembled |
int | m_blockSize |
MPI_Comm | m_communicator |
long | m_global_colOffset |
long | m_global_maxRowNZ |
long | m_global_nCols |
long | m_global_nNZ |
long | m_global_nRows |
long | m_global_rowOffset |
long | m_lastRow |
long | m_maxRowNZ |
long | m_nCols |
long | m_nNZ |
long | m_nRows |
bool | m_partitioned |
FlatVector2D< long > | m_pattern |
std::vector< double > | m_values |
Sparse matrix.
Rather than working with individual elements in the matrix, it is possible to employ blocks of elements. The size of the blocks can be defined during assembly. When a size different that one is provided, the matrix will store elements by fixed-sized dense nb × nb blocks, where nb is the size of the blocks. Blocking may be advantageous when solving PDE-based simulations that leads to matrices with a naturally blocked structure (with a block size equal to the number of degrees of freedom per cell).
When blocking is used, row and column indexes will count the number of blocks in the row/column direction, not the number of rows/columns of the matrix.
Definition at line 38 of file system_matrix.hpp.
bitpit::SparseMatrix::SparseMatrix | ( | ) |
The SparseMatrix class mimics the beahviour of the sparse parallel matrix in AIJ/BAIJ format of the PETSc library.
The parallel matrix is partitioned across processes such that the first m0 rows belong to process 0, the next m1 rows belong to process 1, the next m2 rows belong to process 2 etc.. where m0, m1, m2,.. are the local number of rows defined by each processes.
Each process stores values corresponding to [m x N] submatrix, wher N is the global number of columns of the matrix, N is obtained summing the local number of columns of each process.
Although each process stores values for the whole global row, columns are logically partitioned across processes, with the n0 columns belonging to 0th partition, the next n1 columns belonging to the next partition etc.. where n0, n1, n2... are the local number of columns defined by each process.
The DIAGONAL portion of the local submatrix on any given process is the submatrix corresponding to the rows and columns m,n corresponding to the given process. i.e diagonal matrix on process 0 is [m0 x n0], diagonal matrix on process 1 is [m1 x n1] etc. The remaining portion of the local submatrix [m x (N-n)] constitute the OFF-DIAGONAL portion.
For a square global matrix we define each process's diagonal portion to be its local rows and the corresponding columns (a square submatrix); each process's off-diagonal portion encompasses the remainder of the local matrix (a rectangular submatrix). Default constructor
Definition at line 84 of file system_matrix.cpp.
bitpit::SparseMatrix::SparseMatrix | ( | long | nRows, |
long | nCols, | ||
long | nNZ ) |
Constructor
nRows | is the number of rows of the matrix |
nCols | is the number of columns of the matrix |
nNZ | is the number of non-zero elements that the matrix will contain. If this number is unknown, an estimate (or zero) could be passed. If the actual number of non-zero elements turns out to be greater than the provided value, the initialization of the matrix will be slower because reallocation of internal data may be needed |
Definition at line 127 of file system_matrix.cpp.
bitpit::SparseMatrix::SparseMatrix | ( | int | blockSize, |
long | nRows, | ||
long | nCols, | ||
long | nNZ ) |
Constructor
blockSize | is the block size of the matrix |
nRows | is the number of rows of the matrix |
nCols | is the number of columns of the matrix |
nNZ | is the number of non-zero blocks that the matrix will contain. If this number is unknown, an estimate (or zero) could be passed. If the actual number of non-zero elements turns out to be greater than the provided value, the initialization of the matrix will be slower because reallocation of internal data may be needed |
Definition at line 144 of file system_matrix.cpp.
bitpit::SparseMatrix::SparseMatrix | ( | MPI_Comm | communicator | ) |
Constructor
communicator | is the MPI communicator |
Definition at line 94 of file system_matrix.cpp.
bitpit::SparseMatrix::SparseMatrix | ( | MPI_Comm | communicator, |
bool | partitioned, | ||
long | nRows, | ||
long | nCols, | ||
long | nNZ ) |
Constructor
communicator | is the MPI communicator |
partitioned | controls if the matrix is partitioned |
nRows | is the number rows of the matrix, if the matrix is partitioned this is the number of local rows |
nCols | is the number columns of the matrix, if the matrix is partitioned this is the number of local columns |
nNZ | is the number of non-zero elements that the matrix will contain. If this number is unknown, an estimate (or zero) could be passed. If the actual number of non-zero elements turns out to be greater than the provided value, the initialization of the matrix will be slower because reallocation of internal data may be needed |
Definition at line 164 of file system_matrix.cpp.
bitpit::SparseMatrix::SparseMatrix | ( | MPI_Comm | communicator, |
bool | partitioned, | ||
int | blockSize, | ||
long | nRows, | ||
long | nCols, | ||
long | nNZ ) |
Constructor
communicator | is the MPI communicator |
partitioned | controls if the matrix is partitioned |
blockSize | is the block size of the matrix |
nRows | is the number rows of the matrix, if the matrix is partitioned this is the number of local rows |
nCols | is the number columns of the matrix, if the matrix is partitioned this is the number of local columns |
nNZ | is the number of non-zero blocks that the matrix will contain. If this number is unknown, an estimate (or zero) could be passed. If the actual number of non-zero elements turns out to be greater than the provided value, the initialization of the matrix will be slower because reallocation of internal data may be needed |
Definition at line 186 of file system_matrix.cpp.
bitpit::SparseMatrix::SparseMatrix | ( | const SparseMatrix & | other | ) |
Copy constructor
Definition at line 231 of file system_matrix.cpp.
bitpit::SparseMatrix::~SparseMatrix | ( | ) |
Destructor
Definition at line 257 of file system_matrix.cpp.
void bitpit::SparseMatrix::addRow | ( | const std::vector< long > & | rowPattern, |
const std::vector< double > & | rowValues ) |
Add a row.
The values of the row are stored using a block-row-major order: the rows of the single block elements are stored consecutively:
<row_1_block_1><row_1_block_2>...<row_2_block_1><row_2_block_2>...
rowPattern | are the indexes of the non-zero columns of the matrix |
rowValues | are the values of the non-zero columns of the matrix |
Definition at line 1214 of file system_matrix.cpp.
void bitpit::SparseMatrix::addRow | ( | long | nRowNZ, |
const long * | rowPattern, | ||
const double * | rowValues ) |
Add a row.
The values of the row are stored using a block-row-major order: the rows of the single block elements are stored consecutively:
<row_1_block_1><row_1_block_2>...<row_2_block_1><row_2_block_2>...
nRowNZ | is the number of non-zero elements in the row |
rowPattern | are the indexes of the non-zero columns of the matrix |
rowValues | are the values of the non-zero columns of the matrix |
Definition at line 1231 of file system_matrix.cpp.
void bitpit::SparseMatrix::assembly | ( | ) |
Assembly the matrix.
This function should be called after adding all the rows of the matrix. Its purpose is to prepare the matrix for the usage.
It's a collective operation, hence it has to be called by all processes.
Definition at line 737 of file system_matrix.cpp.
void bitpit::SparseMatrix::clear | ( | bool | release = false | ) |
Clear the matrix.
release | if set to true the memory hold by the matrix will be released |
Definition at line 429 of file system_matrix.cpp.
|
protected |
Clear the storage for the pattern.
release | if set to true the memory hold by the pattern storage will be released |
Definition at line 675 of file system_matrix.cpp.
|
protected |
Clear the storage for the values.
release | if set to true the memory hold by the value storage will be released |
Definition at line 717 of file system_matrix.cpp.
std::unique_ptr< SparseMatrix > bitpit::SparseMatrix::computeTranspose | ( | ) | const |
Compute the transpose of the matrix.
The transpose is evaluated as a new matrix, the current matrix is not modified.
Definition at line 1387 of file system_matrix.cpp.
long bitpit::SparseMatrix::countAddedRows | ( | ) | const |
Count the number of rows that have been added to the matrix.
Definition at line 792 of file system_matrix.cpp.
long bitpit::SparseMatrix::countMissingRows | ( | ) | const |
Count the number of rows that needs to be added to fill the matrix.
Definition at line 779 of file system_matrix.cpp.
|
virtual |
Displays matrix information.
stream | is the output stream | |
negligiblity | is the threshold below which the values are considered negligible | |
[in] | indent | is the number of spaces to prepend to each row |
Definition at line 474 of file system_matrix.cpp.
std::vector< long > bitpit::SparseMatrix::extractGhostGlobalCols | ( | ) | const |
Extract the list of ghost global columns.
Definition at line 1181 of file system_matrix.cpp.
std::vector< long > bitpit::SparseMatrix::extractGhostGlobalRows | ( | ) | const |
Extract the list of ghost global rows.
Definition at line 1147 of file system_matrix.cpp.
std::vector< long > bitpit::SparseMatrix::extractLocalGlobalCols | ( | ) | const |
Extract the list of local global columns.
Definition at line 1157 of file system_matrix.cpp.
std::vector< long > bitpit::SparseMatrix::extractLocalGlobalRows | ( | ) | const |
Extract the list of local global rows.
Definition at line 1126 of file system_matrix.cpp.
int bitpit::SparseMatrix::getBlockSize | ( | ) | const |
Get the number of blocks of the matrix.
Definition at line 802 of file system_matrix.cpp.
long bitpit::SparseMatrix::getColCount | ( | ) | const |
Get the number of columns of the matrix.
Definition at line 822 of file system_matrix.cpp.
long bitpit::SparseMatrix::getColElementCount | ( | ) | const |
Get the number of columns of the matrix.
Definition at line 844 of file system_matrix.cpp.
long bitpit::SparseMatrix::getColGlobalCount | ( | ) | const |
Get number of global columns.
Definition at line 1038 of file system_matrix.cpp.
long bitpit::SparseMatrix::getColGlobalElementCount | ( | ) | const |
Get the number of global column
Definition at line 1058 of file system_matrix.cpp.
long bitpit::SparseMatrix::getColGlobalElementOffset | ( | ) | const |
Get global column offset.
Definition at line 1070 of file system_matrix.cpp.
long bitpit::SparseMatrix::getColGlobalOffset | ( | ) | const |
Get global column offset.
Definition at line 1048 of file system_matrix.cpp.
const MPI_Comm & bitpit::SparseMatrix::getCommunicator | ( | ) | const |
Gets the MPI communicator associated to the matrix.
Definition at line 955 of file system_matrix.cpp.
long bitpit::SparseMatrix::getMaxRowNZCount | ( | ) | const |
Get the maximum number of non-zero blocks/elements per row.
Definition at line 876 of file system_matrix.cpp.
long bitpit::SparseMatrix::getMaxRowNZElementCount | ( | ) | const |
Get the maximum number of non-zero elements per row.
This is the number of individual non-zero elements, NOT the number of non-zero blocks.
Definition at line 932 of file system_matrix.cpp.
long bitpit::SparseMatrix::getMaxRowNZGlobalCount | ( | ) | const |
Get the global maximum number of non-zero elements per row.
Definition at line 1092 of file system_matrix.cpp.
long bitpit::SparseMatrix::getMaxRowNZGlobalElementCount | ( | ) | const |
Get the global maximum number of non-zero elements per row.
Definition at line 1114 of file system_matrix.cpp.
long bitpit::SparseMatrix::getNZCount | ( | ) | const |
Get the number of non-zero blocks/elements.
Definition at line 856 of file system_matrix.cpp.
long bitpit::SparseMatrix::getNZElementCount | ( | ) | const |
Get the number of non-zero elements.
This is the number of individual non-zero elements, NOT the number of non-zero blocks.
Definition at line 888 of file system_matrix.cpp.
long bitpit::SparseMatrix::getNZGlobalCount | ( | ) | const |
Get the global number of non-zero elements.
Definition at line 1082 of file system_matrix.cpp.
long bitpit::SparseMatrix::getNZGlobalElementCount | ( | ) | const |
Get the global number of non-zero elements.
Definition at line 1102 of file system_matrix.cpp.
long bitpit::SparseMatrix::getRowCount | ( | ) | const |
Get the number of rows of the matrix.
Definition at line 812 of file system_matrix.cpp.
long bitpit::SparseMatrix::getRowElementCount | ( | ) | const |
Get the number of rows of the matrix.
Definition at line 832 of file system_matrix.cpp.
long bitpit::SparseMatrix::getRowGlobalCount | ( | ) | const |
Get the number of global rows
Definition at line 994 of file system_matrix.cpp.
long bitpit::SparseMatrix::getRowGlobalElementCount | ( | ) | const |
Get the number of global rows
Definition at line 1014 of file system_matrix.cpp.
long bitpit::SparseMatrix::getRowGlobalElementOffset | ( | ) | const |
Get global row offset.
Definition at line 1026 of file system_matrix.cpp.
long bitpit::SparseMatrix::getRowGlobalOffset | ( | ) | const |
Get global row offset.
Definition at line 1004 of file system_matrix.cpp.
long bitpit::SparseMatrix::getRowNZCount | ( | long | row | ) | const |
Get the number of non-zero blocks/elements in the specified row.
Definition at line 866 of file system_matrix.cpp.
long bitpit::SparseMatrix::getRowNZElementCount | ( | long | row | ) | const |
Get the number of non-zero elements in the specified row.
This is the number of individual non-zero elements, NOT the number of non-zero blocks.
Definition at line 918 of file system_matrix.cpp.
ConstProxyVector< long > bitpit::SparseMatrix::getRowPattern | ( | long | row | ) | const |
Get the pattern of the specified row.
row | is the row |
Definition at line 1260 of file system_matrix.cpp.
void bitpit::SparseMatrix::getRowPattern | ( | long | row, |
ConstProxyVector< long > * | pattern ) const |
Get the pattern of the specified row.
row | is the row |
pattern | on output will contain the pattern of the specified row |
Definition at line 1274 of file system_matrix.cpp.
|
protected |
Get a constant pointer to the internal pattern of the specified row.
row | is the row |
Definition at line 1318 of file system_matrix.cpp.
|
protected |
Get a constant pointer to the internal pattern of the specified row.
row | is the row |
Definition at line 1329 of file system_matrix.cpp.
ConstProxyVector< double > bitpit::SparseMatrix::getRowValues | ( | long | row | ) | const |
Get the values of the specified row.
row | is the row |
Definition at line 1287 of file system_matrix.cpp.
void bitpit::SparseMatrix::getRowValues | ( | long | row, |
ConstProxyVector< double > * | values ) const |
Get the values of the specified row.
row | is the row |
values | on output will contain the values of the specified row |
Definition at line 1301 of file system_matrix.cpp.
|
protected |
Get a constant pointer to the internal values of the specified row.
The data of the row is stored using a block-row-major order: the rows of the single block elements are stored consecutively:
<row_1_block_1><row_1_block_2>...<row_2_block_1><row_2_block_2>...
row | is the row |
Definition at line 1350 of file system_matrix.cpp.
|
protected |
Get a constant pointer to the internal values of the specified row.
The data of the row is stored using a block-row-major order: the rows of the single block elements are stored consecutively:
<row_1_block_1><row_1_block_2>...<row_2_block_1><row_2_block_2>...
row | is the row |
Definition at line 1366 of file system_matrix.cpp.
void bitpit::SparseMatrix::initialize | ( | bool | partitioned, |
int | blockSize, | ||
long | nRows, | ||
long | nCols, | ||
long | nNZ ) |
Initialize the pattern.
partitioned | controls if the matrix is partitioned |
blockSize | is the block size of the matrix |
nRows | is the number rows of the matrix, if the matrix is partitioned this is the number of local rows |
nCols | is the number columns of the matrix, if the matrix is partitioned this is the number of local columns |
nNZ | is the number of non-zero blocks that the matrix will contain. If this number is unknown, an estimate (or zero) could be passed. If the actual number of non-zero elements turns out to be greater than the provided value, the initialization of the matrix will be slower because reallocation of internal data may be needed |
Definition at line 300 of file system_matrix.cpp.
void bitpit::SparseMatrix::initialize | ( | bool | partitioned, |
long | nRows, | ||
long | nCols, | ||
long | nNZ ) |
Initialize the pattern.
partitioned | controls if the matrix is partitioned |
nRows | is the number rows of the matrix, if the matrix is partitioned this is the number of local rows |
nCols | is the number columns of the matrix, if the matrix is partitioned this is the number of local columns |
nNZ | is the number of non-zero elements that the matrix will contain. If this number is unknown, an estimate (or zero) could be passed. If the actual number of non-zero elements turns out to be greater than the provided value, the initialization of the matrix will be slower because reallocation of internal data may be needed |
Definition at line 280 of file system_matrix.cpp.
void bitpit::SparseMatrix::initialize | ( | int | blockSize, |
long | nRows, | ||
long | nCols, | ||
long | nNZ ) |
Initialize the pattern.
blockSize | is the block size of the matrix |
nRows | is the number of rows of the matrix |
nCols | is the number of columns of the matrix |
nNZ | is the number of non-zero blocks that the matrix will contain. If this number is unknown, an estimate (or zero) could be passed. If the actual number of non-zero elements turns out to be greater than the provided value, the initialization of the matrix will be slower because reallocation of internal data may be needed |
Definition at line 334 of file system_matrix.cpp.
void bitpit::SparseMatrix::initialize | ( | long | nRows, |
long | nCols, | ||
long | nNZ ) |
Initialize the pattern.
nRows | is the number of rows of the matrix |
nCols | is the number of columns of the matrix |
nNZ | is the number of non-zero elements that the matrix will contain. If this number is unknown, an estimate (or zero) could be passed. If the actual number of non-zero elements turns out to be greater than the provided value, the initialization of the matrix will be slower because reallocation of internal data may be needed |
Definition at line 317 of file system_matrix.cpp.
|
protected |
Initialize the storage for the pattern.
Definition at line 641 of file system_matrix.cpp.
|
protected |
Initialize the storage for the values.
Definition at line 683 of file system_matrix.cpp.
bool bitpit::SparseMatrix::isAssembled | ( | ) | const |
Check if the matrix is assembled and ready for use.
Definition at line 769 of file system_matrix.cpp.
bool bitpit::SparseMatrix::isPartitioned | ( | ) | const |
Checks if the matrix is partitioned.
Definition at line 945 of file system_matrix.cpp.
void bitpit::SparseMatrix::squeeze | ( | ) |
Squeeze.
Requests the matrix to reduce its capacity to fit its size.
Definition at line 460 of file system_matrix.cpp.
|
protected |
Squeeze the storage for the pattern.
Requests the pattern storage to reduce its capacity to fit its size.
Definition at line 665 of file system_matrix.cpp.
|
protected |
Squeeze the storage for the values.
Requests the value storage to reduce its capacity to fit its size.
Definition at line 707 of file system_matrix.cpp.
|
protected |
Definition at line 141 of file system_matrix.hpp.
|
protected |
Definition at line 132 of file system_matrix.hpp.
|
protected |
Definition at line 145 of file system_matrix.hpp.
|
protected |
Definition at line 152 of file system_matrix.hpp.
|
protected |
Definition at line 150 of file system_matrix.hpp.
|
protected |
Definition at line 148 of file system_matrix.hpp.
|
protected |
Definition at line 149 of file system_matrix.hpp.
|
protected |
Definition at line 147 of file system_matrix.hpp.
|
protected |
Definition at line 151 of file system_matrix.hpp.
|
protected |
Definition at line 139 of file system_matrix.hpp.
|
protected |
Definition at line 137 of file system_matrix.hpp.
|
protected |
Definition at line 135 of file system_matrix.hpp.
|
protected |
Definition at line 136 of file system_matrix.hpp.
|
protected |
Definition at line 134 of file system_matrix.hpp.
|
protected |
Definition at line 144 of file system_matrix.hpp.
|
protected |
Definition at line 155 of file system_matrix.hpp.
|
protected |
Definition at line 156 of file system_matrix.hpp.