Reference documentation for deal.II version GIT relicensing-31-gf283a0fc39 2024-02-29 06:50:02+00:00
\(\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\}}\)
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
LinearAlgebra::EpetraWrappers::Vector Class Reference

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

Inheritance diagram for LinearAlgebra::EpetraWrappers::Vector:
Inheritance graph
[legend]

Public Types

using value_type = double
 
using size_type = types::global_dof_index
 
using real_type = double
 

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)
 
void reinit (const Vector &V, const bool omit_zeroing_entries=false)
 
virtual void extract_subvector_to (const ArrayView< const types::global_dof_index > &indices, ArrayView< double > &elements) const override
 
Vectoroperator= (const Vector &V)
 
Vectoroperator= (const double s)
 
void import_elements (const ReadWriteVector< double > &V, VectorOperation::values operation, const std::shared_ptr< const Utilities::MPI::CommunicationPatternBase > &communication_pattern={})
 
void import (const ReadWriteVector< double > &V, const VectorOperation::values operation, const std::shared_ptr< const Utilities::MPI::CommunicationPatternBase > &communication_pattern={})
 
Vectoroperator*= (const double factor)
 
Vectoroperator/= (const double factor)
 
Vectoroperator+= (const Vector &V)
 
Vectoroperator-= (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
 
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)
 
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
 
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
 
template<class Archive >
void serialize (Archive &ar, const unsigned int version)
 
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 ::ExceptionBaseExcDifferentParallelPartitioning ()
 
static ::ExceptionBaseExcVectorTypeNotCompatible ()
 
static ::ExceptionBaseExcTrilinosError (int arg1)
 
static ::ExceptionBaseExcInUse (int arg1, std::string arg2, std::string arg3)
 
