ParaMonte MATLAB 3.0.0
Parallel Monte Carlo and Machine Learning Library
See the latest version documentation.
ompi.m
Go to the documentation of this file.
1%> \brief
2%> Return the MPI image count and the current image ID (e.g., MPI rank + 1)
3%> if the application has been launched via the OpenMPI ``mpiexec`` launcher.<br>
4%>
5%> \details
6%> This function attempts to detect the invocation of the current MATLAB
7%> session via an OpenMPI ``mpiexec`` binary MPI launcher instance.<br>
8%> The runtime detection is achieved by checking for runtime environment
9%> variables that the OpenMPI ``mpiexec`` binary executable defines upon launch.<br>
10%>
11%> Specifically, OpenMPI provides the following
12%> environment variables that are defined on every MPI process:<br>
13%> <ol>
14%> <li> ``OMPI_COMM_WORLD_SIZE`` : The number of processes in this process ``MPI_COMM_WORLD``.<br>
15%> <li> ``OMPI_COMM_WORLD_RANK`` : The MPI rank of this process in ``MPI_COMM_WORLD``.<br>
16%> <li> ``OMPI_COMM_WORLD_LOCAL_SIZE`` : The number of ranks from this job that are running on this node.<br>
17%> <li> ``OMPI_COMM_WORLD_LOCAL_RANK`` : The relative rank of this process on this node within its job.<br>
18%> For example, if four processes in a job share a node,
19%> they will each be given a local rank ranging from ``0`` to ``3``.
20%> <li> ``OMPI_UNIVERSE_SIZE`` : The number of process slots allocated to this job.<br>
21%> Note that this may be different than the number of processes in the job.<br>
22%> <li> ``OMPI_COMM_WORLD_NODE_RANK`` : The relative rank of this process on this node looking across all jobs.<br>
23%> </ol>
24%>
25%> \return
26%> ``nproc`` : The output scalar MATLAB non-negative whole number containing
27%> the number of MPI images in the current invocation of the
28%> OpenMPI ``mpiexec`` binary MPI launcher.<br>
29%> An output value of ``0`` implies the algorithm failed to detect
30%> a ParaMonte-compatible OpenMPI library or failed to infer the image count.<br>
31%> ``rankp1`` : The output scalar MATLAB non-negative whole number containing
32%> the image ID (e.g., MPI rank + 1) of the current MPI image in
33%> the current invocation of the OpenMPI ``mpiexec`` binary MPI launcher.<br>
34%> An output value of ``0`` implies the algorithm failed to detect
35%> a ParaMonte-compatible MPI library or failed to infer the image count.<br>
36%> Note that the image ID always starts at ``1``, unlike the MPI rank.<br>
37%> The argument ``rankp1`` stands for ``rank + 1``.<br>
38%> An output value of ``0`` implies the algorithm failed to detect
39%> a ParaMonte-compatible OpenMPI library or failed to infer the image count.<br>
40%>
41%> \interface{ompi}
42%> \code{.m}
43%>
44%> [nproc, rankp1] = pm.lib.mpi.runtime.ompi()
45%>
46%> \endcode
47%>
48%> \see
49%> [pm.lib.mpi.runtime.mmpi()](@ref mmpi)<br>
50%> [pm.lib.mpi.runtime.impi()](@ref impi)<br>
51%> [pm.lib.mpi.runtime.ompi()](@ref ompi)<br>
52%> [pm.lib.mpi.runtime.hydra()](@ref hydra)<br>
53%> [pm.lib.mpi.runtime.nproc()](@ref nproc)<br>
54%> [pm.lib.mpi.runtime.rankp1()](@ref rankp1)<br>
55%> [pm.lib.mpi.runtime.isimpi()](@ref isimpi)<br>
56%> [pm.lib.mpi.runtime.detect()](@ref detect)<br>
57%>
58%> \example{ompi}
59%> \include{lineno} example/lib/mpi/runtime/ompi/main.m
60%> \output{ompi}
61%> \include{lineno} example/lib/mpi/runtime/ompi/main.out.m
62%>
63%> \final{ompi}
64%>
65%> \author
66%> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
67%> \AmirShahmoradi, 12:10 AM Wednesday, November 13, 2024, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
68function [nproc, rankp1] = ompi()
69
70 nproc = getenv("OMPI_COMM_WORLD_SIZE");
71 if ~isempty(nproc)
72 nproc = str2double(nproc);
73 else
74 nproc = 0;
75 end
76
77 rankp1 = getenv("OMPI_COMM_WORLD_RANK");
78 if ~isempty(rankp1)
79 rankp1 = str2double(rankp1) + 1;
80 else
81 rankp1 = 0;
82 end
83
84end
function detect(in vendor)
Return the MPI image count and current image ID (e.g., MPI rank + 1) and the MPI library name as it a...
function hydra()
Return the MPI image count and the current image ID (e.g., MPI rank + 1) if the application has been ...
function impi()
Return the MPI image count and the current image ID (e.g., MPI rank + 1) if the application has been ...
function isimpi()
Return true if and only if the application has been invoked via an Intel MPI mpiexec launcher,...
function lib()
Return a scalar MATLAB string containing the path to the lib directory of the ParaMonte library packa...
function mmpi()
Return the MPI image count and the current image ID (e.g., MPI rank + 1) if the application has been ...
function nproc(in vendor)
Return the runtime number of MPI processes with which the mpiexec launcher may have been invoked.
function ompi()
Return the MPI image count and the current image ID (e.g., MPI rank + 1) if the application has been ...
function rankp1(in vendor)
Return the ID (MPI rank + 1) of the current MPI image (process), starting from the number one.