Template Numerical Library version\ main:4e58ea6
Loading...
Searching...
No Matches
TNL::MPI::Comm Class Reference

An RAII wrapper for custom MPI communicators. More...

#include <TNL/MPI/Comm.h>

Public Member Functions

 Comm ()=default
 Constructs an empty communicator with a null handle (MPI_COMM_NULL).
 
 Comm (Comm &&other)=default
 Default move-constructor.
 
 Comm (const Comm &other)=default
 Default copy-constructor.
 
 Comm (MPI_Comm comm)
 Constructs a communicator initialized by given predefined communicator.
 
void barrier () const
 Wait for all processes within a communicator to reach the barrier.
 
int compare (MPI_Comm comm2) const
 Compares two communicators – wrapper for MPI_Comm_compare.
 
Comm duplicate () const
 Non-static factory method – wrapper for MPI_Comm_dup
 
 operator const MPI_Comm & () const
 Access the MPI communicator associated with this object.
 
Commoperator= (Comm &&other)=default
 Default move-assignment operator.
 
Commoperator= (const Comm &other)=default
 Default copy-assignment operator.
 
int rank () const
 Determines the rank of the calling process in the communicator.
 
int size () const
 Returns the size of the group associated with a communicator.
 
Comm split (int color, int key) const
 Non-static factory method – wrapper for MPI_Comm_split
 
Comm split_type (int split_type, int key, MPI_Info info) const
 Non-static factory method – wrapper for MPI_Comm_split_type
 

Static Public Member Functions

static Comm duplicate (MPI_Comm comm)
 Factory method – wrapper for MPI_Comm_dup
 
static Comm split (MPI_Comm comm, int color, int key)
 Factory method – wrapper for MPI_Comm_split
 
static Comm split_type (MPI_Comm comm, int split_type, int key, MPI_Info info)
 Factory method – wrapper for MPI_Comm_split_type
 

Detailed Description

An RAII wrapper for custom MPI communicators.

This is an RAII wrapper for custom MPI communicators created by calls to MPI_Comm_create, MPI_Comm_split, or similar functions. It is based on std::shared_ptr so copy-constructible and copy-assignable, copies of the object represent the same communicator that is deallocated only when the internal reference counter drops to zero.

Note that predefined communicators (i.e. MPI_COMM_WORLD, MPI_COMM_NULL and MPI_COMM_SELF) can be used to initialize this class, but other handles of the MPI_Comm type cannot be used to initialize this class.

This class follows the factory pattern, i.e. it provides static methods such as Comm::duplicate or Comm::split that return an instance of a new communicator.

Constructor & Destructor Documentation

◆ Comm()

TNL::MPI::Comm::Comm ( MPI_Comm comm)
inline

Constructs a communicator initialized by given predefined communicator.

Note that only predefined communicators (i.e. MPI_COMM_WORLD, MPI_COMM_NULL and MPI_COMM_SELF) can be used to initialize this class. Other handles of the MPI_Comm type cannot be used to initialize this class.

Exceptions
std::logic_errorwhen the comm handle is not a predefined communicator.

Member Function Documentation

◆ barrier()

void TNL::MPI::Comm::barrier ( ) const
inline

Wait for all processes within a communicator to reach the barrier.

This routine is a collective operation that blocks each process until all processes have entered it, then releases all of the processes "simultaneously". It is equivalent to calling MPI_Barrier with the MPI communicator associated with this object.

◆ operator const MPI_Comm &()

TNL::MPI::Comm::operator const MPI_Comm & ( ) const
inline

Access the MPI communicator associated with this object.

This routine permits the implicit conversion from Comm to MPI_Comm.

Warning
The obtained MPI_Comm handle becomes invalid when the originating Comm object is destroyed. For example, the following code is invalid, because the Comm object managing the lifetime of the communicator is destroyed as soon as it is cast to MPI_Comm:
const MPI_Comm comm = MPI::Comm::duplicate( MPI_COMM_WORLD );
const int nproc = MPI::GetSize( comm );
Comm duplicate() const
Non-static factory method – wrapper for MPI_Comm_dup
Definition Comm.h:148

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