static ::ExceptionBaseExcNoSubscriber (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_epetra_comm_pattern (const IndexSet &source_index_set, const MPI_Comm mpi_comm)
 
void check_no_subscribers () const noexcept
 

Private Attributes

std::unique_ptr< Epetra_FEVector > vector
 
::IndexSet source_stored_elements
 
std::shared_ptr< const CommunicationPatternepetra_comm_pattern
 
std::atomic< unsigned intcounter
 
std::map< std::string, unsigned intcounter_map
 
std::vector< std::atomic< bool > * > validity_pointers
 
const std::type_info * object_info
 

Static Private Attributes

static std::mutex mutex
 

Detailed Description

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 61 of file trilinos_epetra_vector.h.

Member Typedef Documentation

◆ value_type

Definition at line 64 of file trilinos_epetra_vector.h.

◆ size_type

Definition at line 65 of file trilinos_epetra_vector.h.

◆ real_type

Definition at line 66 of file trilinos_epetra_vector.h.

◆ map_value_type

using Subscriptor::map_value_type = decltype(counter_map)::value_type
privateinherited

The data type used in counter_map.

Definition at line 229 of file subscriptor.h.

◆ map_iterator

using Subscriptor::map_iterator = decltype(counter_map)::iterator
privateinherited

The iterator type used in counter_map.

Definition at line 234 of file subscriptor.h.

Constructor & Destructor Documentation

◆ Vector() [1/3]

Vector< Number >::Vector ( )

Constructor. Create a vector of dimension zero.

Definition at line 48 of file trilinos_epetra_vector.cc.

◆ Vector() [2/3]

Vector< Number >::Vector ( const Vector V)

Copy constructor. Sets the dimension and the partitioning to that of the given vector and copies all elements.

Definition at line 56 of file trilinos_epetra_vector.cc.

◆ Vector() [3/3]

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.

Definition at line 63 of file trilinos_epetra_vector.cc.

Member Function Documentation

◆ reinit() [1/2]

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 zero (false) or left untouched (true).

Definition at line 73 of file trilinos_epetra_vector.cc.

◆ reinit() [2/2]

void Vector< Number >::reinit ( const Vector V,
const bool  omit_zeroing_entries = false 
)

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

Definition at line 92 of file trilinos_epetra_vector.cc.

◆ extract_subvector_to()

void Vector< Number >::extract_subvector_to ( const ArrayView< const types::global_dof_index > &  indices,
ArrayView< double > &  elements 
) const
overridevirtual

Extract a range of elements all at once.

Implements ReadVector< double >.

Definition at line 102 of file trilinos_epetra_vector.cc.

◆ operator=() [1/2]

Vector & Vector< Number >::operator= ( const Vector V)

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

Definition at line 122 of file trilinos_epetra_vector.cc.

◆ operator=() [2/2]

Vector & Vector< Number >::operator= ( const double  s)

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

Definition at line 152 of file trilinos_epetra_vector.cc.

◆ import_elements()

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 166 of file trilinos_epetra_vector.cc.

◆ import()

void LinearAlgebra::EpetraWrappers::Vector::import ( const ReadWriteVector< double > &  V,
const VectorOperation::values  operation,
const std::shared_ptr< const Utilities::MPI::CommunicationPatternBase > &  communication_pattern = {} 
)
inline
Deprecated:
Use import_elements() instead.

Definition at line 149 of file trilinos_epetra_vector.h.

◆ operator*=()

Vector & Vector< Number >::operator*= ( const double  factor)

Multiply the entire vector by a fixed factor.

Definition at line 222 of file trilinos_epetra_vector.cc.

◆ operator/=()

Vector & Vector< Number >::operator/= ( const double  factor)

Divide the entire vector by a fixed factor.

Definition at line 233 of file trilinos_epetra_vector.cc.

◆ operator+=()

Vector & Vector< Number >::operator+= ( const Vector V)

Add the vector V to the present one.

Definition at line 245 of file trilinos_epetra_vector.cc.

◆ operator-=()

Vector & Vector< Number >::operator-= ( const Vector V)

Subtract the vector V from the present one.

Definition at line 288 of file trilinos_epetra_vector.cc.

◆ operator*()

double Vector< Number >::operator* ( const Vector V) const

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

Definition at line 298 of file trilinos_epetra_vector.cc.

◆ add() [1/3]

void Vector< Number >::add ( const double  a)

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

Definition at line 316 of file trilinos_epetra_vector.cc.

◆ add() [2/3]

void Vector< Number >::add ( const double  a,
const Vector V 
)

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

Definition at line 327 of file trilinos_epetra_vector.cc.

◆ add() [3/3]

void Vector< Number >::add ( const double  a,
const Vector V,
const double  b,
const Vector W 
)

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 341 of file trilinos_epetra_vector.cc.

◆ sadd()

void Vector< Number >::sadd ( const double  s,
const double  a,
const Vector V 
)

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

Definition at line 362 of file trilinos_epetra_vector.cc.

◆ scale()

void Vector< Number >::scale ( const Vector 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.

Definition at line 373 of file trilinos_epetra_vector.cc.

◆ equ()

void Vector< Number >::equ ( const double  a,
const Vector V 
)

Assignment *this = a*V.

Definition at line 387 of file trilinos_epetra_vector.cc.

◆ all_zero()

bool Vector< Number >::all_zero ( ) const

Return whether the vector contains only elements with value zero.

Definition at line 404 of file trilinos_epetra_vector.cc.

◆ mean_value()

double Vector< Number >::mean_value ( ) const

Return the mean value of the element of this vector.

Definition at line 433 of file trilinos_epetra_vector.cc.

◆ l1_norm()

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 447 of file trilinos_epetra_vector.cc.

◆ l2_norm()

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 460 of file trilinos_epetra_vector.cc.

◆ linfty_norm()

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 473 of file trilinos_epetra_vector.cc.

◆ add_and_dot()

double Vector< Number >::add_and_dot ( const double  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

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

Definition at line 486 of file trilinos_epetra_vector.cc.

◆ has_ghost_elements()

bool Vector< Number >::has_ghost_elements ( ) const
inline

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

Definition at line 423 of file trilinos_epetra_vector.h.

◆ size()

Vector::size_type 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 ReadVector< double >.

Definition at line 496 of file trilinos_epetra_vector.cc.

◆ locally_owned_size()

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 508 of file trilinos_epetra_vector.cc.

◆ get_mpi_communicator()

MPI_Comm Vector< Number >::get_mpi_communicator ( ) const

Return the underlying MPI communicator.

Definition at line 516 of file trilinos_epetra_vector.cc.

◆ locally_owned_elements()

IndexSet 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

vec.locally_owned_elements() == complete_index_set(vec.size())
IndexSet complete_index_set(const IndexSet::size_type N)
Definition index_set.h:1193

Definition at line 527 of file trilinos_epetra_vector.cc.

◆ compress()

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 560 of file trilinos_epetra_vector.cc.

◆ trilinos_vector() [1/2]

const Epetra_FEVector & Vector< Number >::trilinos_vector ( ) const

Return a const reference to the underlying Trilinos Epetra_FEVector class.

Definition at line 566 of file trilinos_epetra_vector.cc.

◆ trilinos_vector() [2/2]

Epetra_FEVector & Vector< Number >::trilinos_vector ( )

Return a (modifiable) reference to the underlying Trilinos Epetra_FEVector class.

Definition at line 574 of file trilinos_epetra_vector.cc.

◆ print()

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 582 of file trilinos_epetra_vector.cc.

◆ memory_consumption()

std::size_t Vector< Number >::memory_consumption ( ) const

Return the memory consumption of this class in bytes.

Definition at line 620 of file trilinos_epetra_vector.cc.

◆ create_epetra_comm_pattern()

void Vector< Number >::create_epetra_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.

Definition at line 630 of file trilinos_epetra_vector.cc.

◆ subscribe()

void Subscriptor::subscribe ( std::atomic< bool > *const  validity,
const std::string &  identifier = "" 
) const
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 135 of file subscriptor.cc.

◆ unsubscribe()

void Subscriptor::unsubscribe ( std::atomic< bool > *const  validity,
const std::string &  identifier = "" 
) const
inherited

Unsubscribes a user from the object.

Note
The identifier and the validity pointer must be the same as the one supplied to subscribe().

Definition at line 155 of file subscriptor.cc.

◆ n_subscriptions()

unsigned int Subscriptor::n_subscriptions ( ) const
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 300 of file subscriptor.h.

◆ list_subscribers() [1/2]

template<typename StreamType >
void Subscriptor::list_subscribers ( StreamType &  stream) const
inlineinherited

List the subscribers to the input stream.

Definition at line 317 of file subscriptor.h.

◆ list_subscribers() [2/2]

void Subscriptor::list_subscribers ( ) const
inherited

List the subscribers to deallog.

Definition at line 203 of file subscriptor.cc.

◆ serialize()

template<class Archive >
void Subscriptor::serialize ( Archive &  ar,
const unsigned int  version 
)
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 309 of file subscriptor.h.

◆ check_no_subscribers()

void Subscriptor::check_no_subscribers ( ) const
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.

Note
Since this function is just a consistency check it does nothing in release mode.
If this function is called when there is an uncaught exception then, rather than aborting, this function prints an error message to the standard error stream and returns.

Definition at line 52 of file subscriptor.cc.

Member Data Documentation

◆ vector

std::unique_ptr<Epetra_FEVector> LinearAlgebra::EpetraWrappers::Vector::vector
private

Pointer to the actual Epetra vector object.

Definition at line 407 of file trilinos_epetra_vector.h.

◆ source_stored_elements

::IndexSet LinearAlgebra::EpetraWrappers::Vector::source_stored_elements
private

IndexSet of the elements of the last imported vector.

Definition at line 412 of file trilinos_epetra_vector.h.

◆ epetra_comm_pattern

std::shared_ptr<const CommunicationPattern> LinearAlgebra::EpetraWrappers::Vector::epetra_comm_pattern
private

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

Definition at line 418 of file trilinos_epetra_vector.h.

◆ counter

std::atomic<unsigned int> Subscriptor::counter
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 218 of file subscriptor.h.

◆ counter_map

std::map<std::string, unsigned int> Subscriptor::counter_map
mutableprivateinherited

In this map, we count subscriptions for each different identification string supplied to subscribe().

Definition at line 224 of file subscriptor.h.

◆ validity_pointers

std::vector<std::atomic<bool> *> Subscriptor::validity_pointers
mutableprivateinherited

In this vector, we store pointers to the validity bool in the SmartPointer objects that subscribe to this class.

Definition at line 240 of file subscriptor.h.

◆ object_info

const std::type_info* Subscriptor::object_info
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 248 of file subscriptor.h.

◆ mutex

std::mutex Subscriptor::mutex
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 271 of file subscriptor.h.


The documentation for this class was generated from the following files: