Discontinuous Galerkin Library
#include "dg/algorithm.h"
Loading...
Searching...
No Matches
dg::MPI_Vector< container > Struct Template Reference

A simple wrapper around a container object and an MPI_Comm. More...

Public Types

using container_type = container
 typedef to acces underlying container
 

Public Member Functions

 MPI_Vector ()
 no data is allocated, communicator is MPI_COMM_NULL
 
 MPI_Vector (container data, MPI_Comm comm)
 construct a vector
 
template<class OtherContainer >
 MPI_Vector (const MPI_Vector< OtherContainer > &src)
 Conversion operator.
 
const container & data () const
 Get underlying data.
 
container & data ()
 Set underlying data.
 
MPI_Comm communicator () const
 Get the communicator to which this vector belongs.
 
void set_communicator (MPI_Comm comm)
 Set the communicator.
 
unsigned size () const
 Return the size of the data object.
 
void swap (MPI_Vector &src)
 Swap data and communicator.
 

Friends

void swap (MPI_Vector< container > &first, MPI_Vector< container > &second)
 

Detailed Description

template<class container>
struct dg::MPI_Vector< container >

A simple wrapper around a container object and an MPI_Comm.

This enables the tag dispatch system for e.g. blas1 and blas2 functions to choose the corresponding MPI implementation of a function over its shared memory analogon.

In the dg library MPI_Vectors are generated notably via the dg::evaluate function when called with a dg::RealMPIGrid

Note
The design choice to keep a communicator with the local data was made to allow to write global reductions like dg::blas1::dot in the same way as in shared memory code without an additional comm parameter.
Template Parameters
containerlocal container type. Must have a size() and a swap() member function and a specialization of the TensorTraits class.
See also
dg::x::HVec dg::MHVec dg::MDVec dg::x::DVec and others

Member Typedef Documentation

◆ container_type

template<class container >
using dg::MPI_Vector< container >::container_type = container

typedef to acces underlying container

Constructor & Destructor Documentation

◆ MPI_Vector() [1/3]

template<class container >
dg::MPI_Vector< container >::MPI_Vector ( )
inline

no data is allocated, communicator is MPI_COMM_NULL

◆ MPI_Vector() [2/3]

template<class container >
dg::MPI_Vector< container >::MPI_Vector ( container data,
MPI_Comm comm )
inline

construct a vector

Parameters
datainternal data copy
commMPI communicator (may not be MPI_COMM_NULL)

◆ MPI_Vector() [3/3]

template<class container >
template<class OtherContainer >
dg::MPI_Vector< container >::MPI_Vector ( const MPI_Vector< OtherContainer > & src)
inline

Conversion operator.

uses conversion between compatible containers

Template Parameters
OtherContaineranother container class (container must be copy constructible from OtherContainer)
Parameters
srcthe source

Member Function Documentation

◆ communicator()

template<class container >
MPI_Comm dg::MPI_Vector< container >::communicator ( ) const
inline

Get the communicator to which this vector belongs.

Returns
read access to MPI communicator

◆ data() [1/2]

template<class container >
container & dg::MPI_Vector< container >::data ( )
inline

Set underlying data.

Returns
write access to data

◆ data() [2/2]

template<class container >
const container & dg::MPI_Vector< container >::data ( ) const
inline

Get underlying data.

Returns
read access to data

◆ set_communicator()

template<class container >
void dg::MPI_Vector< container >::set_communicator ( MPI_Comm comm)
inline

Set the communicator.

Parameters
commnew communicator to set

◆ size()

template<class container >
unsigned dg::MPI_Vector< container >::size ( ) const
inline

Return the size of the data object.

Returns
data.size()

◆ swap()

template<class container >
void dg::MPI_Vector< container >::swap ( MPI_Vector< container > & src)
inline

Swap data and communicator.

Parameters
srccommunicator and data is swapped

Friends And Related Symbol Documentation

◆ swap

template<class container >
void swap ( MPI_Vector< container > & first,
MPI_Vector< container > & second )
friend

This follows the discussion in https://stackoverflow.com/questions/5695548/public-friend-swap-member-function

Note
the std library does call this function via unqualified calls in many algorithms, for example in std::iter_swap, it is just std::swap that will not call it directly. Most of the time this is not an issue because we have move assignments now, but if you do want to enable free swap functions like these use:
using std::swap;
swap(a,b);
friend void swap(MPI_Vector< container > &first, MPI_Vector< container > &second)
Definition mpi_vector.h:104
Parameters
firstfirst instance
secondsecond instance

The documentation for this struct was generated from the following file: