BioCMAMC-ST
WrapMPI Namespace Reference

Namespace to correclty wrap MPI C API for modern C++. More...

Namespaces

namespace  Async
 

Classes

class  HostIterationPayload
 Represents the payload of data on the host side for an iteration. More...
 
class  IterationPayload
 Represents the payload of data exchanged during an iteration. More...
 

Concepts

concept  POD_t
 

Enumerations

enum class  SIGNALS : char { STOP , RUN , NOP , DUMP }
 

Functions

template<POD_t DataType>
static int _send_unsafe (DataType *buf, size_t buf_size, size_t dest, size_t tag=0) noexcept
 Sends raw data to a destination in an unsafe manner.
 
template<POD_t DataType>
int send (DataType data, size_t dest, size_t tag=0)
 Sends a single instance of data to a destination.
 
template<POD_t DataType>
int send_v (std::span< const DataType > data, size_t dest, size_t tag=0, bool send_size=true) noexcept
 Sends a vector of data to a destination.
 
template<POD_t DataType>
std::optional< DataType > recv (size_t src, MPI_Status *status=nullptr, size_t tag=0) noexcept
 Receives a single data item from a source.
 
template<POD_t DataType>
int recv_span (std::span< DataType > buf, size_t src, MPI_Status *status=nullptr, size_t tag=0) noexcept
 Receives data into a span buffer.
 
template<POD_t DataType>
DataType try_recv (size_t src, MPI_Status *status=nullptr, size_t tag=0)
 Attempts to receive a single data item from a source.
 
template<POD_t T>
std::optional< std::vector< T > > recv_v (size_t source, MPI_Status *status=nullptr, size_t tag=0) noexcept
 Receives a vector of data items from a source.
 
template<POD_t T>
std::vector< T > try_recv_v (size_t src, MPI_Status *status=nullptr, size_t tag=0)
 Attempts to receive a vector of data items from a source.
 
template<POD_t T>
int _broadcast_unsafe (T *data, size_t _size, size_t root)
 Broadcasts raw data to all processes in an unsafe manner.
 
template<POD_t DataType>
int broadcast (DataType &data, size_t root) noexcept
 Broadcasts a single data item to all processes.
 
template<POD_t T>
int broadcast_span (std::span< T > data, size_t root)
 Broadcasts data stored in a span to all processes.
 
template<POD_t... Args>
void host_dispatch (const ExecInfo &info, SIGNALS sign, Args &&... args)
 Dispatches a task to the host with signal and arguments.
 
template<POD_t T>
std::vector< T > _gather_unsafe (T *src_data, size_t size, size_t n_rank, size_t root=0)
 Gathers raw data from all processes in an unsafe manner.
 
template<POD_t T>
int _gather_unsafe_to_buffer (T *dest, T *src_data, size_t size, size_t root=0) noexcept
 
template<POD_t T>
std::vector< T > gather (std::span< T > local_data, size_t n_rank, size_t root=0)
 Gathers data from all processes.
 
template<POD_t T>
void gather_span (std::span< T > dest, std::span< const T > local_data, size_t root=0)
 
template<NumberType T>
gather_reduce (T data, size_t root=0)
 Gathers and reduces data to a single value.
 
template<NumberType T>
all_reduce (T data)
 
template<POD_t T>
std::vector< T > gather_v (const std::vector< T > &local_data, size_t n_rank, size_t root=0)
 Gathers a vector of data from all processes.
 
template<POD_t T>
int broadcast (std::vector< T > &data, size_t root, size_t current_rank)
 
int critical_error () noexcept
 
void barrier () noexcept
 
void finalize () noexcept
 
bool is_initialized () noexcept
 
template<typename T >
constexpr MPI_Datatype get_type () noexcept
 

Detailed Description

Namespace to correclty wrap MPI C API for modern C++.

Enumeration Type Documentation

◆ SIGNALS

enum class WrapMPI::SIGNALS : char
strong
Enumerator
STOP 
RUN 
NOP 
DUMP 

Function Documentation

◆ _broadcast_unsafe()

template<POD_t T>
int WrapMPI::_broadcast_unsafe ( T * data,
size_t _size,
size_t root )
nodiscard

Broadcasts raw data to all processes in an unsafe manner.

This function sends raw data of type T from the root process to all other processes. It performs only basic safety checks

Template Parameters
TThe type of the data to broadcast.
Parameters
dataPointer to the data to be broadcasted.
_sizeThe size of the data in bytes.
rootThe identifier of the root process that initiates the broadcast.
Returns
An integer indicating the success or failure of the operation.
Note
Use this function with caution
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _gather_unsafe()

template<POD_t T>
std::vector< T > WrapMPI::_gather_unsafe ( T * src_data,
size_t size,
size_t n_rank,
size_t root = 0 )

Gathers raw data from all processes in an unsafe manner.

This function collects raw data of type T from all processes into a single vector on the root process. It performs no safety checks and assumes the input pointers and sizes are valid.

