ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
Loading...
Searching...
No Matches
Parallel::ParaWorld Class Reference

Value type describing one MPI communication domain. More...

#include <para_world.h>

Inheritance diagram for Parallel::ParaWorld:
Collaboration diagram for Parallel::ParaWorld:

Public Member Functions

virtual ~ParaWorld ()=default
const std::string & tag () const
 Domain tag string.
int rank () const
 Rank of this process inside the domain (0 in serial builds).
int size () const
 Number of processes in the domain (1 in serial builds).
bool valid () const
 True if this process belongs to the domain.
MPI_Comm comm () const
 Underlying MPI communicator (MPI builds only).

Static Public Member Functions

static ParaWorld serial (const std::string &tag)
 Build a serial (size=1, rank=0) domain for the given tag.
static std::unique_ptr< ParaWorld > make_serial (const std::string &tag)
 Build a serial domain as a heap-allocated unique_ptr.
static ParaWorld make_mpi (const std::string &tag, const MPI_Comm &comm)
 Build a domain wrapping an MPI communicator.
static std::unique_ptr< ParaWorld > make_mpi_ptr (const std::string &tag, const MPI_Comm &comm)

Protected Member Functions

 ParaWorld (const std::string &tag)
 Construct a serial (single-process) domain.
 ParaWorld (const std::string &tag, const MPI_Comm &comm)
 Construct a domain wrapping an existing MPI communicator.

Private Attributes

std::string tag_
 domain tag
int rank_
 rank inside domain
int size_
 number of processes in domain
MPI_Comm comm_
 wrapped communicator (never owned/freed here)

Detailed Description

Value type describing one MPI communication domain.

A ParaWorld couples a domain tag (a short string constant, see para_tag.h) with the communicator, rank and size of the current process inside that domain. It replaces loose globals such as GlobalV::RANK_IN_POOL / POOL_WORLD by an object that functions receive explicitly.

In serial builds (no __MPI) the communicator member does not exist; rank() always returns 0 and size() always returns 1, so call sites compile unchanged in both serial and MPI builds.

Constructor & Destructor Documentation

◆ ~ParaWorld()

virtual Parallel::ParaWorld::~ParaWorld ( )
virtualdefault

◆ ParaWorld() [1/2]

Parallel::ParaWorld::ParaWorld ( const std::string & tag)
explicitprotected

Construct a serial (single-process) domain.

Usable in both serial and MPI builds; in MPI builds the communicator is set to MPI_COMM_SELF. Mainly intended for tests and safe fall-back behavior.

Parameters
[in]tagdomain tag string (must be non-empty for a meaningful domain; empty tag marks "no domain")
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ParaWorld() [2/2]

Parallel::ParaWorld::ParaWorld ( const std::string & tag,
const MPI_Comm & comm )
protected

Construct a domain wrapping an existing MPI communicator.

Parameters
[in]tagdomain tag string
[in]commMPI communicator (may be MPI_COMM_NULL, which yields an invalid domain on this rank)
Here is the call graph for this function:

Member Function Documentation

◆ comm()

MPI_Comm Parallel::ParaWorld::comm ( ) const
inline

Underlying MPI communicator (MPI builds only).

Here is the caller graph for this function:

◆ make_mpi()

ParaWorld Parallel::ParaWorld::make_mpi ( const std::string & tag,
const MPI_Comm & comm )
inlinestatic

Build a domain wrapping an MPI communicator.

Factory for setup functions that need to create ParaWorld objects from split communicators.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ make_mpi_ptr()

std::unique_ptr< ParaWorld > Parallel::ParaWorld::make_mpi_ptr ( const std::string & tag,
const MPI_Comm & comm )
inlinestatic
Here is the call graph for this function:
Here is the caller graph for this function:

◆ make_serial()

std::unique_ptr< ParaWorld > Parallel::ParaWorld::make_serial ( const std::string & tag)
inlinestatic

Build a serial domain as a heap-allocated unique_ptr.

Convenience factory for ParaCollection::add().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ rank()

int Parallel::ParaWorld::rank ( ) const
inline

Rank of this process inside the domain (0 in serial builds).

Here is the caller graph for this function:

◆ serial()

ParaWorld Parallel::ParaWorld::serial ( const std::string & tag)
inlinestatic

Build a serial (size=1, rank=0) domain for the given tag.

Safe degradation used by tests and by ParaCollection when a tag is not found.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ size()

int Parallel::ParaWorld::size ( ) const
inline

Number of processes in the domain (1 in serial builds).

Here is the caller graph for this function:

◆ tag()

const std::string & Parallel::ParaWorld::tag ( ) const
inline

Domain tag string.

Here is the caller graph for this function:

◆ valid()

bool Parallel::ParaWorld::valid ( ) const

True if this process belongs to the domain.

In MPI builds this means comm() != MPI_COMM_NULL; in serial builds a default/empty domain is invalid, everything else valid.

Here is the caller graph for this function:

Member Data Documentation

◆ comm_

MPI_Comm Parallel::ParaWorld::comm_
private

wrapped communicator (never owned/freed here)

◆ rank_

int Parallel::ParaWorld::rank_
private

rank inside domain

◆ size_

int Parallel::ParaWorld::size_
private

number of processes in domain

◆ tag_

std::string Parallel::ParaWorld::tag_
private

domain tag


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