![]() |
deal.II version GIT relicensing-6809-ge913b9bb34 2026-09-25 17:20:01+00:00
|
#include <deal.II/lac/trilinos_epetra_vector.h>
This class implements a wrapper to the Trilinos distributed vector class Epetra_FEVector. This class requires Trilinos to be compiled with MPI support.
Definition at line 229 of file trilinos_epetra_vector.h.
Public Types | |
| using | value_type = VectorTraits::value_type |
| using | size_type = VectorTraits::size_type |
| using | real_type = value_type |
| using | reference = internal::VectorReference |
| using | const_reference = const internal::VectorReference |
Public Member Functions | |
| virtual void | extract_subvector_to (const ArrayView< const types::global_dof_index > &indices, const ArrayView< VectorTraits::value_type > &elements) const=0 |
| template<class Archive > | |
| void | serialize (Archive &ar, const unsigned int version) |
1: Basic Object-handling | |
| Vector () | |
| Vector (const Vector &V) | |
| Vector (const IndexSet ¶llel_partitioner, const MPI_Comm communicator) | |
| void | reinit (const IndexSet ¶llel_partitioner, const MPI_Comm communicator, const bool omit_zeroing_entries=false) |
| void | reinit (const Vector &V, const bool omit_zeroing_entries=false) |
| virtual void | extract_subvector_to (const ArrayView< const types::global_dof_index > &indices, const ArrayView< double > &elements) const override |
| Vector & | operator= (const Vector &V) |
| Vector & | operator= (const double s) |
| void | import_elements (const ReadWriteVector< double > &V, VectorOperation::values operation, const std::shared_ptr< const Utilities::MPI::CommunicationPatternBase > &communication_pattern={}) |
2: Data-Access | |
| reference | operator() (const size_type index) |
| value_type | operator() (const size_type index) const |
| reference | operator[] (const size_type index) |
| value_type | operator[] (const size_type index) const |
3: Modification of vectors | |
| Vector & | operator*= (const double factor) |
| Vector & | operator/= (const double factor) |
| Vector & | operator+= (const Vector &V) |
| Vector & | operator-= (const Vector &V) |
| double | operator* (const Vector &V) const |
| void | add (const double a) |
| void | add (const double a, const Vector &V) |
| void | add (const double a, const Vector &V, const double b, const Vector &W) |
| void | sadd (const double s, const double a, const Vector &V) |
| void | scale (const Vector &scaling_factors) |
| void | equ (const double a, const Vector &V) |
| bool | all_zero () const |
4: Scalar products, norms and related operations | |
| double | mean_value () const |
| double | l1_norm () const |
| double | l2_norm () const |
| double | linfty_norm () const |
| double | add_and_dot (const double a, const Vector &V, const Vector &W) |
5: Scalar products, norms and related operations | |
| bool | has_ghost_elements () const |
| virtual size_type | size () const override |
| size_type | locally_owned_size () const |
| MPI_Comm | get_mpi_communicator () const |
| ::IndexSet | locally_owned_elements () const |
6: Mixed stuff | |
| void | compress (const VectorOperation::values operation) |
| const Epetra_FEVector & | trilinos_vector () const |
| Epetra_FEVector & | trilinos_vector () |
| void | print (std::ostream &out, const unsigned int precision=3, const bool scientific=true, const bool across=true) const |
| std::size_t | memory_consumption () const |
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 & | ExcDifferentParallelPartitioning () |
| static ::ExceptionBase & | ExcVectorTypeNotCompatible () |
| static ::ExceptionBase & | ExcTrilinosError (int arg1) |
| static ::ExceptionBase & | ExcInUse (int arg1, std::string arg2, std::string arg3) |
| static ::ExceptionBase & | ExcNoSubscriber (std::string arg1, std::string arg2) |
Private Member Functions | |
| void | create_epetra_comm_pattern (const IndexSet &source_index_set, const MPI_Comm mpi_comm) |
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 | |
| std::unique_ptr< Epetra_FEVector > | vector |
| ::IndexSet | source_stored_elements |
| std::shared_ptr< const CommunicationPattern > | epetra_comm_pattern |
| 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 | internal::VectorReference |
Definition at line 234 of file trilinos_epetra_vector.h.
Definition at line 235 of file trilinos_epetra_vector.h.
Definition at line 236 of file trilinos_epetra_vector.h.
| using LinearAlgebra::EpetraWrappers::Vector::reference = internal::VectorReference |
Definition at line 237 of file trilinos_epetra_vector.h.
| using LinearAlgebra::EpetraWrappers::Vector::const_reference = const internal::VectorReference |
Definition at line 238 of file trilinos_epetra_vector.h.
Constructor. Create a vector of dimension zero.
Definition at line 90 of file trilinos_epetra_vector.cc.
Copy constructor. Sets the dimension and the partitioning to that of the given vector and copies all elements.
Definition at line 97 of file trilinos_epetra_vector.cc.
|
explicit |
This constructor takes an IndexSet that defines how to distribute the individual components among the MPI processors. Since it also includes information about the size of the vector, this is all we need to generate a parallel vector.
Definition at line 103 of file trilinos_epetra_vector.cc.
| void Vector< Number >::reinit | ( | const IndexSet & | parallel_partitioner, |
| const MPI_Comm | communicator, | ||
| const bool | omit_zeroing_entries = false |
||
| ) |
Reinit functionality. This function destroys the old vector content and generates a new one based on the input partitioning. The flag omit_zeroing_entries determines whether the vector should be filled with zeros (false) or left in an undetermined state (true).
Definition at line 112 of file trilinos_epetra_vector.cc.
Change the dimension to that of the vector V. The elements of V are not copied.
Definition at line 130 of file trilinos_epetra_vector.cc.
|
overridevirtual |
Extract a range of elements all at once.
Definition at line 140 of file trilinos_epetra_vector.cc.
Copy function. This function takes a Vector and copies all the elements. The Vector will have the same parallel distribution as 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 160 of file trilinos_epetra_vector.cc.
Sets all elements of the vector to the scalar s. This operation is only allowed if s is equal to zero.
Because this operation modifies the vector, it is only allowed to call this function on vectors that have no ghost entries. However, as a special case, assigning zero to the entire vector by writing v=0; where v is a variable of the current type is allowed as we interpret it as equivalent to creating a new, zero-initialized vector. See vectors with ghost elements for more on writing into vectors with ghost elements.
Definition at line 189 of file trilinos_epetra_vector.cc.
| void Vector< Number >::import_elements | ( | const ReadWriteVector< double > & | V, |
| VectorOperation::values | operation, | ||
| const std::shared_ptr< const Utilities::MPI::CommunicationPatternBase > & | communication_pattern = {} |
||
| ) |
Imports all the elements present in the vector's IndexSet from the input vector V. VectorOperation::values operation is used to decide if the elements in V should be added to the current vector or replace the current elements. The last parameter can be used if the same communication pattern is used multiple times. This can be used to improve performance.
Definition at line 204 of file trilinos_epetra_vector.cc.
Provide access to a given element, both read and write.
When using a vector distributed with MPI, this operation only makes sense for elements that are actually present on the calling processor. Otherwise, an exception is thrown.
Definition at line 802 of file trilinos_epetra_vector.h.
| value_type LinearAlgebra::EpetraWrappers::Vector::operator() | ( | const size_type | index | ) | const |
Provide read-only access to an element.
When using a vector distributed with MPI, this operation only makes sense for elements that are actually present on the calling processor. Otherwise, an exception is thrown.
Provide access to a given element, both read and write.
Exactly the same as operator().
Definition at line 808 of file trilinos_epetra_vector.h.
|
inline |
Provide read-only access to an element.
Exactly the same as operator().
Definition at line 814 of file trilinos_epetra_vector.h.
Multiply the entire vector by a fixed factor.
Definition at line 259 of file trilinos_epetra_vector.cc.
Divide the entire vector by a fixed factor.
Definition at line 274 of file trilinos_epetra_vector.cc.
Add the vector V to the present one.
Definition at line 290 of file trilinos_epetra_vector.cc.
Subtract the vector V from the present one.
Definition at line 320 of file trilinos_epetra_vector.cc.
Return the scalar product of two vectors. The vectors need to have the same layout.
Definition at line 334 of file trilinos_epetra_vector.cc.
| void Vector< Number >::add | ( | const double | a | ) |
Add a to all components. Note that is a scalar not a vector.
Definition at line 351 of file trilinos_epetra_vector.cc.
Simple addition of a multiple of a vector, i.e. *this += a*V. The vectors need to have the same layout.
Definition at line 366 of file trilinos_epetra_vector.cc.
Multiple addition of multiple of a vector, i.e. *this> += a*V+b*W. The vectors need to have the same layout.
Definition at line 382 of file trilinos_epetra_vector.cc.
Scaling and simple addition of a multiple of a vector, i.e. this = s(*this)+a*V.
Definition at line 405 of file trilinos_epetra_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. The vectors need to have the same layout.
Definition at line 420 of file trilinos_epetra_vector.cc.
Assignment *this = a*V.
Definition at line 436 of file trilinos_epetra_vector.cc.
Return whether the vector contains only elements with value zero.
Definition at line 456 of file trilinos_epetra_vector.cc.
| double Vector< Number >::mean_value | ( | ) | const |
Return the mean value of the element of this vector.
Definition at line 471 of file trilinos_epetra_vector.cc.
| double Vector< Number >::l1_norm | ( | ) | const |
Return the l1 norm of the vector (i.e., the sum of the absolute values of all entries among all processors).
Definition at line 486 of file trilinos_epetra_vector.cc.
| double Vector< Number >::l2_norm | ( | ) | const |
Return the l2 norm of the vector (i.e., the square root of the sum of the square of all entries among all processors).
Definition at line 500 of file trilinos_epetra_vector.cc.
| double Vector< Number >::linfty_norm | ( | ) | const |
Return the maximum norm of the vector (i.e., the maximum absolute value among all entries and among all processors).
Definition at line 514 of file trilinos_epetra_vector.cc.
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
The reason this function exists is that this operation involves less memory transfer than calling the two functions separately. This method only needs to load three vectors, this, V, W, whereas calling separate methods means to load the calling vector this twice. Since most vector operations are memory transfer limited, this reduces the time by 25% (or 50% if W equals this).
The vectors need to have the same layout.
For complex-valued vectors, the scalar product in the second step is implemented as \(\left<v,w\right>=\sum_i v_i \bar{w_i}\).
Definition at line 526 of file trilinos_epetra_vector.cc.
This function always returns false and is present only for backward compatibility.
Definition at line 821 of file trilinos_epetra_vector.h.
|
overridevirtual |
Return the global size of the vector, equal to the sum of the number of locally owned indices among all processors.
Implements ReadVector< VectorTraits::value_type >.
Definition at line 538 of file trilinos_epetra_vector.cc.
| Vector::size_type Vector< Number >::locally_owned_size | ( | ) | const |
Return the local size of the vector, i.e., the number of indices owned locally.
Definition at line 550 of file trilinos_epetra_vector.cc.
Return the underlying MPI communicator.
Definition at line 558 of file trilinos_epetra_vector.cc.
Return an index set that describes which elements of this vector are owned by the current 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 569 of file trilinos_epetra_vector.cc.
| void Vector< Number >::compress | ( | const VectorOperation::values | operation | ) |
Compress the underlying representation of the Trilinos 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.
See Compressing distributed objects for more information.
Definition at line 602 of file trilinos_epetra_vector.cc.
| const Epetra_FEVector & Vector< Number >::trilinos_vector | ( | ) | const |
Return a const reference to the underlying Trilinos Epetra_FEVector class.
Definition at line 608 of file trilinos_epetra_vector.cc.
| Epetra_FEVector & Vector< Number >::trilinos_vector | ( | ) |
Return a (modifiable) reference to the underlying Trilinos Epetra_FEVector class.
Definition at line 616 of file trilinos_epetra_vector.cc.
| void Vector< Number >::print | ( | std::ostream & | out, |
| const unsigned int | precision = 3, |
||
| const bool | scientific = true, |
||
| const bool | across = true |
||
| ) | const |
Prints the vector to the output stream out.
Definition at line 624 of file trilinos_epetra_vector.cc.
| std::size_t Vector< Number >::memory_consumption | ( | ) | const |
Return the memory consumption of this class in bytes.
Definition at line 661 of file trilinos_epetra_vector.cc.
|
private |
Create the CommunicationPattern for the communication between the IndexSet source_index_set and the current vector based on the communicator mpi_comm.
Definition at line 671 of file trilinos_epetra_vector.cc.
|
pure virtualinherited |
Extract a subset of the vector specified by indices into the output array elements.
|
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 |
Definition at line 694 of file trilinos_epetra_vector.h.
|
private |
Pointer to the actual Epetra vector object.
Definition at line 680 of file trilinos_epetra_vector.h.
|
private |
IndexSet of the elements of the last imported vector.
Definition at line 685 of file trilinos_epetra_vector.h.
|
private |
CommunicationPattern for the communication between the source_stored_elements IndexSet and the current vector.
Definition at line 691 of file trilinos_epetra_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.