scope_profiler.mpi_launch
Detection of whether the process was launched by an MPI launcher.
Importing mpi4py.MPI calls MPI_Init, and any collective (bcast,
Barrier, …) issued afterwards costs something even on a single process.
A plain python script.py run should therefore never touch MPI at all, even
when mpi4py happens to be installed. This module answers the only question
that decides it: was this process started by mpirun/mpiexec/srun
(or an equivalent launcher)?
The answer is read from the environment the launcher sets up, so it is available before mpi4py is imported.
Attributes
| Name | Description |
|---|---|
LAUNCHER_ENV_VARS | No description. |
Functions
| Name | Description |
|---|---|
get_comm | Return MPI.COMM_WORLD, or None when MPI must not be used. |
launched_under_mpi | Whether this process was started by an MPI launcher. |
LAUNCHER_ENV_VARSattributemodule attribute#
LAUNCHER_ENV_VARS = (
'OMPI_COMM_WORLD_RANK',
'PMI_RANK',
'PMIX_RANK',
'MV2_COMM_WORLD_RANK',
'MPI_LOCALRANKID',
'ALPS_APP_PE',
'PALS_RANKID'
)get_commfunction#
def get_comm()Return MPI.COMM_WORLD, or None when MPI must not be used.
The decision is made entirely by :func:launched_under_mpi, so a plain
python script.py run never touches MPI. Override it with the
SCOPE_PROFILER_MPI environment variable when a launcher this module
does not recognize is in play.
Returns
mpi4py.MPI.Intracomm or None The world communicator, or None if this is not an MPI run or mpi4py is unavailable.
launched_under_mpifunction#
def launched_under_mpi() -> boolWhether this process was started by an MPI launcher.
Returns
bool
True if a launcher’s per-rank environment variable is present, or if
the application itself already initialized MPI (in which case using
the communicator is free). SCOPE_PROFILER_MPI=0/1 overrides
the detection.