Template Struct MPIWrapper

Struct Documentation

template<typename Real>
struct MPIWrapper

The MPIWrapper struct is a lightweight C++ wrapper around the C MPI functions. Its main purpose is to provide RAII semantics, ensuring that memory is correctly freed. It also conveniently abstracts away the different MPI type descriptors for each floating point type.

Public Functions

inline void assertNodePartitioningValid(int numNodes, int numNodesX, int numNodesY, int numNodesZ) const
inline MPIWrapper()
inline MPIWrapper(const MPI_Comm &communicator, int numNodesX, int numNodesY, int numNodesZ)
inline ~MPIWrapper()
inline void barrier()

barrier wait for all members of this communicator to reach this point.

inline std::unique_ptr<MPIWrapper> split(int color, int key)

split split this communicator into subgroups.

Parameters:
  • color – the number identifying the subgroup the new communicator belongs to.

  • key – the rank of the new communicator within the subgroup.

Returns:

the new communicator.

inline void allToAll(std::complex<Real> *inBuffer, std::complex<Real> *outBuffer, int dimension)

allToAll perform alltoall communication within this communicator.

Parameters:
  • inBuffer – the buffer containing input data.

  • outBuffer – the buffer to send results to.

  • dimension – the number of elements to be communicated.

inline void allToAll(Real *inBuffer, Real *outBuffer, int dimension)

allToAll perform alltoall communication within this communicator.

Parameters:
  • inBuffer – the buffer containing input data.

  • outBuffer – the buffer to send results to.

  • dimension – the number of elements to be communicated.

inline void reduce(Real *inBuffer, Real *outBuffer, int dimension, int node = 0)

reduce performs a reduction, with summation as the operation.

Parameters:
  • inBuffer – the buffer containing input data.

  • outBuffer – the buffer to send results to.

  • dimension – the number of elements to be reduced.

  • node – the node to reduce the result to (defaulted to zero).

inline void reduceScatterBlock(Real *inBuffer, Real *outBuffer, int dimension)

reduceScatterBlock performs a reduction, with summation as the operation, then scatters to all nodes.

Parameters:
  • inBuffer – the buffer containing input data.

  • outBuffer – the buffer to send results to.

  • dimension – the number of elements to be reduced on each node (currently must be the same on all nodes).

inline void allGather(Real *inBuffer, Real *outBuffer, int dimension)

allGather broadcasts a chunk of data from each node to every other node.

Parameters:
  • inBuffer – the buffer containing input data.

  • dimension – the number of elements to be broadcast.

  • outBuffer – the buffer to send results to.

Public Members

MPITypes<Real> types_
MPI_Comm mpiCommunicator_

The MPI communicator instance to use for all reciprocal space work.

int numNodes_

The total number of MPI nodes involved in reciprocal space work.

int myRank_

The MPI rank of this node.

int numNodesX_

The number of nodes in the X direction.

int numNodesY_

The number of nodes in the Y direction.

int numNodesZ_

The number of nodes in the Z direction.

Friends

inline friend std::ostream &operator<<(std::ostream &os, const MPIWrapper &obj)

operator << a convenience wrapper around ostream, to inject node info.