|
version GIT relicensing-7336-ga5359f9c0a 2026-12-03 09:40:02+00:00
|
#include <deal.II/lac/psblas_vector.h>
Implementation of a distributed parallel vector class based on PSBLAS (Parallel Sparse BLAS), which is the computational kernel of the PSCToolkit library.
This class stores a contiguous block of vector entries on each MPI process according to an IndexSet partitioning, and optionally maintains read-only ghost elements for entries owned by other processes. It supports the standard algebraic operations (addition, scaling, inner products, norms) as well as element-wise access. The interface is designed to be as close as possible to that of PETScWrappers::MPI::Vector.
A typical workflow for using this vector is as follows:
Definition at line 69 of file psblas_vector.h.
Classes | |
| class | VectorReference |
Public Types | |
| using | size_type = ::types::global_dof_index |
| using | value_type = double |
Public Member Functions | |
| Vector () | |
| Vector (const Vector &) | |
| Vector (const IndexSet &local_partitioning, const MPI_Comm communicator) | |
| Vector (const IndexSet &local_partitioning, const IndexSet &ghost_indices, const MPI_Comm communicator) | |
| ~Vector () | |
| void | reinit (const IndexSet &local_partitioning, const MPI_Comm communicator, const bool omit_zeroing_entries=false) |
| void | reinit (const Vector &v, const bool omit_zeroing_entries=false) |
| void | reinit (const IndexSet &local_partitioning, const IndexSet &ghost_indices, const MPI_Comm communicator) |
| Vector & | operator= (const Vector &v) |
| size_type | size () const override |
| virtual void | extract_subvector_to (const ArrayView< const types::global_dof_index > &indices, const ArrayView< value_type > &elements) const override |
| void | extract_subvector_to (const std::vector< size_type > &indices, std::vector< value_type > &values) const |
| template<typename ForwardIterator , typename OutputIterator > | |
| void | extract_subvector_to (ForwardIterator indices_begin, ForwardIterator indices_end, OutputIterator values_begin) const |
| size_type | locally_owned_size () const |
| void | set (const std::vector< size_type > &indices, const std::vector< value_type > &values) |
| void | add (const std::vector< size_type > &indices, const std::vector< value_type > &values) |
| void | add (const value_type s, const Vector &V) |
| void | add (const value_type s) |
| void | scale (const Vector &v) |
| value_type | add_and_dot (const value_type a, const Vector &v, const Vector &W) |
| void | sadd (const value_type s, const Vector &V) |
| void | sadd (const value_type s, const value_type a, const Vector &V) |
| void | equ (const value_type a, const Vector &v) |
| value_type | operator() (const size_type index) const |
| VectorReference | operator() (const size_type index) |
| value_type | operator[] (const size_type index) const |
| VectorReference | operator[] (const size_type index) |
| value_type | operator* (const Vector &v) const |
| Vector & | operator-= (const Vector &v) |
| Vector & | operator+= (const Vector &v) |
| Vector & | operator= (const value_type s) |
| const IndexSet & | locally_owned_elements () const |
| const IndexSet & | ghost_elements () const |
| bool | has_ghost_elements () const |
| void | update_ghost_values () const |
| void | swap (Vector &v) |
| void | compress (const VectorOperation::values operation) |
| value_type * | begin () |
| const value_type * | begin () const |
| value_type * | end () |
| const value_type * | end () const |
| MPI_Comm | get_mpi_communicator () const |
| psb_c_descriptor * | get_psblas_descriptor () const |
| psb_c_dvector * | get_psblas_vector () const |
| void | clear () |
| Vector::value_type | linfty_norm () const |
| Vector::value_type | l1_norm () const |
| Vector::value_type | l2_norm () const |
| Vector::value_type | mean_value () const |
| bool | all_zero () const |
| std::size_t | memory_consumption () 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 | |
| psb_c_dvector * | psblas_vector |
| psb_c_ctxt * | psblas_context |
| std::shared_ptr< psb_c_descriptor > | psblas_descriptor |
| MPI_Comm | communicator |
| IndexSet | owned_elements |
| IndexSet | ghost_indices |
| bool | ghosted |
| internal::State | state |
| VectorOperation::values | last_action |
| bool | remote_entries_pending |
| 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 | SparseMatrix |
| class | PreconditionAMG |
Definition at line 244 of file psblas_vector.h.
| using PSCToolkitWrappers::Vector::value_type = double |
Definition at line 246 of file psblas_vector.h.
Default constructor. Generates an empty (zero-size) vector.
Definition at line 29 of file psblas_vector.cc.
Copy constructor. Sets the dimension to that of the given vector, and copies all elements.
Definition at line 41 of file psblas_vector.cc.
|
explicit |
Construct a new parallel PSBLAS vector without ghost elements from an IndexSet.
Definition at line 65 of file psblas_vector.cc.
| Vector< Number >::Vector | ( | const IndexSet & | local_partitioning, |
| const IndexSet & | ghost_indices, | ||
| const MPI_Comm | communicator | ||
| ) |
Construct a new parallel ghosted PSBLAS vector from IndexSets.
Definition at line 76 of file psblas_vector.cc.
Destructor. Internally, its frees the PSBLAS vector and descriptor.
Definition at line 53 of file psblas_vector.cc.
| void Vector< Number >::reinit | ( | const IndexSet & | local_partitioning, |
| const MPI_Comm | communicator, | ||
| const bool | omit_zeroing_entries = false |
||
| ) |
Reinit as a vector without ghost elements. If omit_zeroing_entries is false, the vector is filled by zeros. Otherwise, the elements are left an unspecified state.
Definition at line 90 of file psblas_vector.cc.
Change the dimension to that of the vector v, and also take over the partitioning into local sizes as well as the MPI communicator. The same applies as for the other reinit function.
The elements of v are not copied, i.e. this function is the same as calling reinit(v.size(), v.locally_owned_size(), omit_zeroing_entries).
Definition at line 311 of file psblas_vector.cc.
| void Vector< Number >::reinit | ( | const IndexSet & | local_partitioning, |
| const IndexSet & | ghost_indices, | ||
| const MPI_Comm | communicator | ||
| ) |
Construct a new parallel ghosted PSBLAS vector from IndexSets.
Note that the ghost IndexSet may be empty and that any indices already contained in local are ignored during construction. The global indices in ghost are supplied as ghost indices so that they can be read locally.
Definition at line 175 of file psblas_vector.cc.
Copy assignment. The behavior of this class is the same as that of PETScWrappers::MPI::Vector class.
Resize the present vector if necessary. Also take over the MPI communicator of v. The semantics of this operator are complex. If the two vectors have the same size, and if either the left or right hand side vector of the assignment (i.e., either the input vector on the right hand side, or the calling vector to the left of the assignment operator) currently has ghost elements, then the left hand side vector will also have ghost values and will consequently be a read-only vector (see also the glossary entry on the issue). Otherwise, the left hand vector will be a writable vector after this operation. These semantics facilitate having a vector with ghost elements on the left hand side of the assignment, and a vector without ghost elements on the right hand side, with the resulting left hand side vector having the correct values in both its locally owned and its ghost elements. On the other hand, if the left hand side vector does not have the correct size yet, or is perhaps an entirely uninitialized vector, then the assignment is simply a copy operation in the usual sense: In that case, if the right hand side has no ghost elements (i.e., is a completely distributed vector), then the left hand side will have no ghost elements either. And if the right hand side has ghost elements (and is consequently read-only), then the left hand side will have these same properties after the operation.
Definition at line 348 of file psblas_vector.cc.
|
inlineoverridevirtual |
Return the global size of the vector, i.e. the sum of the local sizes over all MPI processes.
Implements ReadVector< double >.
Definition at line 807 of file psblas_vector.h.
|
inlineoverridevirtual |
Extract a range of elements all at once.
Implements ReadVector< double >.
Definition at line 871 of file psblas_vector.h.
|
inline |
Instead of getting individual elements of a vector via operator(), this function allows getting a whole set of elements at once. The indices of the elements to be read are stated in the first argument, the corresponding values are returned in the second.
If the current vector is called v, then this function is the equivalent to the code
indices and values arrays must be identical. Definition at line 882 of file psblas_vector.h.
|
inline |
Instead of getting individual elements of a vector via operator(), this function allows getting a whole set of elements at once. In contrast to the previous function, this function obtains the indices of the elements by dereferencing all elements of the iterator range provided by the first two arguments, and puts the vector values into memory locations obtained by dereferencing a range of iterators starting at the location pointed to by the third argument.
If the current vector is called v, then this function is the equivalent to the code
values_begin as there are iterators between indices_begin and indices_end. Definition at line 893 of file psblas_vector.h.
| Vector::size_type Vector< Number >::locally_owned_size | ( | ) | const |
Return the local dimension of the vector, i.e. the number of elements stored on the present MPI process. For sequential vectors, this number is the same as size(), but for parallel vectors it may be smaller.
To figure out which elements exactly are stored locally, use locally_owned_elements().
Definition at line 531 of file psblas_vector.cc.
| void Vector< Number >::set | ( | const std::vector< size_type > & | indices, |
| const std::vector< value_type > & | values | ||
| ) |
A collective set operation: instead of setting individual elements of a vector, this function allows to set a whole set of elements at once. The indices of the elements to be set are stated in the first argument, the corresponding values in the second.
Definition at line 580 of file psblas_vector.cc.
| void Vector< Number >::add | ( | const std::vector< size_type > & | indices, |
| const std::vector< value_type > & | values | ||
| ) |
A collective add operation: This function adds a whole set of values stored in values to the vector components specified by indices.
Definition at line 602 of file psblas_vector.cc.
| void Vector< Number >::add | ( | const value_type | s, |
| const Vector & | V | ||
| ) |
Addition of a multiple of a vector, i.e. *this += s*V.
Definition at line 644 of file psblas_vector.cc.
| void Vector< Number >::add | ( | const value_type | s | ) |
Addition of s to all components.
Definition at line 659 of file psblas_vector.cc.
Scale each element of this vector by the corresponding element in the argument. This function is mostly meant to simulate multiplication (and immediate re-assignment) by a diagonal scaling matrix.
Definition at line 700 of file psblas_vector.cc.
| Vector::value_type Vector< Number >::add_and_dot | ( | const value_type | a, |
| const Vector & | v, | ||
| const Vector & | W | ||
| ) |
Performs a combined operation of a vector addition and a subsequent inner product, returning the value of the inner product. In other words, the result of this function is the same as if the user called
Definition at line 718 of file psblas_vector.cc.
| void Vector< Number >::sadd | ( | const value_type | s, |
| const Vector & | V | ||
| ) |
Definition at line 675 of file psblas_vector.cc.
| void Vector< Number >::sadd | ( | const value_type | s, |
| const value_type | a, | ||
| const Vector & | V | ||
| ) |
Definition at line 689 of file psblas_vector.cc.
| void Vector< Number >::equ | ( | const value_type | a, |
| const Vector & | v | ||
| ) |
Definition at line 516 of file psblas_vector.cc.
|
inline |
Provide read-only access to an element.
Definition at line 839 of file psblas_vector.h.
|
inline |
Provide read-write access to an element of the vector.
Definition at line 847 of file psblas_vector.h.
|
inline |
Provide read-only access to an element.
Definition at line 855 of file psblas_vector.h.
|
inline |
Provide read-write access to an element of the vector.
Definition at line 863 of file psblas_vector.h.
| Vector::value_type Vector< Number >::operator* | ( | const Vector & | v | ) | const |
Dot product of the vector with another vector.
Definition at line 539 of file psblas_vector.cc.
Subtract the given vector from the present one.
Definition at line 565 of file psblas_vector.cc.
Add the given vector from the present one.
Definition at line 550 of file psblas_vector.cc.
| Vector & Vector< Number >::operator= | ( | const value_type | s | ) |
Set all components of the vector to the given number s. Simply pass this down to the individual block objects, but we still need to declare this function to make the example given in the discussion about making the constructor explicit work.
Since the semantics of assigning a scalar to a vector are not immediately clear, this operator should really only be used if you want to set the entire vector to zero. This allows the intuitive notation v=0.
Definition at line 392 of file psblas_vector.cc.
Return an index set that describes which elements of this vector are owned by the current processor. Note that this index set does not include elements this vector may store locally as ghost elements but that are in fact owned by another processor. As a consequence, the index sets returned on different processors if this is a distributed vector will form disjoint sets that add up to the complete index set. Obviously, if a vector is created on only one processor, then the result would satisfy
Definition at line 815 of file psblas_vector.h.
Return the IndexSet of ghost elements.
Definition at line 823 of file psblas_vector.h.
Return if the vector contains ghost elements.
Definition at line 831 of file psblas_vector.h.
| void Vector< Number >::update_ghost_values | ( | ) | const |
Update ghosted elements.
Definition at line 839 of file psblas_vector.cc.
Swap the contents of this vector and the other vector v. This function only swaps the pointers to the data of the two vectors and therefore does not need to allocate temporary storage and move data around.
This function is analogous to the swap function of all C++ standard containers.
Definition at line 731 of file psblas_vector.cc.
| void Vector< Number >::compress | ( | const VectorOperation::values | operation | ) |
Compress the underlying representation of the PSBLAS object, i.e. flush the buffers of the vector object if it has any. This function is necessary after writing into a vector element-by-element and before anything else can be done on it.
Definition at line 751 of file psblas_vector.cc.
|
inline |
Return an iterator to the start of the locally owned elements of the vector.
Definition at line 775 of file psblas_vector.h.
|
inline |
Return a constant iterator to the start of the locally owned elements of the vector.
Definition at line 783 of file psblas_vector.h.
|
inline |
Return an iterator to the element past the end of the locally owned elements of the vector.
Definition at line 791 of file psblas_vector.h.
|
inline |
Return a constant iterator to the element past the end of the locally owned elements of the vector.
Definition at line 799 of file psblas_vector.h.
Definition at line 404 of file psblas_vector.cc.
| psb_c_descriptor * Vector< Number >::get_psblas_descriptor | ( | ) | const |
Get the underlying PSBLAS descriptor. Use it only when you know what you are doing.
Definition at line 412 of file psblas_vector.cc.
| psb_c_dvector * Vector< Number >::get_psblas_vector | ( | ) | const |
Get a pointer to the underlying PSBLAS vector. Use it only when you know what you are doing.
Definition at line 420 of file psblas_vector.cc.
| void Vector< Number >::clear | ( | ) |
Release all memory and return to a state just like after having called the default constructor.
Definition at line 428 of file psblas_vector.cc.
| Vector::value_type Vector< Number >::linfty_norm | ( | ) | const |
\(l_\infty\)-norm of the vector. Return the value of the vector element with the maximum absolute value.
Definition at line 450 of file psblas_vector.cc.
| Vector::value_type Vector< Number >::l1_norm | ( | ) | const |
\(l_1\)-norm of the vector. The sum of the absolute values.
Definition at line 460 of file psblas_vector.cc.
| Vector::value_type Vector< Number >::l2_norm | ( | ) | const |
\(l_2\)-norm of the vector. The square root of the sum of the squares of the elements.
Definition at line 470 of file psblas_vector.cc.
| Vector::value_type Vector< Number >::mean_value | ( | ) | const |
Compute the mean value of the vector.
Definition at line 480 of file psblas_vector.cc.
Return whether the vector contains only elements with value zero. This is a collective operation. This function is expensive, because potentially all elements have to be checked.
Definition at line 495 of file psblas_vector.cc.
| std::size_t Vector< Number >::memory_consumption | ( | ) | const |
Estimate for the memory consumption (not implemented for this class).
Definition at line 850 of file psblas_vector.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 sparse matrix type used
Typedef for the sparse matrix type used.
Definition at line 765 of file psblas_vector.h.
|
friend |
Typedef for the AMG preconditioner type.
Definition at line 767 of file psblas_vector.h.
|
private |
Definition at line 713 of file psblas_vector.h.
|
private |
Definition at line 718 of file psblas_vector.h.
|
private |
Definition at line 723 of file psblas_vector.h.
|
private |
The MPI communicator over which the vector is distributed.
Definition at line 728 of file psblas_vector.h.
|
private |
This IndexSet contains the global indices of the locally owned values.
Definition at line 733 of file psblas_vector.h.
|
private |
This IndexSet contains the global indices of the ghost values.
Definition at line 738 of file psblas_vector.h.
|
private |
Denotes if this vector has ghost indices associated with it. This means that at least one of the processes in a parallel program has at least one ghost index.
Definition at line 745 of file psblas_vector.h.
|
private |
State of the descriptor associated with the vector. Its state can be either default, building or assembled).
Definition at line 751 of file psblas_vector.h.
|
private |
Member variable storing if the last operation done on the vector was a write or an add operation.
Definition at line 757 of file psblas_vector.h.
|
private |
Whether contributions to entries owned by other processes have been handed to PSBLAS and still need to be exchanged by compress().
Definition at line 763 of file psblas_vector.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.