Template Parameters
TThe type of the data to gather.
Parameters
src_dataPointer to the local data to be gathered.
sizeThe size of the local data in bytes.
n_rankThe number of processes in the communicator.
rootThe identifier of the root process that gathers the data (default is 0).
Returns
A vector containing the gathered data on the root process.
Note
Use this function with caution as it performs no validation on the input.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _gather_unsafe_to_buffer()

template<POD_t T>
int WrapMPI::_gather_unsafe_to_buffer ( T * dest,
T * src_data,
size_t size,
size_t root = 0 )
noexcept
Here is the call graph for this function:
Here is the caller graph for this function:

◆ _send_unsafe()

template<POD_t DataType>
static int WrapMPI::_send_unsafe ( DataType * buf,
size_t buf_size,
size_t dest,
size_t tag = 0 )
staticnodiscardnoexcept

Sends raw data to a destination in an unsafe manner.

This function sends raw data of type DataType to the specified destination. It assumes the provided buffer and its size are valid

Template Parameters
DataTypeA type satisfying the POD concept.
Parameters
bufPointer to the buffer containing data to send.
buf_sizeThe size of the buffer in bytes.
destThe destination identifier for the data.
tagOptional tag to identify the message (default is 0).
Returns
An integer indicating success or failure of the operation.
Note
Use this function with caution as it performs no validation on the input.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ all_reduce()

template<NumberType T>
T WrapMPI::all_reduce ( T data)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ barrier()

void WrapMPI::barrier ( )
noexcept
Here is the call graph for this function:
Here is the caller graph for this function:

◆ broadcast() [1/2]

template<POD_t DataType>
int WrapMPI::broadcast ( DataType & data,
size_t root )
noexcept

Broadcasts a single data item to all processes.

This function sends a single object of type DataType from the root process to all other processes.

Template Parameters
DataTypeA type satisfying the POD concept.
Parameters
dataReference to the data to be broadcasted.
rootThe identifier of the root process that initiates the broadcast.
Returns
An integer indicating the success or failure of the operation.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ broadcast() [2/2]

template<POD_t T>
int WrapMPI::broadcast ( std::vector< T > & data,
size_t root,
size_t current_rank )
Here is the call graph for this function:

◆ broadcast_span()

template<POD_t T>
int WrapMPI::broadcast_span ( std::span< T > data,
size_t root )

Broadcasts data stored in a span to all processes.

This function sends data stored in a std::span from the root process to all other processes.

Template Parameters
TThe type of the data to broadcast.
Parameters
dataA std::span containing the data to be broadcasted.
rootThe identifier of the root process that initiates the broadcast.
Returns
An integer indicating the success or failure of the operation.
Here is the call graph for this function:

◆ critical_error()

int WrapMPI::critical_error ( )
noexcept
Here is the caller graph for this function:

◆ finalize()

void WrapMPI::finalize ( )
noexcept
Here is the caller graph for this function:

◆ gather()

template<POD_t T>
std::vector< T > WrapMPI::gather ( std::span< T > local_data,
size_t n_rank,
size_t root = 0 )

Gathers data from all processes.

This function collects data stored in a std::span from all processes into a single vector on the root process.

Template Parameters
TThe type of the data to gather.
Parameters
local_dataA std::span containing the local data to be gathered.
n_rankThe number of processes in the communicator.
rootThe identifier of the root process that gathers the data (default is 0).
Returns
A vector containing the gathered data on the root process.
Here is the call graph for this function:

◆ gather_reduce()

template<NumberType T>
T WrapMPI::gather_reduce ( T data,
size_t root = 0 )

Gathers and reduces data to a single value.

This function collects data of type T from all processes, performs a reduction operation (sum), and returns the result to the root process.

Template Parameters
TA type satisfying the NumberType concept.
Parameters
dataThe local data to be reduced and gathered.
rootThe identifier of the root process that gathers and reduces the data (default is 0).
Returns
The reduced value on the root process.
Here is the call graph for this function:

◆ gather_span()

template<POD_t T>
void WrapMPI::gather_span ( std::span< T > dest,
std::span< const T > local_data,
size_t root = 0 )
Here is the call graph for this function:

◆ gather_v()

template<POD_t T>
std::vector< T > WrapMPI::gather_v ( const std::vector< T > & local_data,
size_t n_rank,
size_t root = 0 )

Gathers a vector of data from all processes.

This function collects vectors of data from all processes into a single vector on the root process.

Template Parameters
TThe type of the data to gather.
Parameters
local_dataA vector containing the local data to be gathered.
n_rankThe number of processes in the communicator.
rootThe identifier of the root process that gathers the data (default is 0).
Returns
A vector containing the gathered data on the root process.
Here is the call graph for this function:

◆ get_type()

template<typename T >
MPI_Datatype WrapMPI::get_type ( )
constexprnoexcept
Here is the caller graph for this function:

◆ host_dispatch()

template<POD_t... Args>
void WrapMPI::host_dispatch ( const ExecInfo & info,
SIGNALS sign,
Args &&... args )

