TRIQS/mpi 1.3.0
C++ interface to MPI
|
#include <mpi/communicator.hpp>
C++ wrapper around MPI_Comm
providing various convenience functions.
It stores an MPI_Comm
object as its only member which by default is set to MPI_COMM_WORLD
. Note that copying the communicator simply copies the MPI_Comm
object, without calling MPI_Comm_dup
.
All functions that make direct calls to the MPI C library throw an exception in case the call fails.
Definition at line 43 of file communicator.hpp.
Public Member Functions | |
communicator ()=default | |
Construct a communicator with MPI_COMM_WORLD . | |
communicator (MPI_Comm c) | |
Construct a communicator with a given MPI_Comm object. | |
void | abort (int error_code) const |
If mpi::has_env is true, MPI_Abort is called with the given error code, otherwise std::abort is called. | |
void | barrier (long poll_msec=1) const |
Barrier synchronization. | |
communicator | duplicate () const |
Duplicate the communicator. | |
void | free () |
Free the communicator. | |
MPI_Comm | get () const noexcept |
Get the wrapped MPI_Comm object. | |
int | rank () const |
Get the rank of the calling process in the communicator. | |
int | size () const |
Get the size of the communicator. | |
communicator | split (int color, int key=0) const |
Split the communicator into disjoint subgroups. | |
|
inline |
Construct a communicator with a given MPI_Comm
object.
The MPI_Comm
object is copied without calling MPI_Comm_dup
.
Definition at line 55 of file communicator.hpp.
|
inline |
If mpi::has_env is true, MPI_Abort
is called with the given error code, otherwise std::abort is called.
error_code | The error code to pass to MPI_Abort . |
Definition at line 145 of file communicator.hpp.
|
inline |
Barrier synchronization.
Does nothing if mpi::has_env is false. Otherwise, it either uses a blocking MPI_Barrier
(if the given argument is 0) or a non-blocking MPI_Ibarrier
call. The given parameter determines in milliseconds how often each process calls MPI_Test
to check if all processes have reached the barrier. This can considerably reduce the CPU load:
For a very unbalanced load that takes a long time to finish, 1000 msec is a good choice.
poll_msec | The polling interval in milliseconds. If set to 0, a simple MPI_Barrier call is used. |
Definition at line 173 of file communicator.hpp.
|
inlinenodiscard |
Duplicate the communicator.
Calls MPI_Comm_dup
to duplicate the communicator. See the MPI documentation for more details, e.g. open-mpi docs.
free
on the returned communicator when it is no longer needed.MPI_Comm
object wrapped in a new mpi::communicator, otherwise return a default constructed mpi::communicator. Definition at line 119 of file communicator.hpp.
|
inline |
Free the communicator.
Calls MPI_Comm_free
to mark the communicator for deallocation. See the MPI documentation for more details, e.g. open-mpi docs .
Does nothing, if mpi::has_env is false.
Definition at line 137 of file communicator.hpp.
|
inlinenodiscard |
Get the rank of the calling process in the communicator.
MPI_Comm_rank
if mpi::has_env is true, otherwise 0. Definition at line 64 of file communicator.hpp.
|
inlinenodiscard |
Get the size of the communicator.
MPI_Comm_size
if mpi::has_env is true, otherwise 1. Definition at line 77 of file communicator.hpp.
|
inlinenodiscard |
Split the communicator into disjoint subgroups.
Calls MPI_Comm_split
with the given color and key arguments. See the MPI documentation for more details, e.g. open-mpi docs.
free
on the returned communicator when it is no longer needed.MPI_Comm
object wrapped in a new mpi::communicator, otherwise return a default constructed mpi::communicator. Definition at line 98 of file communicator.hpp.