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

Go to the source code of this file.

Functions

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 appears in the ParaMonte library path and the corresponding MPI-parallel ParaMonte library path .
More...
 

Function Documentation

◆ detect()

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 appears in the ParaMonte library path and the corresponding MPI-parallel ParaMonte library path .

This function attempts to detect the invocation of the current MATLAB session via checking the runtime behavior of the mpiexec binary MPI launcher instance.

Output values interpretation

  1. If the output mpiname is set to an empty string "", meaning that strcmp(mpiname, "") yields true, then the algorithm has failed, implying that the current application is likely to have been launched by via an mpiexec binary whose MPI library is supported by the ParaMonte library.
  2. If the output mpiname is set to an non-empty string, which must be the name of an MPI library vendor used within ParaMonte,
    then an instance of the corresponding MPI library likely exists on the current system and its mpiexec binary has been used to launch the current application in parallel.
    If so,
    1. A value of 0 for either of the output values nproc and rankp1 implies the algorithm failed to infer the corresponding parameters.
    2. A non-zero positive value for either or both of the output values nproc and rankp1 implies that the mpiexec MPI launcher binary of the corresponding MPI library might have been used to launch MATLAB and its might have been used to launch MATLAB.
      1. A non-zero positive value other than 1 for the output nproc guarantees that the mpiexec launcher has been used to launch MATLAB with the specified nproc number of MPI images (processes).
Parameters
[in]vendor: The input scalar MATLAB string, containing the MPI library vendor supported by the ParaMonte library.
Possible values are:
  1. OpenMPI, representing the OpenMPI library.
  2. MPICH, representing the MPICH MPI library.
  3. Intel, representing the Intel MPI library.
  4. any, representing any available MPI library.
or any other informal name returned by the ParaMonte MATLAB function pm.lib.mpi.name().
Note that all values are case-insensitive.
(**optional, default = "any".)
Returns
mpiname : The output scalar MATLAB string containing the MPI library name as it appears in the ParaMonte library path.
An output value of "" implies the algorithm failed to detect a ParaMonte-compatible MPI library invoked or installed on the system.
nproc : The output scalar MATLAB non-negative whole number containing the number of MPI images in the current invocation of the 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.
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 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.


Possible calling interfaces

[mpiname, nproc, rankp1] = pm.lib.mpi.runtime.detect();
[mpiname, nproc, rankp1] = pm.lib.mpi.runtime.detect(vendor);
function vendor(in name)
Return the MPI library vendor name from the input MPI name based on the internal ParaMonte shared lib...
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.
Warning
This routine must be called before the MPI library is finalized by any other application.
Example applications that finalize the MPI library upon return includes the ParaMonte MPI-parallel samplers.
However, each application offers an option to prevent the default finalization of the MPI library.
For this reason, the results of this function are saved within the function for subsequent usage after the first call.
Note
This function internally uses a persistent MATLAB struct to store the results for the default input value for vendor to expedite future inquiries using this function.
Specifying an input argument value will always


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('[mpiname, nproc, rankp1] = pm.lib.mpi.runtime.detect()')
5 [mpiname, nproc, rankp1] = pm.lib.mpi.runtime.detect()
6disp("")
7
8disp('[mpiname, nproc, rankp1] = pm.lib.mpi.runtime.detect("impi")')
9 [mpiname, nproc, rankp1] = pm.lib.mpi.runtime.detect("impi")
10disp("")
11
12disp('[mpiname, nproc, rankp1] = pm.lib.mpi.runtime.detect("INTEL")')
13 [mpiname, nproc, rankp1] = pm.lib.mpi.runtime.detect("INTEL")
14disp("")
15
16disp('[mpiname, nproc, rankp1] = pm.lib.mpi.runtime.detect("intel")')
17 [mpiname, nproc, rankp1] = pm.lib.mpi.runtime.detect("intel")
18disp("")
19
20disp('[mpiname, nproc, rankp1] = pm.lib.mpi.runtime.detect("ompi")')
21 [mpiname, nproc, rankp1] = pm.lib.mpi.runtime.detect("ompi")
22disp("")
23
24disp('[mpiname, nproc, rankp1] = pm.lib.mpi.runtime.detect("openmpi")')
25 [mpiname, nproc, rankp1] = pm.lib.mpi.runtime.detect("openmpi")
26disp("")
27
28disp('[mpiname, nproc, rankp1] = pm.lib.mpi.runtime.detect("open-mpi")')
29 [mpiname, nproc, rankp1] = pm.lib.mpi.runtime.detect("open-mpi")
30disp("")
31
32disp('[mpiname, nproc, rankp1] = pm.lib.mpi.runtime.detect("mpich")')
33 [mpiname, nproc, rankp1] = pm.lib.mpi.runtime.detect("mpich")
34disp("")
35
36disp('[mpiname, nproc, rankp1] = pm.lib.mpi.runtime.detect("mpi")')
37 [mpiname, nproc, rankp1] = pm.lib.mpi.runtime.detect("mpi")
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 impi()
Return the MPI image count and the current image ID (e.g., MPI rank + 1) if the application has been ...
function lib()
Return a scalar MATLAB string containing the path to the lib directory of the ParaMonte library packa...
function ompi()
Return the MPI image count and the current image ID (e.g., MPI rank + 1) if the application has been ...
function root()
Return a scalar MATLAB string containing the root directory of the ParaMonte library package.

Example output
1[mpiname, nproc, rankp1] = pm.lib.mpi.runtime.detect()
2mpiname =
3 ""
4nproc =
5 0
6rankp1 =
7 0
8[mpiname, nproc, rankp1] = pm.lib.mpi.runtime.detect("impi")
9mpiname =
10 ""
11nproc =
12 0
13rankp1 =
14 0
15[mpiname, nproc, rankp1] = pm.lib.mpi.runtime.detect("INTEL")
16mpiname =
17 ""
18nproc =
19 0
20rankp1 =
21 0
22[mpiname, nproc, rankp1] = pm.lib.mpi.runtime.detect("intel")
23mpiname =
24 ""
25nproc =
26 0
27rankp1 =
28 0
29[mpiname, nproc, rankp1] = pm.lib.mpi.runtime.detect("ompi")
30mpiname =
31 ""
32nproc =
33 0
34rankp1 =
35 0
36[mpiname, nproc, rankp1] = pm.lib.mpi.runtime.detect("openmpi")
37mpiname =
38 ""
39nproc =
40 0
41rankp1 =
42 0
43[mpiname, nproc, rankp1] = pm.lib.mpi.runtime.detect("open-mpi")
44mpiname =
45 ""
46nproc =
47 0
48rankp1 =
49 0
50[mpiname, nproc, rankp1] = pm.lib.mpi.runtime.detect("mpich")
51mpiname =
52 ""
53nproc =
54 0
55rankp1 =
56 0
57[mpiname, nproc, rankp1] = pm.lib.mpi.runtime.detect("mpi")
58mpiname =
59 ""
60nproc =
61 0
62rankp1 =
63 0
Todo:
High Priority: The internals of this function can be improved for better efficiency and less redundancy.


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:
Amir Shahmoradi, 2:27 AM Monday, November 11, 2024, Dallas, TX