preCICE v3.1.2
Loading...
Searching...
No Matches
Classes | Public Types | Private Types | Static Private Member Functions | Static Private Attributes | List of all members
precice::utils::Parallel Class Reference

Utility class for managing MPI operations. More...

#include <Parallel.hpp>

Collaboration diagram for precice::utils::Parallel:
[legend]

Classes

struct  CommState
 

Public Types

using Communicator = MPI_Comm
 
using CommStatePtr = std::shared_ptr<CommState>
 

Static Public Member Functions

Initialization and Finalization
static bool isMPIInitialized ()
 Return true if MPI is initialized.
 
static void initializeOrDetectMPI (std::optional< Communicator > userProvided=std::nullopt)
 
static void finalizeOrCleanupMPI ()
 Finalized a managed MPI environment or cleans up after an non-managed session.
 
static void initializeTestingMPI (int *argc, char ***argv)
 
static void finalizeTestingMPI ()
 Unconditionally finalizes MPI environment.
 
State-altering Functions
static void splitCommunicator (std::optional< int > group=std::nullopt)
 Splits and creates a local MPI communicator according to groupName.
 
static void resetCommState ()
 
static void resetManagedMPI ()
 
static void popState ()
 
Misc
static Rank getProcessRank ()
 
static CommStatePtr current ()
 Returns an owning pointer to the current CommState.
 

Private Types

enum struct  InitializationState {
  Uninitialized , Provided , Managed , Unmanaged ,
  Testing
}
 Kind of initialization that took place. More...
 

Static Private Member Functions

static void pushState (CommStatePtr newState)
 

Static Private Attributes

static logging::Logger _log
 
static CommStatePtr _currentState = nullptr
 
static bool _mpiInitializedByPrecice = false
 Flag to saveguard against reinitializing MPI, which is forbidden.
 
static InitializationState _initState = Parallel::InitializationState::Uninitialized
 

Detailed Description

Utility class for managing MPI operations.

Definition at line 24 of file Parallel.hpp.

Member Typedef Documentation

◆ CommStatePtr

Definition at line 35 of file Parallel.hpp.

◆ Communicator

Definition at line 27 of file Parallel.hpp.

Member Enumeration Documentation

◆ InitializationState

Kind of initialization that took place.

Enumerator
Uninitialized 
Provided 

Not initialized.

Managed 

Communicator was provided by the user.

Unmanaged 

preCICE manages the lifetime of the MPI environment

Testing 

preCICE was initialized in an existing MPI environment

preCICE was initialized in a testing environment initialized with initializeTestingMPI()

Definition at line 226 of file Parallel.hpp.

Member Function Documentation

◆ current()

Parallel::CommStatePtr precice::utils::Parallel::current ( )
static

Returns an owning pointer to the current CommState.

END CommState.

Definition at line 147 of file Parallel.cpp.

Here is the call graph for this function:

◆ finalizeOrCleanupMPI()

void precice::utils::Parallel::finalizeOrCleanupMPI ( )
static

Finalized a managed MPI environment or cleans up after an non-managed session.

To initialize the managed MPI call initializeOrDetectMPI(). This finalizes MPI only if the preCICE initialized the MPI session itself.

See also
initializeOrDetectMPI()

Definition at line 230 of file Parallel.cpp.

Here is the call graph for this function:

◆ finalizeTestingMPI()

void precice::utils::Parallel::finalizeTestingMPI ( )
static

Unconditionally finalizes MPI environment.

Definition at line 261 of file Parallel.cpp.

Here is the call graph for this function:

◆ getProcessRank()

int precice::utils::Parallel::getProcessRank ( )
static

Returns the global process rank or 0 used in assertions.

Definition at line 299 of file Parallel.cpp.

Here is the call graph for this function:

◆ initializeOrDetectMPI()

void precice::utils::Parallel::initializeOrDetectMPI ( std::optional< Communicator > userProvided = std::nullopt)
static

Initializes or detects an existing MPI environment

If a custom MPI Communicator is provided via userProvided then this registers a user-provided MPI session.

If MPI has already been initialized, then preCICE uses MPI_COMM_WORLD as communicator and registers a unmanaged MPI session. If _currentState isn't nullptr, then this signals launch inside a test.

If MPI hasn't been initialized yet, then preCICE takes ownership. It initializes the environment and will later destroy it. As MPI forbids reinitialization, this prevents reconstruction.

Parameters
[in]userProvidedan optional user-provided Communicator
See also
finalizeOrCleanupMPI()

Definition at line 190 of file Parallel.cpp.

Here is the call graph for this function:

◆ initializeTestingMPI()

void precice::utils::Parallel::initializeTestingMPI ( int * argc,
char *** argv )
static

Unconditionally initializes the MPI environment.

Alters the _currentState, which indicates a testing session.

Parameters
[in]argcParameter count
[in]argvParameter values, is passed to MPI_Init

Definition at line 249 of file Parallel.cpp.

Here is the call graph for this function:

◆ isMPIInitialized()

bool precice::utils::Parallel::isMPIInitialized ( )
static

Return true if MPI is initialized.

Definition at line 179 of file Parallel.cpp.

Here is the call graph for this function:

◆ popState()

void precice::utils::Parallel::popState ( )
static

Sets the current state to its parent

@postcondition current() == old current()->parent

Definition at line 290 of file Parallel.cpp.

Here is the call graph for this function:

◆ pushState()

void precice::utils::Parallel::pushState ( CommStatePtr newState)
staticprivate

Pushes a new state on the state stack

Sets the parent of newState to the current state. Sets the current state to the newState.

@precondition newState->parent == nullptr @postcondition _currentState == newState @postcondition _currentState->parent == old _currentState

Definition at line 167 of file Parallel.cpp.

Here is the call graph for this function:

◆ resetCommState()

void precice::utils::Parallel::resetCommState ( )
static

Resets the commState to World

This resets the _currentState to CommState::world(). Unrequired Communicators will be automatically freed.

@postcondition cureent() == CommState::world()

Definition at line 156 of file Parallel.cpp.

Here is the call graph for this function:

◆ resetManagedMPI()

void precice::utils::Parallel::resetManagedMPI ( )
static

Resets managed MPI

This resets _mpiInitializedByPrecice and _isInitialized to false

Definition at line 161 of file Parallel.cpp.

◆ splitCommunicator()

void precice::utils::Parallel::splitCommunicator ( std::optional< int > group = std::nullopt)
static

Splits and creates a local MPI communicator according to groupName.

Updates the current CommState of Parallel.

Parameters
[in]groupNameMPI group in which the calling process will be put in

Definition at line 272 of file Parallel.cpp.

Here is the call graph for this function:

Member Data Documentation

◆ _currentState

Parallel::CommStatePtr precice::utils::Parallel::_currentState = nullptr
staticprivate

Definition at line 220 of file Parallel.hpp.

◆ _initState

Parallel::InitializationState precice::utils::Parallel::_initState = Parallel::InitializationState::Uninitialized
staticprivate

Definition at line 234 of file Parallel.hpp.

◆ _log

logging::Logger precice::utils::Parallel::_log
staticprivate

Definition at line 218 of file Parallel.hpp.

◆ _mpiInitializedByPrecice

bool precice::utils::Parallel::_mpiInitializedByPrecice = false
staticprivate

Flag to saveguard against reinitializing MPI, which is forbidden.

Definition at line 223 of file Parallel.hpp.


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