Vulpes  0.1.0
Versatile and parallel compUtational Library for high-order discontinuous Polytopal Element Simulations
Loading...
Searching...
No Matches
vulpes::mpi Namespace Reference

Classes

class  MpiHandle

Functions

template<typename T>
MPI_Datatype getMpiType ()
 Map a C++ arithmetic type to its corresponding MPI_Datatype.
static bool isInitialized ()
 Return true if MPI has been initialized.
static bool isPetscInitialized ()
 Return true if PETSc has been initialized.
static bool isFinalized ()
 Return true if MPI has been finalized.
static bool isPetscFinalized ()
 Return true if PETSc has been finalized.
static int rank ()
 Return the MPI rank in MPI_COMM_WORLD.
static int size ()
 Return the size of MPI_COMM_WORLD.
static bool root ()
 Return true if the rank in MPI_COMM_WORLD is zero.
template<typename T>
void send (const T *data, int count, int destination, MPI_Comm communicator=MPI_COMM_WORLD)
 Send count contiguous values of type T to a destination rank.
template<typename T>
void send (const T &data, int destination, MPI_Comm communicator=MPI_COMM_WORLD)
 Send a single value of type T to a destination rank.
template<typename T>
void send (const std::vector< T > &data, int destination, MPI_Comm communicator=MPI_COMM_WORLD)
 Send a std::vector<T>, prefixed with its size.
void send (const std::string &data, int destination, MPI_Comm communicator=MPI_COMM_WORLD)
 Send a std::string, prefixed with its size.
template<typename T, std::size_t N>
void send (const std::vector< std::array< T, N > > &data, int destination, MPI_Comm communicator=MPI_COMM_WORLD)
 Send a std::vector<std::array<T, N>>, prefixed with its size.
template<typename T, int N, int M, int Options>
void send (const std::vector< Eigen::Matrix< T, N, M, Options > > &data, int destination, MPI_Comm communicator=MPI_COMM_WORLD)
 Send a std::vector of fixed-size Eigen matrices, prefixed with its size.
template<typename DataType, typename IndexType, IndexType RowSize = IndexType(-1)>
void send (const datastructure::CrsMap< DataType, IndexType, RowSize > &map, int destination, MPI_Comm communicator=MPI_COMM_WORLD)
 Send a CrsMap by sending its data and indices in sequence.
template<typename T>
void recv (T *data, int count, int source, MPI_Comm communicator=MPI_COMM_WORLD, MPI_Status *status=MPI_STATUS_IGNORE)
 Receive count contiguous values of type T from a source rank.
template<typename T>
T recv (int source, MPI_Comm communicator=MPI_COMM_WORLD, MPI_Status *status=MPI_STATUS_IGNORE)
 Receive a single value of type T from a source rank.
template<typename T>
void recv (std::vector< T > &data, int source, MPI_Comm communicator=MPI_COMM_WORLD, MPI_Status *status=MPI_STATUS_IGNORE)
 Receive a std::vector<T> previously sent with send(), resizing data to the transmitted size.
void recv (std::string &data, int source, MPI_Comm communicator=MPI_COMM_WORLD, MPI_Status *status=MPI_STATUS_IGNORE)
 Receive a std::string previously sent with send(), resizing data to the transmitted size.
template<typename T, std::size_t N>
void recv (std::vector< std::array< T, N > > &data, int source, MPI_Comm communicator=MPI_COMM_WORLD, MPI_Status *status=MPI_STATUS_IGNORE)
 Receive a std::vector<std::array<T, N>> previously sent with send(), resizing data to the transmitted size.
template<typename T, int N, int M, int Options>
void recv (std::vector< Eigen::Matrix< T, N, M, Options > > &data, int source, MPI_Comm communicator=MPI_COMM_WORLD, MPI_Status *status=MPI_STATUS_IGNORE)
 Receive a std::vector of fixed-size Eigen matrices previously sent with send(), resizing data to the transmitted size.
