ParaMonte MATLAB 3.0.0
Parallel Monte Carlo and Machine Learning Library
See the latest version documentation.
impi.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 Intel MPI ``mpiexec`` launcher.<br>
4%>
5%> \details
6%> This function attempts to detect the invocation of the current MATLAB
7%> session via an Intel MPI ``mpiexec`` binary MPI launcher instance.<br>
8%> The runtime detection is achieved by checking for runtime environment
9%> variables that the Intel MPI ``mpiexec`` binary executable defines upon launch.<br>
10%>
11%> Specifically, Intel MPI provides a long informal list of
12%> environment variables that are defined on every MPI process.<br>
13%> These variables may not be defined on all platforms.<br>
14%> Some are only defined at runtime, while others are defined at compile-time.<br>
15%>
16%> <ol>
17%> <li> On **Unix systems**, the best approach to investigate the Intel-specific runtime variables
18%> is to launch the Intel ``mpiexec`` binary executable with the ``printenv`` Unix command.<br>
19%> \code{.sh}
20%> mpiexec -np 1 printenv
21%> \endcode
22%> To see the compile-time variables and compare them with the runtime list from the above, try:<br>
23%> \code{.sh}
24%> printenv
25%> \endcode
26%> <li> On **Windows systems**, the best approach to investigate the Intel-specific runtime variables
27%> is to launch the Intel ``mpiexec`` binary executable with the ``set`` Windows batch command.<br>
28%> \code{.bat}
29%> mpiexec -localonly -n 1 cmd /k set
30%> \endcode
31%> To see the compile-time variables and compare them with the runtime list from the above, try:<br>
32%> \code{.bat}
33%> set
34%> \endcode
35%> </ol>
36%>
37%> Note that all Intel-MPI-specific environment variables are prefixed with ``I_MPI_``.<br>
38%> The most persistent environment variables for Intel ``mpiexec`` binary appear to be the following:<br>
39%>
40%> <ol>
41%> <li> ``I_MPI_INFO_STATE`` : The status code for the Intel MPI runtime (e.g., ``0``).<br>
42%> <li> ``I_MPI_INFO_BRAND`` : The processor brand (e.g., ``12th Gen Intel(R) Core(TM) i9-12950HX``).<br>
43%> <li> ``PMI_RANK`` : The rank of the current process in the current MPI communication world.<br>
44%> This environment variable is common to all Hydra-based MPI libraries, such as MPICH and Intel MPI libraries.<br>
45%> <li> ``PMI_SIZE`` : The size (i.e., number of images/processes) of the current MPI communication world.<br>
46%> This environment variable is common to all Hydra-based MPI libraries, such as MPICH and Intel MPI libraries.<br>
47%> <li> ``MPI_LOCALRANKID`` : The **local** rank of the current process relative to the local host.<br>
48%> This environment variable is common to all Hydra-based MPI libraries, such as MPICH and Intel MPI libraries.<br>
49%> <li> ``MPI_LOCALNRANKS`` : The size (i.e., number of images/processes) of the current MPI communication on the local host.<br>
50%> This environment variable is common to all Hydra-based MPI libraries, such as MPICH and Intel MPI libraries.<br>
51%> </ol>
52%>
53%> Therefore, this function first attempts to detect the Hydra process manager.<br>
54%> If identified, the function will then attempt to identify the Intel ``mpiexec`` runtime variables.<br>
55%>
56%> \return
57%> ``nproc`` : The output scalar MATLAB non-negative whole number containing
58%> the number of MPI images in the current invocation of the
59%> Intel MPI ``mpiexec`` binary MPI launcher.<br>
60%> An output value of ``0`` implies the algorithm failed to detect
61%> a ParaMonte-compatible Intel MPI library or failed to infer the image count.<br>
62%> ``rankp1`` : The output scalar MATLAB non-negative whole number containing
63%> the image ID (e.g., MPI rank + 1) of the current MPI image in
64%> the current invocation of the Intel MPI ``mpiexec`` binary MPI launcher.<br>
65%> An output value of ``0`` implies the algorithm failed to detect
66%> a ParaMonte-compatible MPI library or failed to infer the image count.<br>
67%> Note that the image ID always starts at ``1``, unlike the MPI rank.<br>
68%> The argument ``rankp1`` stands for ``rank + 1``.<br>
69%> An output value of ``0`` implies the algorithm failed to detect
70%> a ParaMonte-compatible Intel MPI library or failed to infer the image count.<br>
71%>
72%> \interface{impi}
73%> \code{.m}
74%>
75%> [nproc, rankp1] = pm.lib.mpi.runtime.impi()
76%>
77%> \endcode
78%>
79%> \see
80%> [pm.lib.mpi.runtime.mmpi()](@ref mmpi)<br>
81%> [pm.lib.mpi.runtime.impi()](@ref impi)<br>
82%> [pm.lib.mpi.runtime.ompi()](@ref ompi)<br>
83%> [pm.lib.mpi.runtime.hydra()](@ref hydra)<br>
84%> [pm.lib.mpi.runtime.nproc()](@ref nproc)<br>
85%> [pm.lib.mpi.runtime.rankp1()](@ref rankp1)<br>
86%> [pm.lib.mpi.runtime.isimpi()](@ref isimpi)<br>
87%> [pm.lib.mpi.runtime.detect()](@ref detect)<br>
88%>
89%> \example{impi}
90%> \include{lineno} example/lib/mpi/runtime/impi/main.m
91%> \output{impi}
92%> \include{lineno} example/lib/mpi/runtime/impi/main.out.m
93%>
94%> \final{impi}
95%>
96%> \author
97%> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
98%> \AmirShahmoradi, 12:10 AM Wednesday, November 13, 2024, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
99function [nproc, rankp1] = impi()
100
101 %%%%
102 %%%% Ensure the consistency of environment variables and Intel identity of ``mpiexec``.
103 %%%%
104
105 if ~pm.lib.mpi.runtime.isimpi()% || nproc == 0 || rankp1 == 0
106 rankp1 = 0;
107 nproc = 0;
108 else
109 [nproc, rankp1] = pm.lib.mpi.runtime.hydra();
110 end
111
112end
function list()
Return a list of MATLAB strings containing the names of OS platforms supported by the ParaMonte MATLA...
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.