OpenMPCD
Public Member Functions | List of all members
OpenMPCD::MPI Class Reference

Wraps MPI functionality. More...

#include <MPI.hpp>

Public Member Functions

 MPI ()
 The constructor. More...
 
 ~MPI ()
 The destructor. More...
 
std::size_t getNumberOfProcesses () const
 Returns the total number of processes. More...
 
std::size_t getRank () const
 Returns the rank of the current process. More...
 
template<typename T >
void broadcast (T *const buffer, const std::size_t count, const std::size_t root) const
 Implements the MPI_BCAST functionality. More...
 
void barrier ()
 Implements the MPI_BARRIER functionality. More...
 
bool test (MPI_Request *const request, std::size_t *const sender=NULL) const
 Calls MPI_TEST on the given request. More...
 

Detailed Description

Wraps MPI functionality.

The first instance of this class that is constructed in a program will initialize the MPI library, and will also finalize it once it is destructed. After that point, no new instances of this class may be constructed, and at that point, no other instances of this class may exist.

All functions can throw OpenMPCD::Exception in case of an MPI error.

Definition at line 26 of file MPI.hpp.

Constructor & Destructor Documentation

◆ MPI()

OpenMPCD::MPI::MPI ( )

The constructor.

Definition at line 12 of file MPI.cpp.

◆ ~MPI()

OpenMPCD::MPI::~MPI ( )

The destructor.

Definition at line 44 of file MPI.cpp.

Member Function Documentation

◆ barrier()

void OpenMPCD::MPI::barrier ( )

Implements the MPI_BARRIER functionality.

The communicator is taken to be MPI_COMM_WORLD.

Definition at line 121 of file MPI.cpp.

◆ broadcast()

template<typename T >
void OpenMPCD::MPI::broadcast ( T *const  buffer,
const std::size_t  count,
const std::size_t  root 
) const

Implements the MPI_BCAST functionality.

The MPI communicator used is MPI_COMM_WORLD.

Exceptions
OpenMPCD::NULLPointerExceptionIf OPENMPCD_DEBUG is defined, throws if count != 0 && buffer == nullptr.
OpenMPCD::OutOfBoundsExceptionIf OPENMPCD_DEBUG is defined, throws if root >= getNumberOfProcesses().
Template Parameters
TThe type of elements to broadcast.
Parameters
[in,out]bufferIf root == getRank(), this designates the buffer to send from; otherwise, this designates the buffer to receive into. In either case, the buffer must be able to hold at least count elements, unless count == 0.
[in]countThe number of elements to broadcast. May be 0, in which case this function does nothing.
[in]rootThe root process rank.

Definition at line 19 of file ImplementationDetails/MPI.hpp.

◆ getNumberOfProcesses()

std::size_t OpenMPCD::MPI::getNumberOfProcesses ( ) const

Returns the total number of processes.

Definition at line 79 of file MPI.cpp.

◆ getRank()

std::size_t OpenMPCD::MPI::getRank ( ) const

Returns the rank of the current process.

Definition at line 100 of file MPI.cpp.

◆ test()

bool OpenMPCD::MPI::test ( MPI_Request *const  request,
std::size_t *const  sender = NULL 
) const

Calls MPI_TEST on the given request.

Exceptions
OpenMPCD::NULLPointerExceptionIf OPENMPCD_DEBUG is defined, throws if request == nullptr.
OpenMPCD::InvalidArgumentExceptionIf OPENMPCD_DEBUG is defined, throws if *request == MPI_REQUEST_NULL.
Parameters
[in,out]requestThe request to test; if completed, the pointee will be set MPI_REQUEST_NULL.
[out]senderIf not nullptr and if the request is completed, the pointee is set to the rank of the sender of the received message, if such information is available.
Returns
Returns true if the request has been completed, false otherwise.

Definition at line 127 of file MPI.cpp.


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