Dispatches a task to the host with signal and arguments.

This function sends execution information and arguments to the host for processing, triggered by a specific signal.

Template Parameters
ArgsVariadic template types for the arguments.
Parameters
infoAn ExecInfo object containing execution metadata.
signA SIGNALS enumeration indicating the signal to trigger the task.
argsVariadic arguments to pass to the host.

◆ is_initialized()

bool WrapMPI::is_initialized ( )
noexcept
Here is the caller graph for this function:

◆ recv()

template<POD_t DataType>
std::optional< DataType > WrapMPI::recv ( size_t src,
MPI_Status * status = nullptr,
size_t tag = 0 )
noexcept

Receives a single data item from a source.

This function attempts to receive a single object of type DataType from the specified source. If the receive operation fails, it returns an empty std::optional.

Template Parameters
DataTypeA type satisfying the POD concept.
Parameters
srcThe source identifier from which to receive data.
statusOptional pointer to an MPI_Status structure to retrieve message details (default is nullptr).
tagOptional tag to filter messages (default is 0).
Returns
A std::optional containing the received data if successful, or empty if the operation fails.
Here is the caller graph for this function:

◆ recv_span()

template<POD_t DataType>
int WrapMPI::recv_span ( std::span< DataType > buf,
size_t src,
MPI_Status * status = nullptr,
size_t tag = 0 )
noexcept

Receives data into a span buffer.

This function attempts to receive data into the provided span buffer. The buffer must be pre-allocated and of sufficient size to hold the incoming data.

Template Parameters
DataTypeA type satisfying the POD concept.
Parameters
bufA std::span representing the destination buffer for the data.
srcThe source identifier from which to receive data.
statusOptional pointer to an MPI_Status structure to retrieve message details (default is nullptr).
tagOptional tag to filter messages (default is 0).
Returns
An integer indicating the success or failure of the operation.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ recv_v()

template<POD_t T>
std::optional< std::vector< T > > WrapMPI::recv_v ( size_t source,
MPI_Status * status = nullptr,
size_t tag = 0 )
noexcept

Receives a vector of data items from a source.

This function attempts to receive a vector of objects of type T from the specified source. If the receive operation fails, it returns an empty std::optional.

Template Parameters
TThe type of data to receive.
Parameters
sourceThe source identifier from which to receive data.
statusOptional pointer to an MPI_Status structure to retrieve message details (default is nullptr).
tagOptional tag to filter messages (default is 0).
Returns
A std::optional containing the received vector if successful, or empty if the operation fails.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ send()

template<POD_t DataType>
int WrapMPI::send ( DataType data,
size_t dest,
size_t tag = 0 )

Sends a single instance of data to a destination.

This function sends a single object of type DataType to the specified destination.

Template Parameters
DataTypeA type satisfying the POD concept.
Parameters
dataThe data object to send.
destThe destination identifier for the data.
tagOptional tag to identify the message (default is 0).
Returns
An integer indicating success or failure of the operation.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ send_v()

template<POD_t DataType>
int WrapMPI::send_v ( std::span< const DataType > data,
size_t dest,
size_t tag = 0,
bool send_size = true )
noexcept

Sends a vector of data to a destination.

This function sends a collection of objects of type DataType to the specified destination. Optionally, the size of the collection can also be transmitted.

Template Parameters
DataTypeA type satisfying the POD concept.
Parameters
dataA std::span containing the data to send.
destThe destination identifier for the data.
tagOptional tag to identify the message (default is 0).
send_sizeIf true, the size of the data will be sent before the data itself (default is true).
Returns
An integer indicating success or failure of the operation.
Here is the call graph for this function:

◆ try_recv()

template<POD_t DataType>
DataType WrapMPI::try_recv ( size_t src,
MPI_Status * status = nullptr,
size_t tag = 0 )

Attempts to receive a single data item from a source.

This function attempts to receive a single object of type DataType from the specified source. If the operation fails, it throws an exception.

Template Parameters
DataTypeA type satisfying the POD concept.
Parameters
srcThe source identifier from which to receive data.
statusOptional pointer to an MPI_Status structure to retrieve message details (default is nullptr).
tagOptional tag to filter messages (default is 0).
Returns
The received data item.
Exceptions
Anexception if the receive operation fails.
Here is the call graph for this function:

◆ try_recv_v()

template<POD_t T>
std::vector< T > WrapMPI::try_recv_v ( size_t src,
MPI_Status * status = nullptr,
size_t tag = 0 )

Attempts to receive a vector of data items from a source.

This function attempts to receive a vector of objects of type T from the specified source. If the operation fails, it throws an exception.

Template Parameters
TThe type of data to receive.
Parameters
srcThe source identifier from which to receive data.
statusOptional pointer to an MPI_Status structure to retrieve message details (default is nullptr).
tagOptional tag to filter messages (default is 0).
Returns
A vector containing the received data items.
Exceptions
Anexception if the receive operation fails.
Here is the call graph for this function: