specfem::MPI¶
specfem::MPI is a static class that provides an interface to MPI
functionality within SPECFEM++. It manages MPI initialization and finalization,
and provides static access to the rank and size of the MPI communicator.
-
class MPI¶
Static MPI wrapper for SPECFEM++.
This class provides a static interface to MPI functionality, eliminating the need to pass MPI pointers throughout the codebase.
Key features:
Static rank and size members accessible globally
Context-managed lifecycle (only Context can initialize/finalize)
Safety checks to prevent use outside Context scope
Minimal API focused on essential MPI operations
Usage:
// After Context is initialized int my_rank = specfem::MPI::get_rank(); int world_size = specfem::MPI::get_size(); specfem::MPI::sync();
Note
This class cannot be instantiated. All members are static.
Note
Only specfem::program::Context can initialize/finalize this class.
Public Static Functions
-
static inline void sync()¶
Synchronize all MPI processes (MPI_Barrier)
- Throws:
Exits – with error code 1 if called outside Context scope
-
static inline void sync_all()¶
Synchronize all MPI processes (alias for sync())
- Throws:
Exits – with error code 1 if called outside Context scope
-
static inline int get_rank()¶
Get MPI rank.
- Throws:
Exits – with error code 1 if called outside Context scope
- Returns:
int Current MPI rank
-
static inline int get_size()¶
Get MPI world size.
- Throws:
Exits – with error code 1 if called outside Context scope
- Returns:
int Total number of MPI processes
-
static inline bool main_proc()¶
Check if current process is the main process (rank 0)
- Throws:
Exits – with error code 1 if called outside Context scope
- Returns:
bool True if rank == 0
-
static inline int reduce(int lvalue, specfem::reduce_type reduce_op)¶
MPI reduce operation.
- Parameters:
lvalue – Local value to reduce
reduce_op – Reduction operation (specfem::sum, specfem::min, specfem::max)
- Throws:
Exits – with error code 1 if called outside Context scope
- Returns:
Reduced value (only valid on root process)
-
static inline float reduce(float lvalue, specfem::reduce_type reduce_op)¶
MPI reduce operation for float.
- Parameters:
lvalue – Local value to reduce
reduce_op – Reduction operation
- Throws:
Exits – with error code 1 if called outside Context scope
- Returns:
Reduced value (only valid on root process)
-
static inline double reduce(double lvalue, specfem::reduce_type reduce_op)¶
MPI reduce operation for double.
- Parameters:
lvalue – Local value to reduce
reduce_op – Reduction operation
- Throws:
Exits – with error code 1 if called outside Context scope
- Returns:
Reduced value (only valid on root process)