Reference documentation for deal.II version 9.2.0
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members

#include <deal.II/lac/trilinos_tpetra_vector.h>

Inheritance diagram for LinearAlgebra::TpetraWrappers::Vector< Number >:
[legend]

Public Types

using value_type = Number
 
using size_type = typename VectorSpaceVector< Number >::size_type
 
- Public Types inherited from LinearAlgebra::VectorSpaceVector< Number >
using value_type = Number
 
using size_type = types::global_dof_index
 
using real_type = typename numbers::NumberTraits< Number >::real_type
 

Public Member Functions

 Vector ()
 
 Vector (const Vector &V)
 
 Vector (const IndexSet &parallel_partitioner, const MPI_Comm &communicator)
 
void reinit (const IndexSet &parallel_partitioner, const MPI_Comm &communicator, const bool omit_zeroing_entries=false)
 
virtual void reinit (const VectorSpaceVector< Number > &V, const bool omit_zeroing_entries=false) override
 
Vectoroperator= (const Vector &V)
 
virtual Vectoroperator= (const Number s) override
 
virtual void import (const ReadWriteVector< Number > &V, VectorOperation::values operation, std::shared_ptr< const CommunicationPatternBase > communication_pattern=std::shared_ptr< const CommunicationPatternBase >()) override
 
virtual Vectoroperator*= (const Number factor) override
 
virtual Vectoroperator/= (const Number factor) override
 
virtual Vectoroperator+= (const VectorSpaceVector< Number > &V) override
 
virtual Vectoroperator-= (const VectorSpaceVector< Number > &V) override
 
virtual Number operator* (const VectorSpaceVector< Number > &V) const override
 
virtual void add (const Number a) override
 
virtual void add (const Number a, const VectorSpaceVector< Number > &V) override
 
virtual void add (const Number a, const VectorSpaceVector< Number > &V, const Number b, const VectorSpaceVector< Number > &W) override
 
virtual void sadd (const Number s, const Number a, const VectorSpaceVector< Number > &V) override
 
virtual void scale (const VectorSpaceVector< Number > &scaling_factors) override
 
virtual void equ (const Number a, const VectorSpaceVector< Number > &V) override
 
virtual bool all_zero () const override
 
virtual Number mean_value () const override
 
virtual LinearAlgebra::VectorSpaceVector< Number >::real_type l1_norm () const override
 
virtual LinearAlgebra::VectorSpaceVector< Number >::real_type l2_norm () const override
 
virtual LinearAlgebra::VectorSpaceVector< Number >::real_type linfty_norm () const override
 
virtual Number add_and_dot (const Number a, const VectorSpaceVector< Number > &V, const VectorSpaceVector< Number > &W) override
 
bool has_ghost_elements () const
 
virtual size_type size () const override
 
MPI_Comm get_mpi_communicator () const
 
virtual ::IndexSet locally_owned_elements () const override
 
const Tpetra::Vector< Number, int, types::global_dof_index > & trilinos_vector () const
 
Tpetra::Vector< Number, int, types::global_dof_index > & trilinos_vector ()
 
virtual void print (std::ostream &out, const unsigned int precision=3, const bool scientific=true, const bool across=true) const override
 
virtual std::size_t memory_consumption () const override
 
- Public Member Functions inherited from LinearAlgebra::VectorSpaceVector< Number >
virtual void compress (VectorOperation::values)
 
virtual ~VectorSpaceVector ()=default
 
- Public Member Functions inherited from Subscriptor
 Subscriptor ()
 
 Subscriptor (const Subscriptor &)
 
 Subscriptor (Subscriptor &&) noexcept
 
virtual ~Subscriptor ()
 
Subscriptoroperator= (const Subscriptor &)
 
Subscriptoroperator= (Subscriptor &&) noexcept
 
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
 
template<class Archive >
void serialize (Archive &ar, const unsigned int version)
 

Static Public Member Functions

static ::ExceptionBaseExcDifferentParallelPartitioning ()
 
static ::ExceptionBaseExcVectorTypeNotCompatible ()
 
static ::ExceptionBaseExcTrilinosError (int arg1)
 
- Static Public Member Functions inherited from Subscriptor
static ::ExceptionBaseExcInUse (int arg1, std::string arg2, std::string arg3)
 
static ::ExceptionBaseExcNoSubscriber (std::string arg1, std::string arg2)
 

Private Member Functions

