ParaMonte MATLAB 3.0.0
Parallel Monte Carlo and Machine Learning Library
See the latest version documentation.
find.m
Go to the documentation of this file.
1%> \brief
2%> Return a list of scalar MATLAB strings containing the paths to
3%> all detected ``mpiexec`` binaries installed on the system and
4%> available in the environment path variable.<br>
5%>
6%> \details
7%> The search strategy is to parse and search the paths in the environmental
8%> ``PATH`` variable of the runtime processor shell and return all ``mpiexec`` paths.<br>
9%> Also, all ``mpiexec`` paths found via [pm.sys.path.mpiexec.which(vendor)](@ref which) are returned.<br>
10%> Additionally, if ``vendor`` is missing or is set to ``"Intel"``, also search the default
11%> installation directories of Intel MPI libraries on all operating systems.<br>
12%> Think of this functionality [pm.sys.path.mpiexec.find(vendor)](@ref find) as a
13%> more comprehensive of what [pm.sys.path.mpiexec.which(vendor)](@ref which) does.<br>
14%>
15%> \warning
16%> In Microsoft Windows Subsystem for Linux (WSL) environments, this function
17%> may freeze MATLAB indefinitely, if Windows paths containing MPI installations
18%> exist within the environmental variable ``PATH``.<br>
19%> Such paths typically begin with ``/mnt/`` and are automatically
20%> prepended by WSL to the contents of the ``PATH`` variable.<br>
21%> This problem happens because Windows applications cannot be executed
22%> from within a WSL terminal, freezing the terminal indefinitely.<br>
23%> The best solution is to remove Windows paths from the contents of the
24%> environment variable ``PATH`` of the WSL terminals.<br>
25%> See [this StackOverflow question](https://stackoverflow.com/questions/51336147/how-to-remove-the-win10s-path-from-wsl)
26%> for possible solutions.<br>
27%>
28%> \param[in] vendor : The input scalar MATLAB string, containing the MPI
29%> library vendor that should match the ``mpiexec`` binary.<br>
30%> Possible values are:<br>
31%> <ol>
32%> <li> ``Intel``, representing the Intel MPI library.
33%> <li> ``MPICH``, representing the MPICH MPI library.
34%> <li> ``OpenMPI``, representing the OpenMPI library.
35%> </ol>
36%> (**optional**, default = ``""``)
37%>
38%> \return
39%> ``pathList`` : A list of scalar MATLAB strings containing the paths to
40%> all detected ``mpiexec`` binaries installed on the system.<br>
41%> If the ``mpiexec`` is not found or does not match the specified ``vendor``,
42%> the output will be an empty list ``[]``.<br>
43%>
44%> \interface{find}
45%> \code{.m}
46%>
47%> pathList = pm.sys.path.mpiexec.find()
48%> pathList = pm.sys.path.mpiexec.find(vendor)
49%>
50%> \endcode
51%>
52%> \example{find}
53%> \include{lineno} example/sys/path/mpiexec/find/main.m
54%> \output{find}
55%> \include{lineno} example/sys/path/mpiexec/find/main.out.m
56%>
57%> \final{find}
58%>
59%> \author
60%> \JoshuaOsborne, May 21 2024, 5:03 AM, University of Texas at Arlington<br>
61%> \FatemehBagheri, May 20 2024, 1:25 PM, NASA Goddard Space Flight Center (GSFC), Washington, D.C.<br>
62%> \AmirShahmoradi, May 16 2016, 9:03 AM, Oden Institute for Computational Engineering and Sciences (ICES), UT Austin<br>
63function pathList = find(vendor)
64
65 pathList = [];
66 if 0 < nargin
67 vendorLower = lower(vendor);
68 if vendorLower == "impi"
69 vendorLower = "intel";
70 elseif vendorLower == "open-mpi" || vendorLower == "openrte"
71 vendorLower = "openmpi";
72 end
73 vendorList = vendorLower;
74 else
75 vendorList = ["Intel", "MPICH", "OpenMPI"];
76 vendorLower = "";
77 end
78
79 %%%%
80 %%%% The strategy is to search for any executable in the
81 %%%% environmental paths whose name contains `mpiexec`.
82 %%%%
83
84 paths = getenv("PATH");
85 paths = string(strsplit(paths, pathsep));
86 for path = paths
87 apps = pm.sys.path.list(path);
88 for icell = 1 : length(apps)
89 app = apps(icell);
90 if contains(app, "mpiexec") && isfile(app)
91 if 0 < nargin
92 name = lower(pm.sys.path.mpiexec.vendor(app));
93 if name ~= ""
94 if contains(name, vendorLower)
95 pathList = [pathList, app];
96 end
97 end
98 else
99 pathList = [pathList, app];
100 end
101 end
102 end
103 end
104
105 %%%%
106 %%%% Try more via `which()` and default installation paths.
107 %%%%
108
109 for name = vendorList
110 path = pm.sys.path.mpiexec.which(name);
111 if path ~= ""
112 if isempty(pathList)
113 pathList = [pathList, path];
114 elseif sum(strcmp(pathList, path)) == 0
115 pathList = [pathList, path];
116 end
117 end
118 end
119
120 if nargin == 0 || contains(vendorLower, "intel")
121 possibilities = [ "C:\Program Files (x86)\Intel\oneAPI\mpi\latest\bin\mpiexec.exe" ...
122 , "C:\Program Files\Intel\oneAPI\mpi\latest\bin\mpiexec.exe" ...
123 , "/opt/intel/oneapi/mpi/latest/bin/mpiexec" ...
124 ];
125 for path = possibilities
126 if isfile(path)
127 if isempty(pathList)
128 pathList = [pathList, path];
129 elseif sum(contains(pathList, path)) == 0
130 pathList = [pathList, path];
131 end
132 end
133 end
134 end
135
136end
function name(in vendor)
Return the MPI library name as used in naming the ParaMonte MATLAB shared libraries.
function list()
Return a list of MATLAB strings containing the names of OS platforms supported by the ParaMonte MATLA...
function find(in vendor)
Return a list of scalar MATLAB strings containing the paths to all detected mpiexec binaries installe...
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...