template<typename DataType, typename IndexType, IndexType RowSize = IndexType(-1)>
void recv (datastructure::CrsMap< DataType, IndexType, RowSize > &map, int source, MPI_Comm communicator=MPI_COMM_WORLD, MPI_Status *status=MPI_STATUS_IGNORE)
 Receive a CrsMap by receiving its data and indices in sequence.
template<typename T>
void bcast (T *data, int count, int root, MPI_Comm communicator=MPI_COMM_WORLD)
 Broadcast count contiguous values of type T from root.
template<typename T>
void bcast (T &data, int root, MPI_Comm communicator=MPI_COMM_WORLD)
 Broadcast a single value of type T from root.
template<typename T>
void bcast (std::vector< T > &data, int root, MPI_Comm communicator=MPI_COMM_WORLD)
 Broadcast a std::vector<T> from root, resizing data on the other ranks to match the root's size.
void bcast (std::string &data, int root, MPI_Comm communicator=MPI_COMM_WORLD)
 Broadcast a std::string from root, resizing data on the other ranks to match the root's size.
template<typename T, int N, int M, int Options>
void bcast (Eigen::Matrix< T, N, M, Options > &data, int root, MPI_Comm communicator=MPI_COMM_WORLD)
 Broadcast a dynamically-sized Eigen matrix from root, resizing data on the other ranks to match the root's shape.
template<typename T>
void reduce (const T *send_data, T *recv_data, int count, MPI_Op op, int root, MPI_Comm communicator=MPI_COMM_WORLD)
 Reduce count contiguous values of type T onto root.
template<typename T>
T reduce (const T &send_data, MPI_Op op, int root, MPI_Comm communicator=MPI_COMM_WORLD)
 Reduce a single value of type T onto root.
auto computeChuncks (int32_t count, int32_t stride=1)
 Split count elements into near-equal contiguous chunks, one per rank in the current communicator.
template<typename T>
void gather (const T *send_data, int send_count, T *recv_data, int recv_count, int root, MPI_Comm communicator=MPI_COMM_WORLD)
 Gather send_count contiguous values of type T from every rank into recv_data on root.
template<typename T>
void gather (const std::vector< T > &send_data, std::vector< T > &recv_data, int root, MPI_Comm communicator=MPI_COMM_WORLD)
 Gather a std::vector<T> of equal size from every rank into recv_data on root.
template<typename T>
void gatherv (const T *send_data, int send_count, T *recv_data, int *recv_count, int *displs, int root, MPI_Comm communicator=MPI_COMM_WORLD)
 Gather variable-length contiguous values of type T from every rank into recv_data on root.
template<typename T>
void scatter (const T *send_data, int send_count, T *recv_data, int recv_count, int root, MPI_Comm communicator=MPI_COMM_WORLD)
 Scatter recv_count contiguous values of type T from root to every rank.
template<typename T>
void scatter (const std::vector< T > &send_data, std::vector< T > &recv_data, int root, MPI_Comm communicator=MPI_COMM_WORLD)
 Scatter a std::vector<T> from root into equal-size chunks on every rank.
template<typename T>
void scatterv (const T *send_data, int *send_counts, int *displacements, T *recv_data, int recv_count, int root, MPI_Comm mpi_comm=MPI_COMM_WORLD, MPI_Datatype send_t=getMpiType< T >(), MPI_Datatype recv_t=getMpiType< T >())
 Scatter variable-length contiguous values of type T from root to every rank.

Variables

static constexpr int s_default_tag = 0
 Default MPI message tag used by all wrappers in this file.

Function Documentation

◆ bcast() [1/5]

template<typename T, int N, int M, int Options>
void vulpes::mpi::bcast ( Eigen::Matrix< T, N, M, Options > & data,
int root,
MPI_Comm communicator = MPI_COMM_WORLD )

Broadcast a dynamically-sized Eigen matrix from root, resizing data on the other ranks to match the root's shape.

Template Parameters
TScalar type of the matrix (must be supported by getMpiType).
NCompile-time number of rows.
MCompile-time number of columns.
OptionsEigen storage options.
Parameters
dataMatrix to broadcast from (root) / resize and fill (other ranks).
rootRank broadcasting the data.
communicatorMPI communicator to use.

◆ bcast() [2/5]