void create_tpetra_comm_pattern (const IndexSet &source_index_set, const MPI_Comm &mpi_comm)
 

Private Attributes

std::unique_ptr< Tpetra::Vector< Number, int, types::global_dof_index > > vector
 
::IndexSet source_stored_elements
 
std::shared_ptr< const TpetraWrappers::CommunicationPatterntpetra_comm_pattern
 

Detailed Description

template<typename Number>
class LinearAlgebra::TpetraWrappers::Vector< Number >

This class implements a wrapper to the Trilinos distributed vector class Tpetra::Vector. This class is derived from the LinearAlgebra::VectorSpaceVector class and 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 CUDA support, this class stores the values in unified virtual memory space and performs its action on the GPU. In particular, there is no need for manually synchronizing memory between host and device.

Author
Daniel Arndt, 2019

Definition at line 84 of file trilinos_tpetra_vector.h.

Member Typedef Documentation

◆ value_type

template<typename Number >
using LinearAlgebra::TpetraWrappers::Vector< Number >::value_type = Number

Definition at line 87 of file trilinos_tpetra_vector.h.

◆ size_type

template<typename Number >
using LinearAlgebra::TpetraWrappers::Vector< Number >::size_type = typename VectorSpaceVector<Number>::size_type

Definition at line 89 of file trilinos_tpetra_vector.h.

Constructor & Destructor Documentation

◆ Vector() [1/3]

template<typename Number >
LinearAlgebra::TpetraWrappers::Vector< Number >::Vector ( )

Constructor. Create a vector of dimension zero.

◆ Vector() [2/3]

template<typename Number >
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.

◆ Vector() [3/3]

template<typename Number >
LinearAlgebra::TpetraWrappers::Vector< Number >::Vector ( const IndexSet parallel_partitioner,
const MPI_Comm communicator 
)
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.

Member Function Documentation

◆ reinit() [1/2]

template<typename Number >
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).

◆ reinit() [2/2]

template<typename Number >
virtual void LinearAlgebra::TpetraWrappers::Vector< Number >::reinit ( const VectorSpaceVector< Number > &  V,
const bool  omit_zeroing_entries = false 
)
overridevirtual

Change the dimension to that of the vector V. The elements of V are not copied.

Implements LinearAlgebra::VectorSpaceVector< Number >.

◆ operator=() [1/2]

template<typename Number >
Vector& LinearAlgebra::TpetraWrappers::Vector< Number >::operator= ( const Vector< Number > &  V)

Copy function. This function takes a Vector and copies all the elements. The Vector will have the same parallel distribution as V.

◆ operator=() [2/2]

template<typename Number >
virtual Vector& LinearAlgebra::TpetraWrappers::Vector< Number >::operator= ( const Number  s)
overridevirtual

Sets all elements of the vector to the scalar s. This operation is only allowed if s is equal to zero.

Implements LinearAlgebra::VectorSpaceVector< Number >.

◆ import()

template<typename Number >
virtual void LinearAlgebra::TpetraWrappers::Vector< Number >::import ( const ReadWriteVector< Number > &  V,
VectorOperation::values  operation,
std::shared_ptr< const CommunicationPatternBase communication_pattern = std::shared_ptr< const CommunicationPatternBase >() 
)
overridevirtual

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.

Implements LinearAlgebra::VectorSpaceVector< Number >.

◆ operator*=()

template<typename Number >
virtual Vector& LinearAlgebra::TpetraWrappers::Vector< Number >::operator*= ( const Number  factor)
overridevirtual

Multiply the entire vector by a fixed factor.

Implements LinearAlgebra::VectorSpaceVector< Number >.

◆ operator/=()

template<typename Number >
virtual Vector& LinearAlgebra::TpetraWrappers::Vector< Number >::operator/= ( const Number  factor)
overridevirtual

Divide the entire vector by a fixed factor.

Implements LinearAlgebra::VectorSpaceVector< Number >.

◆ operator+=()

template<typename Number >
virtual Vector& LinearAlgebra::TpetraWrappers::Vector< Number >::operator+= ( const VectorSpaceVector< Number > &  V)
overridevirtual

Add the vector V to the present one.

Implements LinearAlgebra::VectorSpaceVector< Number >.

◆ operator-=()

template<typename Number >
virtual Vector& LinearAlgebra::TpetraWrappers::Vector< Number >::operator-= ( const VectorSpaceVector< Number > &  V)
overridevirtual

