|
preCICE v3.3.0
|
Utility class for managing MPI operations. More...
#include <Parallel.hpp>
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 safeguard against reinitializing MPI, which is forbidden. | |
| static InitializationState | _initState = Parallel::InitializationState::Uninitialized |
Utility class for managing MPI operations.
Definition at line 24 of file Parallel.hpp.
Definition at line 35 of file Parallel.hpp.
Definition at line 27 of file Parallel.hpp.
|
strongprivate |
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.
|
static |
Returns an owning pointer to the current CommState.
END CommState.
Definition at line 147 of file Parallel.cpp.
|
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.
Definition at line 230 of file Parallel.cpp.
|
static |
Unconditionally finalizes MPI environment.
Definition at line 261 of file Parallel.cpp.
|
static |
Returns the global process rank or 0 used in assertions.
Definition at line 299 of file Parallel.cpp.
|
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.
| [in] | userProvided | an optional user-provided Communicator |
Definition at line 190 of file Parallel.cpp.
|
static |
Unconditionally initializes the MPI environment.
Alters the _currentState, which indicates a testing session.
| [in] | argc | Parameter count |
| [in] | argv | Parameter values, is passed to MPI_Init |
Definition at line 249 of file Parallel.cpp.
|
static |
Return true if MPI is initialized.
Definition at line 179 of file Parallel.cpp.
|
static |
Sets the current state to its parent
@postcondition current() == old current()->parent
Definition at line 290 of file Parallel.cpp.
|
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.
|
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.
|
static |
Resets managed MPI
This resets _mpiInitializedByPrecice and _isInitialized to false
Definition at line 161 of file Parallel.cpp.
|
static |
Splits and creates a local MPI communicator according to groupName.
Updates the current CommState of Parallel.
| [in] | groupName | MPI group in which the calling process will be put in |
Definition at line 272 of file Parallel.cpp.
|
staticprivate |
Definition at line 220 of file Parallel.hpp.
|
staticprivate |
Definition at line 234 of file Parallel.hpp.
|
staticprivate |
Definition at line 218 of file Parallel.hpp.
|
staticprivate |
Flag to safeguard against reinitializing MPI, which is forbidden.
Definition at line 223 of file Parallel.hpp.