void vulpes::mpi::bcast ( std::string & data,
int root,
MPI_Comm communicator = MPI_COMM_WORLD )
inline

Broadcast a std::string from root, resizing data on the other ranks to match the root's size.

Parameters
dataString to broadcast from (root) / resize and fill (other ranks).
rootRank broadcasting the data.
communicatorMPI communicator to use.

◆ bcast() [3/5]

template<typename T>
void vulpes::mpi::bcast ( std::vector< T > & data,
int root,
MPI_Comm communicator = MPI_COMM_WORLD )

Broadcast a std::vector<T> from root, resizing data on the other ranks to match the root's size.

Template Parameters
TElement type (must be supported by getMpiType).
Parameters
dataVector to broadcast from (root) / resize and fill (other ranks).
rootRank broadcasting the data.
communicatorMPI communicator to use.

◆ bcast() [4/5]

template<typename T>
void vulpes::mpi::bcast ( T & data,
int root,
MPI_Comm communicator = MPI_COMM_WORLD )

Broadcast a single value of type T from root.

Template Parameters
TValue type (must be supported by getMpiType).
Parameters
dataValue to broadcast from (root) / into (other ranks).
rootRank broadcasting the data.
communicatorMPI communicator to use.

◆ bcast() [5/5]

template<typename T>
void vulpes::mpi::bcast ( T * data,
int count,
int root,
MPI_Comm communicator = MPI_COMM_WORLD )

Broadcast count contiguous values of type T from root.

Template Parameters
TElement type (must be supported by getMpiType).
Parameters
dataBuffer to broadcast from (root) / into (other ranks).
countNumber of elements to broadcast.
rootRank broadcasting the data.
communicatorMPI communicator to use.

◆ computeChuncks()

auto vulpes::mpi::computeChuncks ( int32_t count,
int32_t stride = 1 )
inline

Split count elements into near-equal contiguous chunks, one per rank in the current communicator.

Parameters
countTotal number of elements to split (assumed known identically by every rank).
strideNumber of scalars per element (e.g. vector component count).
Returns
A pair {displacements, counts}, both of size mpi::size(), giving each rank's chunk offset and length (already multiplied by stride), suitable for MPI_*v calls.

◆ gather() [1/2]

template<typename T>
void vulpes::mpi::gather ( const std::vector< T > & send_data,
std::vector< T > & recv_data,
int root,
MPI_Comm communicator = MPI_COMM_WORLD )

Gather a std::vector<T> of equal size from every rank into recv_data on root.

Template Parameters
TElement type (must be supported by getMpiType).
Parameters
send_dataThis rank's contribution.
recv_dataBuffer receiving the concatenated results (valid on root only); its pre-existing size determines the per-rank chunk size (recv_data.size() / mpi::size()).
rootRank receiving the gathered data.
communicatorMPI communicator to use.

◆ gather() [2/2]

template<typename T>
void vulpes::mpi::gather ( const T * send_data,
int send_count,
T * recv_data,
int recv_count,
int root,
MPI_Comm communicator = MPI_COMM_WORLD )

Gather send_count contiguous values of type T from every rank into recv_data on root.

Template Parameters
TElement type (must be supported by getMpiType).
Parameters
send_dataThis rank's contribution.
send_countNumber of elements this rank sends.
recv_dataBuffer receiving the concatenated results (valid on root only), must hold send_count * mpi::size() elements.
recv_countNumber of elements to receive from each rank.
rootRank receiving the gathered data.
communicatorMPI communicator to use.

◆ gatherv()

template<typename T>
void vulpes::mpi::gatherv ( const T * send_data,
int send_count,
T * recv_data,
int * recv_count,
int * displs,
int root,
MPI_Comm communicator = MPI_COMM_WORLD )

Gather variable-length contiguous values of type T from every rank into recv_data on root.

Template Parameters
TElement type (must be supported by getMpiType).
Parameters
send_dataThis rank's contribution.
send_countNumber of elements this rank sends.
recv_dataBuffer receiving the concatenated results (valid on root only).
recv_countPer-rank element counts (valid on root only).
displsPer-rank offsets into recv_data (valid on root only).
rootRank receiving the gathered data.
communicatorMPI communicator to use.