Subtract the vector V from the present one.

Implements LinearAlgebra::VectorSpaceVector< Number >.

◆ operator*()

template<typename Number >
virtual Number LinearAlgebra::TpetraWrappers::Vector< Number >::operator* ( const VectorSpaceVector< Number > &  V) const
overridevirtual

Return the scalar product of two vectors. The vectors need to have the same layout.

Implements LinearAlgebra::VectorSpaceVector< Number >.

◆ add() [1/3]

template<typename Number >
virtual void LinearAlgebra::TpetraWrappers::Vector< Number >::add ( const Number  a)
overridevirtual

Add a to all components. Note that is a scalar not a vector.

Implements LinearAlgebra::VectorSpaceVector< Number >.

◆ add() [2/3]

template<typename Number >
virtual void LinearAlgebra::TpetraWrappers::Vector< Number >::add ( const Number  a,
const VectorSpaceVector< Number > &  V 
)
overridevirtual

Simple addition of a multiple of a vector, i.e. *this += a*V. The vectors need to have the same layout.

Implements LinearAlgebra::VectorSpaceVector< Number >.

◆ add() [3/3]

template<typename Number >
virtual void LinearAlgebra::TpetraWrappers::Vector< Number >::add ( const Number  a,
const VectorSpaceVector< Number > &  V,
const Number  b,
const VectorSpaceVector< Number > &  W 
)
overridevirtual

Multiple addition of multiple of a vector, i.e. *this> += a*V+b*W. The vectors need to have the same layout.

Implements LinearAlgebra::VectorSpaceVector< Number >.

◆ sadd()

template<typename Number >
virtual void LinearAlgebra::TpetraWrappers::Vector< Number >::sadd ( const Number  s,
const Number  a,
const VectorSpaceVector< Number > &  V 
)
overridevirtual

Scaling and simple addition of a multiple of a vector, i.e. *this = s*(*this)+a*V.

Implements LinearAlgebra::VectorSpaceVector< Number >.

◆ scale()

template<typename Number >
virtual void LinearAlgebra::TpetraWrappers::Vector< Number >::scale ( const VectorSpaceVector< Number > &  scaling_factors)
overridevirtual

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.

Implements LinearAlgebra::VectorSpaceVector< Number >.

◆ equ()

template<typename Number >
virtual void LinearAlgebra::TpetraWrappers::Vector< Number >::equ ( const Number  a,
const VectorSpaceVector< Number > &  V 
)
overridevirtual

Assignment *this = a*V.

Implements LinearAlgebra::VectorSpaceVector< Number >.

◆ all_zero()

template<typename Number >
virtual bool LinearAlgebra::TpetraWrappers::Vector< Number >::all_zero ( ) const
overridevirtual

Return whether the vector contains only elements with value zero.

Implements LinearAlgebra::VectorSpaceVector< Number >.

◆ mean_value()

template<typename Number >
virtual Number LinearAlgebra::TpetraWrappers::Vector< Number >::mean_value ( ) const
overridevirtual

Return the mean value of the element of this vector.

Implements LinearAlgebra::VectorSpaceVector< Number >.

◆ l1_norm()

template<typename Number >
virtual LinearAlgebra::VectorSpaceVector<Number>::real_type LinearAlgebra::TpetraWrappers::Vector< Number >::l1_norm ( ) const
overridevirtual

Return the l1 norm of the vector (i.e., the sum of the absolute values of all entries among all processors).

Implements LinearAlgebra::VectorSpaceVector< Number >.

◆ l2_norm()

template<typename Number >
virtual LinearAlgebra::VectorSpaceVector<Number>::real_type LinearAlgebra::TpetraWrappers::Vector< Number >::l2_norm ( ) const
overridevirtual

Return the l2 norm of the vector (i.e., the square root of the sum of the square of all entries among all processors).

Implements LinearAlgebra::VectorSpaceVector< Number >.

◆ linfty_norm()

template<typename Number >
virtual LinearAlgebra::VectorSpaceVector<Number>::real_type LinearAlgebra::TpetraWrappers::Vector< Number >::linfty_norm ( ) const
overridevirtual

Return the maximum norm of the vector (i.e., the maximum absolute value among all entries and among all processors).

Implements LinearAlgebra::VectorSpaceVector< Number >.

◆ add_and_dot()

