ParaMonte MATLAB 3.0.0
Parallel Monte Carlo and Machine Learning Library
See the latest version documentation.
mmpi.m File Reference

Go to the source code of this file.

Functions

function mmpi ()
 Return the MPI image count and the current image ID (e.g., MPI rank + 1) if the application has been launched via the MPICH MPI mpiexec launcher.
More...
 

Function Documentation

◆ mmpi()

function mmpi ( )

Return the MPI image count and the current image ID (e.g., MPI rank + 1) if the application has been launched via the MPICH MPI mpiexec launcher.

This function attempts to detect the invocation of the current MATLAB session via an MPICH MPI mpiexec binary MPI launcher instance.
The runtime detection is achieved by checking for runtime environment variables that the MPICH MPI mpiexec binary executable defines upon launch.

Specifically, MPICH MPI provides a long informal list of environment variables that are defined on every MPI process.
These variables may not be defined on all platforms.
Some are only defined at runtime, while others are defined at compile-time.

  1. On Unix systems, the best approach to investigate the MPICH-specific runtime variables is to launch the MPICH mpiexec binary executable with the printenv Unix command.
    ```bash mpiexec -np 1 printenv ``` To see the compile-time variables and compare them with the runtime list from the above, try:
    ```bash printenv ```
  2. On Windows systems, the best approach to investigate the MPICH-specific runtime variables is to launch the MPICH mpiexec binary executable with the set Windows batch command.
    ```batch mpiexec -localonly -n 1 cmd /k set ``` To see the compile-time variables and compare them with the runtime list from the above, try:
    ```batch set ```

The most persistent environment variables for MPICH mpiexec binary appear to be the following:

  1. PMI_RANK : The rank of the current process in the current MPI communication world.
    This environment variable is common to all Hydra-based MPI libraries, such as MPICH and MPICH MPI libraries.
  2. PMI_SIZE : The size (i.e., number of images/processes) of the current MPI communication world.
    This environment variable is common to all Hydra-based MPI libraries, such as MPICH and MPICH MPI libraries.
  3. MPI_LOCALRANKID : The local rank of the current process relative to the local host.
    This environment variable is common to all Hydra-based MPI libraries, such as MPICH and MPICH MPI libraries.
  4. MPI_LOCALNRANKS : The size (i.e., number of images/processes) of the current MPI communication on the local host.
    This environment variable is common to all Hydra-based MPI libraries, such as MPICH and MPICH MPI libraries.

Therefore, this function first attempts to detect the Hydra process manager.
If identified, the function will then attempt to identify the MPICH mpiexec runtime variables.

Returns
nproc : The output scalar MATLAB non-negative whole number containing the number of MPI images in the current invocation of the MPICH MPI mpiexec binary MPI launcher.
An output value of 0 implies the algorithm failed to detect a ParaMonte-compatible MPICH MPI library or failed to infer the image count.
rankp1 : The output scalar MATLAB non-negative whole number containing the image ID (e.g., MPI rank + 1) of the current MPI image in the current invocation of the MPICH MPI mpiexec binary MPI launcher.
An output value of 0 implies the algorithm failed to detect a ParaMonte-compatible MPI library or failed to infer the image count.
Note that the image ID always starts at 1, unlike the MPI rank.
The argument rankp1 stands for rank + 1.
An output value of 0 implies the algorithm failed to detect a ParaMonte-compatible MPICH MPI library or failed to infer the image count.


Possible calling interfaces

[nproc, rankp1] = pm.lib.mpi.runtime.mmpi()
function nproc(in vendor)
Return the runtime number of MPI processes with which the mpiexec launcher may have been invoked.
function rankp1(in vendor)
Return the ID (MPI rank + 1) of the current MPI image (process), starting from the number one.
See also
pm.lib.mpi.runtime.mmpi()
pm.lib.mpi.runtime.impi()
pm.lib.mpi.runtime.ompi()
pm.lib.mpi.runtime.hydra()
pm.lib.mpi.runtime.nproc()
pm.lib.mpi.runtime.rankp1()
pm.lib.mpi.runtime.isimpi()
pm.lib.mpi.runtime.detect()


Example usage

1cd(fileparts(mfilename('fullpath'))); % Change working directory to source code directory.
2addpath('../../../../../'); % Add the ParaMonte library root directory to the search path.
3
4disp('[nproc, rankp1] = pm.lib.mpi.runtime.mmpi()')
5 [nproc, rankp1] = pm.lib.mpi.runtime.mmpi()
6disp("")
function root()
Return a scalar MATLAB string containing the root directory of the ParaMonte library package.

Example output
1[nproc, rankp1] = pm.lib.mpi.runtime.mmpi()
2nproc =
3 0
4rankp1 =
5 0


Final Remarks


If you believe this algorithm or its documentation can be improved, we appreciate your contribution and help to edit this page's documentation and source file on GitHub.
For details on the naming abbreviations, see this page.
For details on the naming conventions, see this page.
This software is distributed under the MIT license with additional terms outlined below.

  1. If you use any parts or concepts from this library to any extent, please acknowledge the usage by citing the relevant publications of the ParaMonte library.
  2. If you regenerate any parts/ideas from this library in a programming environment other than those currently supported by this ParaMonte library (i.e., other than C, C++, Fortran, MATLAB, Python, R), please also ask the end users to cite this original ParaMonte library.

This software is available to the public under a highly permissive license.
Help us justify its continued development and maintenance by acknowledging its benefit to society, distributing it, and contributing to it.

Author:
Fatemeh Bagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.
Amir Shahmoradi, 12:10 AM Wednesday, November 13, 2024, NASA Goddard Space Flight Center (GSFC), Washington, D.C.