◆ getMpiType()

template<typename T>
MPI_Datatype vulpes::mpi::getMpiType ( )

Map a C++ arithmetic type to its corresponding MPI_Datatype.

Template Parameters
TArithmetic type to map (must be one of the supported built-in integer/floating-point types).
Returns
The MPI_Datatype corresponding to T.

◆ isFinalized()

bool vulpes::mpi::isFinalized ( )
inlinestatic

Return true if MPI has been finalized.

◆ isInitialized()

bool vulpes::mpi::isInitialized ( )
inlinestatic

Return true if MPI has been initialized.

◆ isPetscFinalized()

bool vulpes::mpi::isPetscFinalized ( )
inlinestatic

Return true if PETSc has been finalized.

◆ isPetscInitialized()

bool vulpes::mpi::isPetscInitialized ( )
inlinestatic

Return true if PETSc has been initialized.

◆ rank()

int vulpes::mpi::rank ( )
inlinestatic

Return the MPI rank in MPI_COMM_WORLD.

◆ recv() [1/7]

template<typename DataType, typename IndexType, IndexType RowSize = IndexType(-1)>
void vulpes::mpi::recv ( datastructure::CrsMap< DataType, IndexType, RowSize > & map,
int source,
MPI_Comm communicator = MPI_COMM_WORLD,
MPI_Status * status = MPI_STATUS_IGNORE )

Receive a CrsMap by receiving its data and indices in sequence.

Template Parameters
DataTypeElement type stored in the map.
IndexTypeIndex type used by the map.
RowSizeCompile-time row size of the map (dynamic if -1).
Parameters
mapThe CrsMap to receive into.
sourceRank of the sending process.
communicatorMPI communicator to use.
statusOptional MPI_Status to fill in.

◆ recv() [2/7]

template<typename T>
T vulpes::mpi::recv ( int source,
MPI_Comm communicator = MPI_COMM_WORLD,
MPI_Status * status = MPI_STATUS_IGNORE )

Receive a single value of type T from a source rank.

Template Parameters
TValue type (must be supported by getMpiType).
Parameters
sourceRank of the sending process.
communicatorMPI communicator to use.
statusOptional MPI_Status to fill in.
Returns
The received value.

◆ recv() [3/7]

void vulpes::mpi::recv ( std::string & data,
int source,
MPI_Comm communicator = MPI_COMM_WORLD,
MPI_Status * status = MPI_STATUS_IGNORE )
inline

Receive a std::string previously sent with send(), resizing data to the transmitted size.

Parameters
dataString to receive into; resized to match the sender's size.
sourceRank of the sending process.
communicatorMPI communicator to use.
statusOptional MPI_Status to fill in.

◆ recv() [4/7]

template<typename T, int N, int M, int Options>
void vulpes::mpi::recv ( std::vector< Eigen::Matrix< T, N, M, Options > > & data,
int source,
MPI_Comm communicator = MPI_COMM_WORLD,
MPI_Status * status = MPI_STATUS_IGNORE )

Receive a std::vector of fixed-size Eigen matrices previously sent with send(), resizing data to the transmitted size.

Template Parameters
TScalar type of the matrices (must be supported by getMpiType).
NCompile-time number of rows.
MCompile-time number of columns.
OptionsEigen storage options.
Parameters
dataVector to receive into; resized to match the sender's size.
sourceRank of the sending process.
communicatorMPI communicator to use.
statusOptional MPI_Status to fill in.

◆ recv() [5/7]

template<typename T, std::size_t N>
void vulpes::mpi::recv ( std::vector< std::array< T, N > > & data,
int source,
MPI_Comm communicator = MPI_COMM_WORLD,
MPI_Status * status = MPI_STATUS_IGNORE )

Receive a std::vector<std::array<T, N>> previously sent with send(), resizing data to the transmitted size.

Template Parameters
TElement type (must be supported by getMpiType).
NLength of each array.
Parameters
dataVector to receive into; resized to match the sender's size.
sourceRank of the sending process.
communicatorMPI communicator to use.
statusOptional MPI_Status to fill in.