template<typename Number >
virtual Number LinearAlgebra::TpetraWrappers::Vector< Number >::add_and_dot ( const Number  a,
const VectorSpaceVector< Number > &  V,
const VectorSpaceVector< Number > &  W 
)
overridevirtual

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

this->add(a, V);
return_value = *this * W;

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}\).

Implements LinearAlgebra::VectorSpaceVector< Number >.

◆ has_ghost_elements()

template<typename Number >
bool Vector< Number >::has_ghost_elements
inline

This function always returns false and is present only for backward compatibility.

Definition at line 415 of file trilinos_tpetra_vector.h.

◆ size()

template<typename Number >
virtual size_type LinearAlgebra::TpetraWrappers::Vector< Number >::size ( ) const
overridevirtual

Return the global size of the vector, equal to the sum of the number of locally owned indices among all processors.

Implements LinearAlgebra::VectorSpaceVector< Number >.

◆ get_mpi_communicator()

template<typename Number >
MPI_Comm LinearAlgebra::TpetraWrappers::Vector< Number >::get_mpi_communicator ( ) const

Return the MPI communicator object in use with this object.

◆ locally_owned_elements()

template<typename Number >
virtual ::IndexSet LinearAlgebra::TpetraWrappers::Vector< Number >::locally_owned_elements ( ) const
overridevirtual

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

vec.locally_owned_elements() == complete_index_set(vec.size())

Implements LinearAlgebra::VectorSpaceVector< Number >.

◆ trilinos_vector() [1/2]

template<typename Number >
const Tpetra::Vector<Number, int, types::global_dof_index>& LinearAlgebra::TpetraWrappers::Vector< Number >::trilinos_vector ( ) const

Return a const reference to the underlying Trilinos Tpetra::Vector class.

◆ trilinos_vector() [2/2]

template<typename Number >
Tpetra::Vector<Number, int, types::global_dof_index>& LinearAlgebra::TpetraWrappers::Vector< Number >::trilinos_vector ( )

Return a (modifiable) reference to the underlying Trilinos Tpetra::Vector class.

◆ print()

template<typename Number >
virtual void LinearAlgebra::TpetraWrappers::Vector< Number >::print ( std::ostream &  out,
const unsigned int  precision = 3,
const bool  scientific = true,
const bool  across = true 
) const
overridevirtual

Prints the vector to the output stream out.

Implements LinearAlgebra::VectorSpaceVector< Number >.

◆ memory_consumption()

template<typename Number >
virtual std::size_t LinearAlgebra::TpetraWrappers::Vector< Number >::memory_consumption ( ) const
overridevirtual

Return the memory consumption of this class in bytes.

Implements LinearAlgebra::VectorSpaceVector< Number >.

◆ create_tpetra_comm_pattern()

template<typename Number >
void LinearAlgebra::TpetraWrappers::Vector< Number >::create_tpetra_comm_pattern ( const IndexSet source_index_set,
const MPI_Comm mpi_comm 
)
private

Create the CommunicationPattern for the communication between the IndexSet source_index_set and the current vector based on the communicator mpi_comm.

Member Data Documentation

◆ vector

template<typename Number >
std::unique_ptr<Tpetra::Vector<Number, int, types::global_dof_index> > LinearAlgebra::TpetraWrappers::Vector< Number >::vector
private

Pointer to the actual Tpetra vector object.

Definition at line 397 of file trilinos_tpetra_vector.h.

◆ source_stored_elements

template<typename Number >
::IndexSet LinearAlgebra::TpetraWrappers::Vector< Number >::source_stored_elements
private

IndexSet of the elements of the last imported vector.

Definition at line 402 of file trilinos_tpetra_vector.h.

◆ tpetra_comm_pattern

template<typename Number >
std::shared_ptr<const TpetraWrappers::CommunicationPattern> LinearAlgebra::TpetraWrappers::Vector< Number >::tpetra_comm_pattern
private

CommunicationPattern for the communication between the source_stored_elements IndexSet and the current vector.

Definition at line 409 of file trilinos_tpetra_vector.h.


The documentation for this class was generated from the following file:
LAPACKSupport::V
static const char V
Definition: lapack_support.h:175
complete_index_set
IndexSet complete_index_set(const IndexSet::size_type N)
Definition: index_set.h:1014
LinearAlgebra::TpetraWrappers::Vector::add
virtual void add(const Number a) override