|
version GIT relicensing-7336-ga5359f9c0a 2026-12-03 09:40:02+00:00
|
#include <deal.II/lac/psblas_sparse_matrix.h>
Implementation of a distributed parallel sparse matrix class based on PSBLAS (Parallel Sparse BLAS), which is the computational kernel of the PSCToolkit library.
Rows of the matrix are distributed across MPI processes according to an IndexSet partitioning (just as for the Vector class). The matrix supports element-wise set/add assembly as well as matrix-vector products (vmult(), Tvmult(), and their _add variants).
A typical workflow for using this matrix is as follows:
A SparsityPattern can optionally be provided at construction time to pre-allocate the non-zero structure, which is strongly recommended for performance.
Definition at line 65 of file psblas_sparse_matrix.h.
Public Types | |
| using | size_type = ::types::global_dof_index |
| using | value_type = double |
Public Member Functions | |
| SparseMatrix () | |
| ~SparseMatrix () | |
| SparseMatrix (const SparsityPattern &psblas_sparsity_pattern, const MPI_Comm communicator=MPI_COMM_WORLD) | |
| SparseMatrix (const SparseMatrix &)=delete | |
| SparseMatrix & | operator= (const SparseMatrix &)=delete |
| SparseMatrix & | operator= (const value_type d)=delete |
| void | copy_from (const SparseMatrix &other) |
| void | reinit (const IndexSet ¶llel_partitioning, const MPI_Comm communicator=MPI_COMM_WORLD) |
| void | reinit (const SparsityPattern &psblas_sparsity_pattern, const MPI_Comm communicator=MPI_COMM_WORLD) |
| void | reinit (const IndexSet &local_rows, const DynamicSparsityPattern &sparsity_pattern, const MPI_Comm communicator=MPI_COMM_WORLD) |
| size_type | m () const |
| size_type | n () const |
| size_type | local_size () const |
| std::pair< size_type, size_type > | local_range () const |
| bool | in_local_range (const size_type index) const |
| size_type | n_nonzero_elements () const |
| value_type | el (const size_type i, const size_type j) const |
| value_type | diag_element (const size_type i) const |
| value_type | operator() (const size_type i, const size_type j) const |
| void | set (const size_type i, const size_type j, const value_type value) |
| void | set (const std::vector< size_type > &indices, const FullMatrix< double > &matrix) |
| void | add (const size_type i, const size_type j, const value_type value) |
| void | add (const size_type row, const std::vector< size_type > &col_indices, const std::vector< value_type > &values, const bool=false) |
| void | add (const size_type row, const size_type ncols, const std::vector< size_type > &col_indices, const value_type *values, const bool=false, const bool=false) |
| void | add (const size_type row, const size_type ncols, const std::vector< size_type > &col_indices, const std::vector< value_type > &values, const bool=false, const bool=false) |
| void | add (const size_type row, const size_type n_cols, const size_type *col_indices, const value_type *values, const bool elide_zero_values=true, const bool col_indices_are_sorted=false) |
| void | compress () |
| void | vmult (Vector &dst, const Vector &src) const |
| void | vmult_add (Vector &dst, const Vector &src) const |
| void | Tvmult (Vector &dst, const Vector &src) const |
| void | Tvmult_add (Vector &dst, const Vector &src) const |
| value_type | l1_norm () const |
| value_type | linfty_norm () const |
| value_type | frobenius_norm () const |
| value_type | trace () const |
| psb_c_dspmat * | get_psblas_matrix () const |
| psb_c_descriptor * | get_psblas_descriptor () const |
| MPI_Comm | get_mpi_communicator () const |
| template<class Archive > | |
| void | serialize (Archive &ar, const unsigned int version) |
Querying the observer pointers an object has. | |
| unsigned int | n_subscriptions () const |
| template<typename StreamType > | |
| void | list_subscribers (StreamType &stream) const |
| void | list_subscribers () const |
Static Public Member Functions | |
| static ::ExceptionBase & | ExcInUse (int arg1, std::string arg2, std::string arg3) |
| static ::ExceptionBase & | ExcNoSubscriber (std::string arg1, std::string arg2) |
Private Member Functions | |
EnableObserverPointer functionality | |
Classes derived from EnableObserverPointer provide a facility to subscribe to this object. This is mostly used by the ObserverPointer class. | |
| void | subscribe (std::atomic< bool > *const validity, const std::string &identifier="") const |
| void | unsubscribe (std::atomic< bool > *const validity, const std::string &identifier="") const |
| void | check_no_subscribers () const noexcept |
Private Attributes | |
| MPI_Comm | communicator |
| psb_c_dspmat * | psblas_sparse_matrix |
| std::shared_ptr< psb_c_descriptor > | psblas_descriptor |
| psb_c_ctxt * | psblas_context |
| internal::State | state |
| std::atomic< unsigned int > | counter |
| std::map< std::string, unsigned int > | counter_map |
| std::vector< std::atomic< bool > * > | validity_pointers |
| const std::type_info * | object_info |
Static Private Attributes | |
| static std::mutex | mutex |
Friends | |
| class | PreconditionAMG |
Type for container size.
Definition at line 71 of file psblas_sparse_matrix.h.
| using PSCToolkitWrappers::SparseMatrix::value_type = double |
Type for container values.
Definition at line 76 of file psblas_sparse_matrix.h.
| SparseMatrix< number >::SparseMatrix | ( | ) |
Default constructor. Generates an empty (zero-size) matrix.
Definition at line 36 of file psblas_sparse_matrix.cc.
| SparseMatrix< number >::~SparseMatrix | ( | ) |
Destructor. Internally, its frees the PSBLAS sparse matrix.
Definition at line 68 of file psblas_sparse_matrix.cc.
| SparseMatrix< number >::SparseMatrix | ( | const SparsityPattern & | psblas_sparsity_pattern, |
| const MPI_Comm | communicator = MPI_COMM_WORLD |
||
| ) |
Generate a matrix from a PSBLAS SparsityPattern.
Definition at line 42 of file psblas_sparse_matrix.cc.
|
delete |
Copy-constructor is deleted.
|
delete |
Copy assignment is deleted.
|
delete |
Assignment of a scalar to all elements of the matrix is deleted.
| void SparseMatrix< number >::copy_from | ( | const SparseMatrix & | other | ) |
Copy the contents of another SparseMatrix into this one.
Definition at line 81 of file psblas_sparse_matrix.cc.
| void SparseMatrix< number >::reinit | ( | const IndexSet & | parallel_partitioning, |
| const MPI_Comm | communicator = MPI_COMM_WORLD |
||
| ) |
Initialize using an IndexSet and a MPI communicator to describe the parallel partitioning of the matrix.
Definition at line 91 of file psblas_sparse_matrix.cc.
| void SparseMatrix< number >::reinit | ( | const SparsityPattern & | psblas_sparsity_pattern, |
| const MPI_Comm | communicator = MPI_COMM_WORLD |
||
| ) |
Initialize using an IndexSet and a MPI communicator to describe the parallel partitioning of the matrix.
Definition at line 147 of file psblas_sparse_matrix.cc.
| void SparseMatrix< number >::reinit | ( | const IndexSet & | local_rows, |
| const DynamicSparsityPattern & | sparsity_pattern, | ||
| const MPI_Comm | communicator = MPI_COMM_WORLD |
||
| ) |
Initialize a square matrix where the size() of the IndexSet determines the number of rows and columns.
Definition at line 181 of file psblas_sparse_matrix.cc.
| SparseMatrix::size_type SparseMatrix< number >::m | ( | ) | const |
Return the number of rows in this matrix.
Definition at line 335 of file psblas_sparse_matrix.cc.
| SparseMatrix::size_type SparseMatrix< number >::n | ( | ) | const |
Return the number of columns in this matrix.
Definition at line 343 of file psblas_sparse_matrix.cc.
| SparseMatrix::size_type SparseMatrix< number >::local_size | ( | ) | const |
Return the local dimension of the matrix, i.e. the number of rows stored on the present MPI process. For sequential matrices, this number is the same as m(), but for parallel matrices it may be smaller. To figure out which elements exactly are stored locally, use local_range().
Definition at line 303 of file psblas_sparse_matrix.cc.
| std::pair< SparseMatrix::size_type, SparseMatrix::size_type > SparseMatrix< number >::local_range | ( | ) | const |
Return a pair of indices indicating which rows of this matrix are stored locally. The first number is the index of the first row stored, the second the index of the one past the last one that is stored locally. If this is a sequential matrix, then the result will be the pair (0,m()), otherwise it will be a pair (i,i+n), where n=local_size().
Definition at line 310 of file psblas_sparse_matrix.cc.
| bool SparseMatrix< number >::in_local_range | ( | const size_type | index | ) | const |
Return whether index is in the local range or not, see also local_range().
Definition at line 326 of file psblas_sparse_matrix.cc.
| SparseMatrix::size_type SparseMatrix< number >::n_nonzero_elements | ( | ) | const |
Return the number of nonzero elements of this matrix.
Definition at line 351 of file psblas_sparse_matrix.cc.
| SparseMatrix::value_type SparseMatrix< number >::el | ( | const size_type | i, |
| const size_type | j | ||
| ) | const |
Return the value of the matrix entry (i,j).
Definition at line 376 of file psblas_sparse_matrix.cc.
| SparseMatrix::value_type SparseMatrix< number >::diag_element | ( | const size_type | i | ) | const |
Return the diagonal element of the matrix at row i.
Definition at line 393 of file psblas_sparse_matrix.cc.
| SparseMatrix::value_type SparseMatrix< number >::operator() | ( | const size_type | i, |
| const size_type | j | ||
| ) | const |
Return the element (i,j) of the matrix. This function is equivalent to the el() function.
Definition at line 402 of file psblas_sparse_matrix.cc.
| void SparseMatrix< number >::set | ( | const size_type | i, |
| const size_type | j, | ||
| const value_type | value | ||
| ) |
Set the element (i,j) to 'value'. If value is not a finite number an exception is thrown.
Definition at line 359 of file psblas_sparse_matrix.cc.
| void SparseMatrix< number >::set | ( | const std::vector< size_type > & | indices, |
| const FullMatrix< double > & | matrix | ||
| ) |
Set all elements given in a FullMatrix into the sparse matrix locations given by indices. In other words, this function writes the elements in full_matrix into the calling matrix, using the local-to-global indexing specified by indices for both the rows and the columns of the matrix. This function assumes a quadratic sparse matrix and a quadratic full_matrix, the usual situation in FE calculations.
Definition at line 436 of file psblas_sparse_matrix.cc.
| void SparseMatrix< number >::add | ( | const size_type | i, |
| const size_type | j, | ||
| const value_type | value | ||
| ) |
Add value 'value' to the element (i,j). If value is not a finite number an exception is thrown.
Definition at line 482 of file psblas_sparse_matrix.cc.
| void PSCToolkitWrappers::SparseMatrix::add | ( | const size_type | row, |
| const std::vector< size_type > & | col_indices, | ||
| const std::vector< value_type > & | values, | ||
| const bool | = false |
||
| ) |
Set several elements in the specified row of the matrix with column indices as given by col_indices to the respective value.
| void SparseMatrix< number >::add | ( | const size_type | row, |
| const size_type | ncols, | ||
| const std::vector< size_type > & | col_indices, | ||
| const value_type * | values, | ||
| const bool | = false, |
||
| const bool | = false |
||
| ) |
Add an array of values given by values in the given global matrix row at columns specified by col_indices in the sparse matrix.
Definition at line 502 of file psblas_sparse_matrix.cc.
| void SparseMatrix< number >::add | ( | const size_type | row, |
| const size_type | ncols, | ||
| const std::vector< size_type > & | col_indices, | ||
| const std::vector< value_type > & | values, | ||
| const bool | = false, |
||
| const bool | = false |
||
| ) |
Same as above, but with a vector of values instead of a pointer to an array. The vector must have the same size as the number of columns given by ncols and the size of col_indices.
Definition at line 518 of file psblas_sparse_matrix.cc.
| void SparseMatrix< number >::add | ( | const size_type | row, |
| const size_type | n_cols, | ||
| const size_type * | col_indices, | ||
| const value_type * | values, | ||
| const bool | elide_zero_values = true, |
||
| const bool | col_indices_are_sorted = false |
||
| ) |
Same as above, but using raw pointers for the column indices and values. The array of column indices must have the same size as ncols, and the array of values must have the same size as ncols as well.
Definition at line 535 of file psblas_sparse_matrix.cc.
| void SparseMatrix< number >::compress | ( | ) |
Compress the matrix after all insertions have been done.
Definition at line 562 of file psblas_sparse_matrix.cc.
| void SparseMatrix< number >::vmult | ( | Vector & | dst, |
| const Vector & | src | ||
| ) | const |
Matrix-vector multiplication: let dst = M*src with M being this matrix.
Source and destination must not be the same vector.
Definition at line 586 of file psblas_sparse_matrix.cc.
| void SparseMatrix< number >::vmult_add | ( | Vector & | dst, |
| const Vector & | src | ||
| ) | const |
Adding matrix-vector multiplication: Add M*src to dst with M being this matrix.
Source and destination must not be the same vector.
Definition at line 608 of file psblas_sparse_matrix.cc.
| void SparseMatrix< number >::Tvmult | ( | Vector & | dst, |
| const Vector & | src | ||
| ) | const |
Matrix-vector multiplication: let dst = MT*src with M being this matrix. This function does the same as vmult() but takes the transposed matrix.
Source and destination must not be the same vector.
Definition at line 630 of file psblas_sparse_matrix.cc.
| void SparseMatrix< number >::Tvmult_add | ( | Vector & | dst, |
| const Vector & | src | ||
| ) | const |
Adding matrix-vector multiplication: Add M^T*src to dst with M being this matrix.
Source and destination must not be the same vector.
Definition at line 655 of file psblas_sparse_matrix.cc.
| SparseMatrix::value_type SparseMatrix< number >::l1_norm | ( | ) | const |
Return the l1-norm of the matrix.
Definition at line 680 of file psblas_sparse_matrix.cc.
| SparseMatrix::value_type SparseMatrix< number >::linfty_norm | ( | ) | const |
Return the linfty-norm of the matrix.
Definition at line 688 of file psblas_sparse_matrix.cc.
| SparseMatrix::value_type SparseMatrix< number >::frobenius_norm | ( | ) | const |
Return the Frobenius of the matrix.
Definition at line 696 of file psblas_sparse_matrix.cc.
| SparseMatrix::value_type SparseMatrix< number >::trace | ( | ) | const |
Returns the trace of the matrix, i.e., the sum of the diagonal elements.
Definition at line 704 of file psblas_sparse_matrix.cc.
| psb_c_dspmat * SparseMatrix< number >::get_psblas_matrix | ( | ) | const |
Get the underlying PSBLAS sparse matrix. Do not use this function unless you know what you are doing.
Definition at line 412 of file psblas_sparse_matrix.cc.
| psb_c_descriptor * SparseMatrix< number >::get_psblas_descriptor | ( | ) | const |
Get the underlying PSBLAS descriptor. Do not use this function unless you know what you are doing.
Definition at line 420 of file psblas_sparse_matrix.cc.
| MPI_Comm SparseMatrix< number >::get_mpi_communicator | ( | ) | const |
Return the underlying MPI communicator. Do not use this function unless you know what you are doing.
Definition at line 428 of file psblas_sparse_matrix.cc.
|
inlineinherited |
Return the present number of subscriptions to this object. This allows to use this class for reference counted lifetime determination where the last one to unsubscribe also deletes the object.
Definition at line 318 of file enable_observer_pointer.h.
|
inlineinherited |
List the subscribers to the input stream.
Definition at line 335 of file enable_observer_pointer.h.
|
inherited |
List the subscribers to deallog.
Definition at line 200 of file enable_observer_pointer.cc.
|
inlineinherited |
Read or write the data of this object to or from a stream for the purpose of serialization using the BOOST serialization library.
This function does not actually serialize any of the member variables of this class. The reason is that what this class stores is only who subscribes to this object, but who does so at the time of storing the contents of this object does not necessarily have anything to do with who subscribes to the object when it is restored. Consequently, we do not want to overwrite the subscribers at the time of restoring, and then there is no reason to write the subscribers out in the first place.
Definition at line 327 of file enable_observer_pointer.h.
|
privateinherited |
Subscribes a user of the object by storing the pointer validity. The subscriber may be identified by text supplied as identifier.
Definition at line 136 of file enable_observer_pointer.cc.
|
privateinherited |
Unsubscribes a user from the object.
identifier and the validity pointer must be the same as the one supplied to subscribe(). Definition at line 154 of file enable_observer_pointer.cc.
|
privatenoexceptinherited |
Check that there are no objects subscribing to this object. If this check passes then it is safe to destroy the current object. It this check fails then this function will either abort or print an error message to deallog (by using the AssertNothrow mechanism), but will not throw an exception.
Definition at line 58 of file enable_observer_pointer.cc.
|
friend |
Typedef for the AMG preconditioner type.
Definition at line 408 of file psblas_sparse_matrix.h.
|
private |
The underlying MPI communicator.
Definition at line 385 of file psblas_sparse_matrix.h.
|
private |
Pointer the underlying PSBLAS sparse matrix.
Definition at line 390 of file psblas_sparse_matrix.h.
|
private |
Shared pointer to the underlying PSBLAS descriptor object.
Definition at line 395 of file psblas_sparse_matrix.h.
|
private |
Pointer to the underlying PSBLAS context object.
Definition at line 400 of file psblas_sparse_matrix.h.
|
private |
State of the descriptor associated with the vector. Its state can be either default, building or assembled).
Definition at line 406 of file psblas_sparse_matrix.h.
|
mutableprivateinherited |
Store the number of objects which subscribed to this object. Initially, this number is zero, and upon destruction it shall be zero again (i.e. all objects which subscribed should have unsubscribed again).
The creator (and owner) of an object is counted in the map below if HE manages to supply identification.
We use the mutable keyword in order to allow subscription to constant objects also.
This counter may be read from and written to concurrently in multithreaded code: hence we use the std::atomic class template.
Definition at line 212 of file enable_observer_pointer.h.
|
mutableprivateinherited |
In this map, we count subscriptions for each different identification string supplied to subscribe().
Definition at line 218 of file enable_observer_pointer.h.
|
mutableprivateinherited |
In this vector, we store pointers to the validity bool in the ObserverPointer objects that subscribe to this class.
Definition at line 224 of file enable_observer_pointer.h.
|
mutableprivateinherited |
Pointer to the typeinfo object of this object, from which we can later deduce the class name. Since this information on the derived class is neither available in the destructor, nor in the constructor, we obtain it in between and store it here.
Definition at line 232 of file enable_observer_pointer.h.
|
staticprivateinherited |
A mutex used to ensure data consistency when accessing the mutable members of this class. This lock is used in the subscribe() and unsubscribe() functions, as well as in list_subscribers().
Definition at line 239 of file enable_observer_pointer.h.