◆ recv() [6/7]

template<typename T>
void vulpes::mpi::recv ( std::vector< T > & data,
int source,
MPI_Comm communicator = MPI_COMM_WORLD,
MPI_Status * status = MPI_STATUS_IGNORE )

Receive a std::vector<T> previously sent with send(), resizing data to the transmitted size.

Template Parameters
TElement type (must be supported by getMpiType).
Parameters
dataVector to receive into; resized to match the sender's size.
sourceRank of the sending process.
communicatorMPI communicator to use.
statusOptional MPI_Status to fill in.

◆ recv() [7/7]

template<typename T>
void vulpes::mpi::recv ( T * data,
int count,
int source,
MPI_Comm communicator = MPI_COMM_WORLD,
MPI_Status * status = MPI_STATUS_IGNORE )

Receive count contiguous values of type T from a source rank.

Template Parameters
TElement type (must be supported by getMpiType).
Parameters
dataPointer to the buffer to receive into (must hold count elements).
countNumber of elements to receive.
sourceRank of the sending process.
communicatorMPI communicator to use.
statusOptional MPI_Status to fill in.

◆ reduce() [1/2]

template<typename T>
T vulpes::mpi::reduce ( const T & send_data,
MPI_Op op,
int root,
MPI_Comm communicator = MPI_COMM_WORLD )

Reduce a single value of type T onto root.

Template Parameters
TValue type (must be supported by getMpiType).
Parameters
send_dataThis process's contribution to the reduction.
opMPI reduction operator (e.g. MPI_SUM).
rootRank receiving the reduced result.
communicatorMPI communicator to use.
Returns
The reduced result on root; unspecified on other ranks.

◆ reduce() [2/2]

template<typename T>
void vulpes::mpi::reduce ( const T * send_data,
T * recv_data,
int count,
MPI_Op op,
int root,
MPI_Comm communicator = MPI_COMM_WORLD )

Reduce count contiguous values of type T onto root.

Template Parameters
TElement type (must be supported by getMpiType).
Parameters
send_dataBuffer of values to reduce, one per process.
recv_dataBuffer receiving the reduced result (valid on root only).
countNumber of elements to reduce.
opMPI reduction operator (e.g. MPI_SUM).
rootRank receiving the reduced result.
communicatorMPI communicator to use.

◆ root()

bool vulpes::mpi::root ( )
inlinestatic

Return true if the rank in MPI_COMM_WORLD is zero.

◆ scatter() [1/2]

template<typename T>
void vulpes::mpi::scatter ( const std::vector< T > & send_data,
std::vector< T > & recv_data,
int root,
MPI_Comm communicator = MPI_COMM_WORLD )

Scatter a std::vector<T> from root into equal-size chunks on every rank.

Template Parameters
TElement type (must be supported by getMpiType).
Parameters
send_dataVector on root to distribute (unused on other ranks); its size must be a multiple of mpi::size().
recv_dataBuffer receiving this rank's chunk; its pre-existing size determines the chunk length.
rootRank distributing the data.
communicatorMPI communicator to use.

◆ scatter() [2/2]

template<typename T>
void vulpes::mpi::scatter ( const T * send_data,
int send_count,
T * recv_data,
int recv_count,
int root,
MPI_Comm communicator = MPI_COMM_WORLD )

Scatter recv_count contiguous values of type T from root to every rank.

Template Parameters
TElement type (must be supported by getMpiType).
Parameters
send_dataBuffer on root holding recv_count * mpi::size() elements to distribute (unused on other ranks).
send_countNumber of elements root sends to each rank.
recv_dataBuffer receiving this rank's chunk.
recv_countNumber of elements this rank receives.
rootRank distributing the data.
communicatorMPI communicator to use.

◆ scatterv()

template<typename T>
void vulpes::mpi::scatterv ( const T * send_data,
int * send_counts,
int * displacements,
T * recv_data,
int recv_count,
int root,
MPI_Comm mpi_comm = MPI_COMM_WORLD,
MPI_Datatype send_t = getMpiType<T>(),
MPI_Datatype recv_t = getMpiType<T>() )

