fml  0.1-0
Fused Matrix Library
fml::comm Class Reference

MPI communicator data and helpers. More...

#include <comm.hh>

Public Member Functions

 comm (MPI_Comm comm=MPI_COMM_WORLD)
 Create a new comm object and uses 'MPI_COMM_WORLD' as the communicator. More...
 
void set (MPI_Comm comm)
 Change communicator to an existing one. More...
 
comm create (MPI_Group group)
 Create new communicator based on color/key. More...
 
comm split (int color, int key)
 Create new communicator based on color/key. More...
 
void free ()
 Destroy communicator.
 
void finalize ()
 Shut down MPI.
 
void printf (int rank, const char *fmt,...) const
 Helper wrapper around the C standard I/O 'printf()' function. Conceptually similar to guarding a normal 'printf()' function with a check for 'rank==rank()'. More...
 
void info () const
 Print some brief information about the MPI communicator. The printing is done by rank 0.
 
bool rank0 () const
 Check if the executing process is rank 0.
 
std::vector< int > jid (const int n) const
 
void barrier () const
 Execute a barrier.
 
template<typename T >
void send (int n, const T *data, int dest, int tag=0) const
 Point-to-point send. Should be matched by a corresponding 'recv' call. More...
 
template<typename T >
void isend (int n, const T *data, int dest, int tag=0) const
 
template<typename T >
void recv (int n, T *data, int source, int tag=0) const
 Point-to-point receive. Should be matched by a corresponding 'send' call. More...
 
template<typename T >
void irecv (int n, T *data, int source, int tag=0) const
 
template<typename T >
void allreduce (int n, T *data, MPI_Op op=MPI_SUM) const
 Sum reduce operation across all processes in the MPI communicator. More...
 
template<typename T >
void reduce (int n, T *data, MPI_Op op=MPI_SUM, int root=0) const
 Sum reduce operation across all processes in the MPI communicator. More...
 
template<typename T >
void bcast (int n, T *data, int root) const
 Broadcast. More...
 
MPI_Comm get_comm () const
 
int rank () const
 Calling process rank (0-based index) in the MPI communicator.
 
int size () const
 Total number of ranks in the MPI communicator. The same across all ranks.
 
int localrank () const
 Calling process rank (0-based index) in within the node.
 
int localsize () const
 Total number of ranks within the node. Can vary across nodes.
 

Protected Attributes

MPI_Comm _comm
 
int _rank
 
int _size
 
int _localrank
 
int _localsize
 

Detailed Description

MPI communicator data and helpers.

Constructor & Destructor Documentation

◆ comm()

fml::comm::comm ( MPI_Comm  comm = MPI_COMM_WORLD)
inline

Create a new comm object and uses 'MPI_COMM_WORLD' as the communicator.

Parameters
[in]commAn MPI communicator. Default is MPI_COMM_WORLD.

Member Function Documentation

◆ allreduce()

template<typename T >
void fml::comm::allreduce ( int  n,
T *  data,
MPI_Op  op = MPI_SUM 
) const
inline

Sum reduce operation across all processes in the MPI communicator.

Parameters
[in]nNumber of elemends of 'data'.
[in,out]dataThe data to reduce.
[in]opMPI reduction operation. Default is MPI_SUM.

◆ bcast()

template<typename T >
void fml::comm::bcast ( int  n,
T *  data,
int  root 
) const
inline

Broadcast.

Parameters
[in]nNumber of elemends of 'data'.
[in,out]dataThe data to broadcast.
[in]rootThe rank in the MPI communicator that does the broadcasting.

◆ create()

fml::comm fml::comm::create ( MPI_Group  group)
inline

Create new communicator based on color/key.

Parameters
[in]group
Returns
The new communicator managed in a new comm object.

◆ get_comm()

MPI_Comm fml::comm::get_comm ( ) const
inline

The MPI communicator.

◆ jid()

std::vector< int > fml::comm::jid ( const int  n) const
inline
Parameters
[in]nThe number of tasks.
Returns
A std::vector of task numbers.

Communication Details
The method has no communication.

◆ printf()

void fml::comm::printf ( int  rank,
const char *  fmt,
  ... 
) const
inline

Helper wrapper around the C standard I/O 'printf()' function. Conceptually similar to guarding a normal 'printf()' function with a check for 'rank==rank()'.

Parameters
[in]rankThe process that should do the printing.
[in]fmtThe printf format string.
[in]...additional arguments to printf.

◆ recv()

template<typename T >
void fml::comm::recv ( int  n,
T *  data,
int  source,
int  tag = 0 
) const
inline

Point-to-point receive. Should be matched by a corresponding 'send' call.

Parameters
[in]nNumber of elements of 'data'.
[in]dataThe data to send.
[in]sourceThe process source in the MPI communicator.
[in]tagOptional MPI tag (default=0).

◆ reduce()

template<typename T >
void fml::comm::reduce ( int  n,
T *  data,
MPI_Op  op = MPI_SUM,
int  root = 0 
) const
inline

Sum reduce operation across all processes in the MPI communicator.

Parameters
[in]nNumber of elemends of 'data'.
[in,out]dataThe data to reduce.
[in]rootThe rank in the MPI communicator to receive the final answer.

◆ send()

template<typename T >
void fml::comm::send ( int  n,
const T *  data,
int  dest,
int  tag = 0 
) const
inline

Point-to-point send. Should be matched by a corresponding 'recv' call.

Parameters
[in]nNumber of elements of 'data'.
[in]dataThe data to send.
[in]destThe process destination in the MPI communicator.
[in]tagOptional MPI tag (default=0).

◆ set()

void fml::comm::set ( MPI_Comm  comm)
inline

Change communicator to an existing one.

Parameters
[in]commAn MPI communicator.

◆ split()

fml::comm fml::comm::split ( int  color,
int  key 
)
inline

Create new communicator based on color/key.

Parameters
[in]color
[in]key
Returns
The new communicator managed in a new comm object.

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