ParaMonte MATLAB 3.0.0
Parallel Monte Carlo and Machine Learning Library
See the latest version documentation.
nproc.m
Go to the documentation of this file.
1%> \brief
2%> Return the runtime number of MPI cores
3%> with which the `mpiexec` launcher may have been invoked.<br>
4%>
5%> \details
6%> Otherwise, return `1` if no use of `mpiexec` launcher is detected
7%> or it is invoked with only ``1`` MPI process.<br>
8%>
9%> An output value of ``1`` can be used as an indication of
10%> the ``mpiexec`` launcher in launching the ParaMonte library.<br>
11%>
12%> \warning
13%> This routine can lead to a full MATLAB session crash if the
14%> required MPI library dependencies are not detected on the system.<br>
15%> This issue severely limits the utility of this routine.<br>
16%>
17%> \param[in] config : The input scalar (or array of) MATLAB string(s)
18%> containing the ParaMonte-preferred MPI library vendor/name
19%> or other configurations as used in naming the ParaMonte MATLAB shared libraries.<br>
20%> This argument is passed directly to the corresponding argument of [pm.lib.path.mexdir](@ref mexdir).<br>
21%> Possible values of outmost interest to MPI applications are:<br>
22%> <ol>
23%> <li> the value ``"Intel"`` or ``"impi"``, representing the Intel MPI library.<br>
24%> <li> the value ``"MPICH"`` or ``"mmpi"``, representing the MPICH MPI library.<br>
25%> <li> the value ``"OpenMPI"`` or ``"ompi"``, representing the OpenMPI library.<br>
26%> </ol>
27%> Note that **all values are case-insensitive**.<br>
28%> (**optional**. If missing, all possibilities are considered and the largest inferred ``count`` is returned.)
29%>
30%> \return
31%> ``count`` : The output MATLAB scalar integer containing the number of
32%> MPI processes launched by the ``mpiexec`` command or ``1``
33%> if no ``mpiexec`` invocation has occurred or the routine
34%> fails to load any MPI-enabled ParaMonte library.<br>
35%>
36%> \interface{nproc}
37%> \code{.m}
38%>
39%> count = pm.lib.mpi.nproc()
40%> count = pm.lib.mpi.nproc([])
41%> count = pm.lib.mpi.nproc(config)
42%>
43%> \endcode
44%>
45%> \final{nproc}
46%>
47%> \author
48%> \JoshuaOsborne, May 21 2024, 7:14 PM, University of Texas at Arlington<br>
49%> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
50%> \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute for Computational Engineering and Sciences (ICES), UT Austin<br>
51function count = nproc(config)
52 if nargin < 1
53 configList = [];
54 else
55 configList = string(config);
56 end
57 if pm.array.len(configList) == 0
58 configList = pm.lib.mpi.choices();
59 end
60 count = 1;
61 mexname = "pm_parallelism";
62 for iname = 1 : length(configList)
63 mexdirs = pm.lib.path.mexdir(mexname, configList(iname));
64 for ipath = 1 : length(mexdirs)
65 %mexdirs{ipath}
66 matpath = path;
67 pm.lib.path.clean();
68 path(matpath, mexdirs{ipath});
69 %persistent mh;
70 %if ~isa(mh, 'matlab.mex.MexHost') || ~isvalid(mh)
71 % mh = mexhost;
72 %end
73 %temp = feval(mh, mexname, 'getImageCountMPI');
74 %count = max(count, temp);
75 mexcall = string(mexname + "('getImageCountMPI');");
76 try
77 temp = eval(mexcall);
78 count = max(count, temp);
79 catch
80 continue;
81 end
82 path(matpath);
83 end
84 end
85end
function name(in vendor)
Return the MPI library name as used in naming the ParaMonte MATLAB shared libraries.
function mexdir(in mexname, in config)
Return the vector of MATLAB strings containing the directory path(s) containing the specified ParaMon...
function nproc(in config)
Return the runtime number of MPI cores with which the mpiexec launcher may have been invoked.
function vendor(in path)
Return the a MATLAB string containing the MPI library vendor name corresponding to the input mpiexec ...
function which(in vendor)
Return the a MATLAB string containing the path to the first mpiexec executable binary found in system...