Scatter variable-length contiguous values of type T from root to every rank.

Template Parameters
TElement type (must be supported by getMpiType).
Parameters
send_dataBuffer on root holding the data to distribute (unused on other ranks).
send_countsPer-rank element counts (valid on root only).
displacementsPer-rank offsets into send_data (valid on root only).
recv_dataBuffer receiving this rank's chunk.
recv_countNumber of elements this rank receives.
rootRank distributing the data.
mpi_commMPI communicator to use.
send_tMPI datatype of the sent elements.
recv_tMPI datatype of the received elements.

◆ send() [1/7]

template<typename DataType, typename IndexType, IndexType RowSize = IndexType(-1)>
void vulpes::mpi::send ( const datastructure::CrsMap< DataType, IndexType, RowSize > & map,
int destination,
MPI_Comm communicator = MPI_COMM_WORLD )

Send a CrsMap by sending its data and indices in sequence.

Template Parameters
DataTypeElement type stored in the map.
IndexTypeIndex type used by the map.
RowSizeCompile-time row size of the map (dynamic if -1).
Parameters
mapThe CrsMap to send.
destinationRank of the receiving process.
communicatorMPI communicator to use.

◆ send() [2/7]

void vulpes::mpi::send ( const std::string & data,
int destination,
MPI_Comm communicator = MPI_COMM_WORLD )
inline

Send a std::string, prefixed with its size.

Parameters
dataThe string to send.
destinationRank of the receiving process.
communicatorMPI communicator to use.

◆ send() [3/7]

template<typename T, int N, int M, int Options>
void vulpes::mpi::send ( const std::vector< Eigen::Matrix< T, N, M, Options > > & data,
int destination,
MPI_Comm communicator = MPI_COMM_WORLD )

Send a std::vector of fixed-size Eigen matrices, prefixed with its size.

Template Parameters
TScalar type of the matrices (must be supported by getMpiType).
NCompile-time number of rows.
MCompile-time number of columns.
OptionsEigen storage options.
Parameters
dataThe vector of matrices to send.
destinationRank of the receiving process.
communicatorMPI communicator to use.

◆ send() [4/7]

template<typename T, std::size_t N>
void vulpes::mpi::send ( const std::vector< std::array< T, N > > & data,
int destination,
MPI_Comm communicator = MPI_COMM_WORLD )

Send a std::vector<std::array<T, N>>, prefixed with its size.

Template Parameters
TElement type (must be supported by getMpiType).
NLength of each array.
Parameters
dataThe vector of fixed-size arrays to send.
destinationRank of the receiving process.
communicatorMPI communicator to use.

◆ send() [5/7]

template<typename T>
void vulpes::mpi::send ( const std::vector< T > & data,
int destination,
MPI_Comm communicator = MPI_COMM_WORLD )

Send a std::vector<T>, prefixed with its size.

Template Parameters
TElement type (must be supported by getMpiType).
Parameters
dataThe vector to send.
destinationRank of the receiving process.
communicatorMPI communicator to use.

◆ send() [6/7]

template<typename T>
void vulpes::mpi::send ( const T & data,
int destination,
MPI_Comm communicator = MPI_COMM_WORLD )

Send a single value of type T to a destination rank.

Template Parameters
TValue type (must be supported by getMpiType).
Parameters
dataThe value to send.
destinationRank of the receiving process.
communicatorMPI communicator to use.

◆ send() [7/7]

template<typename T>
void vulpes::mpi::send ( const T * data,
int count,
int destination,
MPI_Comm communicator = MPI_COMM_WORLD )

Send count contiguous values of type T to a destination rank.

Template Parameters
TElement type (must be supported by getMpiType).
Parameters
dataPointer to the first element to send.
countNumber of elements to send.
destinationRank of the receiving process.
communicatorMPI communicator to use.

◆ size()

int vulpes::mpi::size ( )
inlinestatic

Return the size of MPI_COMM_WORLD.

Variable Documentation

◆ s_default_tag

int vulpes::mpi::s_default_tag = 0
inlinestaticconstexpr

Default MPI message tag used by all wrappers in this file.