![]() |
Reference documentation for deal.II version GIT 29f9da0a34 2023-12-07 10:00:01+00:00
|
#include <deal.II/lac/trilinos_tpetra_vector.h>
Public Types | |
using | value_type = Number |
using | real_type = typename numbers::NumberTraits< Number >::real_type |
using | size_type = types::global_dof_index |
using | reference = internal::VectorReference< Number > |
using | MapType = Tpetra::Map< int, ::types::signed_global_dof_index > |
using | VectorType = Tpetra::Vector< Number, int, ::types::signed_global_dof_index > |
Public Member Functions | |
template<class Archive > | |
void | serialize (Archive &ar, const unsigned int version) |
1: Basic Object-handling | |
Vector () | |
Vector (const Vector &V) | |
Vector (const Teuchos::RCP< VectorType > 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 IndexSet &locally_owned_entries, const IndexSet &locally_relevant_or_ghost_entries, const MPI_Comm communicator=MPI_COMM_WORLD) |
void | reinit (const Vector< Number > &V, const bool omit_zeroing_entries=false) |
virtual void | extract_subvector_to (const ArrayView< const types::global_dof_index > &indices, ArrayView< Number > &elements) const override |
Vector & | operator= (const Vector &V) |
Vector & | operator= (const Number s) |
void | import_elements (const ReadWriteVector< Number > &V, VectorOperation::values operation, const Teuchos::RCP< const Utilities::MPI::CommunicationPatternBase > &communication_pattern) |
void | import_elements (const ReadWriteVector< Number > &V, VectorOperation::values operation, const std::shared_ptr< const Utilities::MPI::CommunicationPatternBase > &communication_pattern) |
void | import_elements (const ReadWriteVector< Number > &V, VectorOperation::values operation) |
void | import (const ReadWriteVector< Number > &V, VectorOperation::values operation, std::shared_ptr< const Utilities::MPI::CommunicationPatternBase > communication_pattern={}) |
2: Data-Access | |
reference | operator() (const size_type index) |
3: Modification of vectors | |
Vector & | operator*= (const Number factor) |
Vector & | operator/= (const Number factor) |
Vector & | operator+= (const Vector< Number > &V) |
Vector & | operator-= (const Vector< Number > &V) |
Number | operator* (const Vector< Number > &V) const |
void | add (const Number a) |
void | add (const Number a, const Vector< Number > &V) |
void | add (const Number a, const Vector< Number > &V, const Number b, const Vector< Number > &W) |
void | add (const std::vector< size_type > &indices, const std::vector< TrilinosScalar > &values) |
void | add (const size_type n_elements, const size_type *indices, const Number *values) |
void | sadd (const Number s, const Number a, const Vector< Number > &V) |
void | set (const size_type n_elements, const size_type *indices, const Number *values) |
void | scale (const Vector< Number > &scaling_factors) |
void | equ (const Number a, const Vector< Number > &V) |
bool | all_zero () const |
4: Scalar products, norms and related operations | |
Number | mean_value () const |
real_type | l1_norm () const |
real_type | l2_norm () const |
real_type | linfty_norm () const |
Number | add_and_dot (const Number a, const Vector< Number > &V, const Vector< Number > &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 Tpetra::Vector< Number, int, types::signed_global_dof_index > & | trilinos_vector () const |
Tpetra::Vector< Number, int, types::signed_global_dof_index > & | trilinos_vector () |
Teuchos::RCP< const Tpetra::Vector< Number, int, types::signed_global_dof_index > > | trilinos_rcp () const |
Teuchos::RCP< Tpetra::Vector< Number, int, types::signed_global_dof_index > > | trilinos_rcp () |
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 |
MPI_Comm | mpi_comm () const |
Subscriptor functionality | |
Classes derived from Subscriptor provide a facility to subscribe to this object. This is mostly used by the SmartPointer 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 |
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 Types | |
using | map_value_type = decltype(counter_map)::value_type |
using | map_iterator = decltype(counter_map)::iterator |
Private Member Functions | |
void | create_tpetra_comm_pattern (const IndexSet &source_index_set, const MPI_Comm mpi_comm) |
void | check_no_subscribers () const noexcept |
Private Attributes | |
Teuchos::RCP< VectorType > | vector |
::IndexSet | source_stored_elements |
Teuchos::RCP< const TpetraWrappers::CommunicationPattern > | tpetra_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< Number > |
This class implements a wrapper to the Trilinos distributed vector class Tpetra::Vector. This class requires Trilinos to be compiled with MPI support.
Tpetra uses Kokkos for thread-parallelism and chooses the execution and memory space automatically depending on Kokkos configuration. The priority is ranked from highest to lowest:
In case Kokkos was configured with GPU support, this class performs its actions on the GPU. In particular, there is no need for manually synchronizing memory between host and device.
Definition at line 250 of file trilinos_tpetra_vector.h.
using LinearAlgebra::TpetraWrappers::Vector< Number >::value_type = Number |
Declare some of the standard types used in all containers.
Definition at line 256 of file trilinos_tpetra_vector.h.
using LinearAlgebra::TpetraWrappers::Vector< Number >::real_type = typename numbers::NumberTraits<Number>::real_type |
Definition at line 257 of file trilinos_tpetra_vector.h.
using LinearAlgebra::TpetraWrappers::Vector< Number >::size_type = types::global_dof_index |
Definition at line 258 of file trilinos_tpetra_vector.h.
using LinearAlgebra::TpetraWrappers::Vector< Number >::reference = internal::VectorReference<Number> |
Definition at line 259 of file trilinos_tpetra_vector.h.
using LinearAlgebra::TpetraWrappers::Vector< Number >::MapType = Tpetra::Map<int, ::types::signed_global_dof_index> |
Definition at line 260 of file trilinos_tpetra_vector.h.
using LinearAlgebra::TpetraWrappers::Vector< Number >::VectorType = Tpetra::Vector<Number, int, ::types::signed_global_dof_index> |
Definition at line 261 of file trilinos_tpetra_vector.h.
|
privateinherited |
The data type used in counter_map.
Definition at line 230 of file subscriptor.h.
|
privateinherited |
The iterator type used in counter_map.
Definition at line 235 of file subscriptor.h.
LinearAlgebra::TpetraWrappers::Vector< Number >::Vector | ( | ) |
Default constructor that generates an empty (zero size) vector. The function reinit()
will have to give the vector the correct size and distribution among processes in case of an MPI run.
LinearAlgebra::TpetraWrappers::Vector< Number >::Vector | ( | const Vector< Number > & | V | ) |
Copy constructor. Sets the dimension and the partitioning to that of the given vector and copies all elements.
LinearAlgebra::TpetraWrappers::Vector< Number >::Vector | ( | const Teuchos::RCP< VectorType > | V | ) |
Copy constructor from Teuchos::RCP<Tpetra::Vector>.
|
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.
void LinearAlgebra::TpetraWrappers::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 zero (false) or left untouched (true).
void LinearAlgebra::TpetraWrappers::Vector< Number >::reinit | ( | const IndexSet & | locally_owned_entries, |
const IndexSet & | locally_relevant_or_ghost_entries, | ||
const MPI_Comm | communicator = MPI_COMM_WORLD |
||
) |
Reinit functionality. This function destroys the old vector content and generates a new one based on the input partitioning. In addition to just specifying one index set as in all the other methods above, this method allows to supply an additional set of ghost entries.
Depending on whether the locally_relevant_or_ghost_entries
argument uniquely subdivides elements among processors or not, the resulting vector may or may not have ghost elements. See the general documentation of this class for more information.
void LinearAlgebra::TpetraWrappers::Vector< Number >::reinit | ( | const Vector< Number > & | V, |
const bool | omit_zeroing_entries = false |
||
) |
Change the dimension to that of the vector V
. The elements of V
are not copied.
|
overridevirtual |
Extract a range of elements all at once.
Implements ReadVector< Number >.
Vector& LinearAlgebra::TpetraWrappers::Vector< Number >::operator= | ( | const Vector< Number > & | V | ) |
Vector& LinearAlgebra::TpetraWrappers::Vector< Number >::operator= | ( | const Number | s | ) |
Sets all elements of the vector to the scalar s
. This operation is only allowed if s
is equal to zero.
void LinearAlgebra::TpetraWrappers::Vector< Number >::import_elements | ( | const ReadWriteVector< Number > & | V, |
VectorOperation::values | operation, | ||
const Teuchos::RCP< 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.
void LinearAlgebra::TpetraWrappers::Vector< Number >::import_elements | ( | const ReadWriteVector< Number > & | V, |
VectorOperation::values | operation, | ||
const std::shared_ptr< const Utilities::MPI::CommunicationPatternBase > & | communication_pattern | ||
) |
void LinearAlgebra::TpetraWrappers::Vector< Number >::import_elements | ( | const ReadWriteVector< Number > & | V, |
VectorOperation::values | operation | ||
) |
|
inline |
Definition at line 397 of file trilinos_tpetra_vector.h.
|
inline |
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 885 of file trilinos_tpetra_vector.h.
Vector& LinearAlgebra::TpetraWrappers::Vector< Number >::operator*= | ( | const Number | factor | ) |
Multiply the entire vector by a fixed factor.
Vector& LinearAlgebra::TpetraWrappers::Vector< Number >::operator/= | ( | const Number | factor | ) |
Divide the entire vector by a fixed factor.
Vector& LinearAlgebra::TpetraWrappers::Vector< Number >::operator+= | ( | const Vector< Number > & | V | ) |
Add the vector V
to the present one.
Vector& LinearAlgebra::TpetraWrappers::Vector< Number >::operator-= | ( | const Vector< Number > & | V | ) |
Subtract the vector V
from the present one.
Number LinearAlgebra::TpetraWrappers::Vector< Number >::operator* | ( | const Vector< Number > & | V | ) | const |
Return the scalar product of two vectors. The vectors need to have the same layout.
void LinearAlgebra::TpetraWrappers::Vector< Number >::add | ( | const Number | a | ) |
Add a
to all components. Note that is
a scalar not a vector.
void LinearAlgebra::TpetraWrappers::Vector< Number >::add | ( | const Number | a, |
const Vector< Number > & | V | ||
) |
Simple addition of a multiple of a vector, i.e. *this += a*V
. The vectors need to have the same layout.
void LinearAlgebra::TpetraWrappers::Vector< Number >::add | ( | const Number | a, |
const Vector< Number > & | V, | ||
const Number | b, | ||
const Vector< Number > & | W | ||
) |
Multiple addition of multiple of a vector, i.e. *this> += a*V+b*W
. The vectors need to have the same layout.
|
inline |
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 797 of file trilinos_tpetra_vector.h.
|
inline |
Take an address where n_elements
are stored contiguously and add them into the vector. Handles all cases which are not covered by the other two add()
functions above.
Definition at line 811 of file trilinos_tpetra_vector.h.
void LinearAlgebra::TpetraWrappers::Vector< Number >::sadd | ( | const Number | s, |
const Number | a, | ||
const Vector< Number > & | V | ||
) |
Scaling and simple addition of a multiple of a vector, i.e. this = s(*this)+a*V
.
|
inline |
A collective set operation: instead of setting individual elements of a vector, this function allows to set a whole set of elements at once. It is assumed that the elements to be set are located in contiguous memory.
Definition at line 848 of file trilinos_tpetra_vector.h.
void LinearAlgebra::TpetraWrappers::Vector< Number >::scale | ( | const Vector< Number > & | scaling_factors | ) |
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.
void LinearAlgebra::TpetraWrappers::Vector< Number >::equ | ( | const Number | a, |
const Vector< Number > & | V | ||
) |
Assignment *this = a*V
.
bool LinearAlgebra::TpetraWrappers::Vector< Number >::all_zero | ( | ) | const |
Return whether the vector contains only elements with value zero.
Number LinearAlgebra::TpetraWrappers::Vector< Number >::mean_value | ( | ) | const |
Return the mean value of the element of this vector.
real_type LinearAlgebra::TpetraWrappers::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).
real_type LinearAlgebra::TpetraWrappers::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).
real_type LinearAlgebra::TpetraWrappers::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).
Number LinearAlgebra::TpetraWrappers::Vector< Number >::add_and_dot | ( | const Number | a, |
const Vector< Number > & | V, | ||
const Vector< Number > & | 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
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}\).
This function always returns false and is present only for backward compatibility.
Definition at line 788 of file trilinos_tpetra_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< Number >.
size_type LinearAlgebra::TpetraWrappers::Vector< Number >::locally_owned_size | ( | ) | const |
Return the local size of the vector, i.e., the number of indices owned locally.
MPI_Comm LinearAlgebra::TpetraWrappers::Vector< Number >::get_mpi_communicator | ( | ) | const |
Return the underlying MPI communicator.
::IndexSet LinearAlgebra::TpetraWrappers::Vector< Number >::locally_owned_elements | ( | ) | const |
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
void LinearAlgebra::TpetraWrappers::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.
const Tpetra::Vector<Number, int, types::signed_global_dof_index>& LinearAlgebra::TpetraWrappers::Vector< Number >::trilinos_vector | ( | ) | const |
Return a const reference to the underlying Trilinos Tpetra::Vector class.
Tpetra::Vector<Number, int, types::signed_global_dof_index>& LinearAlgebra::TpetraWrappers::Vector< Number >::trilinos_vector | ( | ) |
Return a (modifiable) reference to the underlying Trilinos Tpetra::Vector class.
Teuchos::RCP< const Tpetra::Vector<Number, int, types::signed_global_dof_index> > LinearAlgebra::TpetraWrappers::Vector< Number >::trilinos_rcp | ( | ) | const |
Return a const Teuchos::RCP to the underlying Trilinos Tpetra::Vector class.
Teuchos::RCP<Tpetra::Vector<Number, int, types::signed_global_dof_index> > LinearAlgebra::TpetraWrappers::Vector< Number >::trilinos_rcp | ( | ) |
Return a (modifiable) Teuchos::RCP to the underlying Trilinos Tpetra::Vector class.
void LinearAlgebra::TpetraWrappers::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
.
std::size_t LinearAlgebra::TpetraWrappers::Vector< Number >::memory_consumption | ( | ) | const |
Return the memory consumption of this class in bytes.
MPI_Comm LinearAlgebra::TpetraWrappers::Vector< Number >::mpi_comm | ( | ) | const |
Return the mpi communicator
|
private |
Create the CommunicationPattern for the communication between the IndexSet source_index_set
and the current vector based on the communicator mpi_comm
.
|
inherited |
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 subscriptor.cc.
|
inherited |
Unsubscribes a user from the object.
identifier
and the validity
pointer must be the same as the one supplied to subscribe(). Definition at line 156 of file subscriptor.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 301 of file subscriptor.h.
|
inlineinherited |
List the subscribers to the input stream
.
Definition at line 318 of file subscriptor.h.
|
inherited |
List the subscribers to deallog
.
Definition at line 204 of file subscriptor.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 310 of file subscriptor.h.
|
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 53 of file subscriptor.cc.
|
friend |
Definition at line 777 of file trilinos_tpetra_vector.h.
|
private |
Teuchos::RCP to the actual Tpetra vector object.
Definition at line 765 of file trilinos_tpetra_vector.h.
|
private |
IndexSet of the elements of the last imported vector.
Definition at line 770 of file trilinos_tpetra_vector.h.
|
private |
CommunicationPattern for the communication between the source_stored_elements IndexSet and the current vector.
Definition at line 777 of file trilinos_tpetra_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 219 of file subscriptor.h.
|
mutableprivateinherited |
In this map, we count subscriptions for each different identification string supplied to subscribe().
Definition at line 225 of file subscriptor.h.
|
mutableprivateinherited |
In this vector, we store pointers to the validity bool in the SmartPointer objects that subscribe to this class.
Definition at line 241 of file subscriptor.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 249 of file subscriptor.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 272 of file subscriptor.h.