Salome HOME
Copyright update 2021
[tools/libbatch.git] / src / Core / MpiImpl.cxx
1 // Copyright (C) 2007-2021  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #include <iostream>
24 #include <sstream>
25 #include <string>
26 #include "MpiImpl.hxx"
27
28 using namespace std;
29
30 // Constructor
31 MpiImpl::MpiImpl()
32 {
33 }
34
35 // Destructor
36 MpiImpl::~MpiImpl()
37 {
38 }
39
40 // lam implementation
41 // Constructor
42 MpiImpl_LAM::MpiImpl_LAM() : MpiImpl()
43 {
44 }
45
46 // Destructor
47 MpiImpl_LAM::~MpiImpl_LAM()
48 {
49 }
50
51 string MpiImpl_LAM::size()
52 {
53   return "${LAMWORLD}";
54 }
55
56 string MpiImpl_LAM::rank()
57 {
58   return "${LAMRANK}";
59 }
60
61 string MpiImpl_LAM::boot(const string machinefile, const unsigned int /*nbnodes*/)
62 {
63   ostringstream oss;
64   oss << "lamboot " << machinefile << endl;
65   return oss.str();
66 }
67
68 string MpiImpl_LAM::run(const string /*machinefile*/, const unsigned int nbproc, const string fileNameToExecute)
69 {
70   ostringstream oss;
71   oss << "mpirun -np " << nbproc << " " << fileNameToExecute << endl;
72   return oss.str();
73 }
74
75 string MpiImpl_LAM::halt()
76 {
77   ostringstream oss;
78   oss << "lamhalt" << endl;
79   return oss.str();
80 }
81
82 string MpiImpl_LAM::name()
83 {
84   return "lam";
85 }
86
87 // mpich1 implementation
88 // Constructor
89 MpiImpl_MPICH1::MpiImpl_MPICH1() : MpiImpl()
90 {
91 }
92
93 // Destructor
94 MpiImpl_MPICH1::~MpiImpl_MPICH1()
95 {
96 }
97
98 string MpiImpl_MPICH1::size()
99 {
100   return "${MPIRUN_NPROCS}";
101 }
102
103 string MpiImpl_MPICH1::rank()
104 {
105   return "${MPIRUN_RANK}";
106 }
107
108 string MpiImpl_MPICH1::boot(const string /*machinefile*/, const unsigned int /*nbnodes*/)
109 {
110   return "";
111 }
112
113 string MpiImpl_MPICH1::run(const string machinefile, const unsigned int nbproc, const string fileNameToExecute)
114 {
115   ostringstream oss;
116   oss << "mpirun -machinefile " << machinefile << " -np " << nbproc << " " << fileNameToExecute << endl;
117   return oss.str();
118 }
119
120 string MpiImpl_MPICH1::halt()
121 {
122   return "";
123 }
124
125 string MpiImpl_MPICH1::name()
126 {
127   return "mpich";
128 }
129
130 // mpich2 implementation
131 // Constructor
132 MpiImpl_MPICH2::MpiImpl_MPICH2() : MpiImpl()
133 {
134 }
135
136 // Destructor
137 MpiImpl_MPICH2::~MpiImpl_MPICH2()
138 {
139 }
140
141 string MpiImpl_MPICH2::size()
142 {
143   return "${PMI_SIZE}";
144 }
145
146 string MpiImpl_MPICH2::rank()
147 {
148   return "${PMI_RANK}";
149 }
150
151 string MpiImpl_MPICH2::boot(const string machinefile, const unsigned int nbnodes)
152 {
153   ostringstream oss;
154   oss << "mpdboot" << " -n " << nbnodes;
155   if (machinefile!="")
156     oss  << " -f " << machinefile;
157   oss << endl;
158   return oss.str();
159 }
160
161 string MpiImpl_MPICH2::run(const string /*machinefile*/, const unsigned int nbproc, const string fileNameToExecute)
162 {
163   ostringstream oss;
164   oss << "mpirun -np " << nbproc << " " << fileNameToExecute << endl;
165   return oss.str();
166 }
167
168 string MpiImpl_MPICH2::halt()
169 {
170   ostringstream oss;
171   oss << "mpdallexit" << endl;
172   return oss.str();
173 }
174
175 string MpiImpl_MPICH2::name()
176 {
177   return "mpich";
178 }
179
180 // openmpi implementation
181 // Constructor
182 MpiImpl_OPENMPI::MpiImpl_OPENMPI() : MpiImpl()
183 {
184 }
185
186 // Destructor
187 MpiImpl_OPENMPI::~MpiImpl_OPENMPI()
188 {
189 }
190
191 string MpiImpl_OPENMPI::size()
192 {
193   return "${OMPI_MCA_ns_nds_num_procs}";
194 }
195
196 string MpiImpl_OPENMPI::rank()
197 {
198   return "${OMPI_MCA_ns_nds_vpid}";
199 }
200
201 string MpiImpl_OPENMPI::boot(const string /*machinefile*/, const unsigned int /*nbnodes*/)
202 {
203   return "";
204 }
205
206 string MpiImpl_OPENMPI::run(const string machinefile, const unsigned int nbproc, const string fileNameToExecute)
207 {
208   ostringstream oss;
209   oss << "mpirun -hostfile " << machinefile << " -np " << nbproc << " " << fileNameToExecute << endl;
210   return oss.str();
211 }
212
213 string MpiImpl_OPENMPI::halt()
214 {
215   return "";
216 }
217
218 string MpiImpl_OPENMPI::name()
219 {
220   return "openmpi";
221 }
222
223 // ompi implementation
224 // Constructor
225 MpiImpl_OMPI::MpiImpl_OMPI() : MpiImpl()
226 {
227 }
228
229 // Destructor
230 MpiImpl_OMPI::~MpiImpl_OMPI()
231 {
232 }
233
234 string MpiImpl_OMPI::size()
235 {
236   return "${OMPI_MCA_ns_nds_num_procs}";
237 }
238
239 string MpiImpl_OMPI::rank()
240 {
241   return "${OMPI_MCA_ns_nds_vpid}";
242 }
243
244 string MpiImpl_OMPI::boot(const string /*machinefile*/, const unsigned int /*nbnodes*/)
245 {
246   return "";
247 }
248
249 string MpiImpl_OMPI::run(const string machinefile, const unsigned int nbproc, const string fileNameToExecute)
250 {
251   ostringstream oss;
252   oss << "mpirun -hostfile " << machinefile << " -np " << nbproc << " " << fileNameToExecute << endl;
253   return oss.str();
254 }
255
256 string MpiImpl_OMPI::halt()
257 {
258   return "";
259 }
260
261 string MpiImpl_OMPI::name()
262 {
263   return "ompi";
264 }
265
266 // slurm implementation
267 // Constructor
268 MpiImpl_SLURM::MpiImpl_SLURM() : MpiImpl()
269 {
270 }
271
272 // Destructor
273 MpiImpl_SLURM::~MpiImpl_SLURM()
274 {
275 }
276
277 string MpiImpl_SLURM::size()
278 {
279   return "${SLURM_NPROCS}";
280 }
281
282 string MpiImpl_SLURM::rank()
283 {
284   return "${SLURM_PROCID}";
285 }
286
287 string MpiImpl_SLURM::boot(const string /*machinefile*/, const unsigned int /*nbnodes*/)
288 {
289   return "";
290 }
291
292 string MpiImpl_SLURM::run(const string /*machinefile*/, const unsigned int /*nbproc*/, const string fileNameToExecute)
293 {
294   ostringstream oss;
295   oss << "srun " << fileNameToExecute << endl;
296   return oss.str();
297 }
298
299 string MpiImpl_SLURM::halt()
300 {
301   return "";
302 }
303
304 string MpiImpl_SLURM::name()
305 {
306   return "slurm";
307 }
308
309 // prun implementation
310 // Constructor
311 MpiImpl_PRUN::MpiImpl_PRUN() : MpiImpl()
312 {
313 }
314
315 // Destructor
316 MpiImpl_PRUN::~MpiImpl_PRUN()
317 {
318 }
319
320 string MpiImpl_PRUN::size()
321 {
322   return "${RMS_NPROCS}";
323 }
324
325 string MpiImpl_PRUN::rank()
326 {
327   return "${RMS_RANK}";
328 }
329
330 string MpiImpl_PRUN::boot(const string /*machinefile*/, const unsigned int /*nbnodes*/)
331 {
332   return "";
333 }
334
335 string MpiImpl_PRUN::run(const string /*machinefile*/, const unsigned int nbproc, const string fileNameToExecute)
336 {
337   ostringstream oss;
338   oss << "prun -n " << nbproc << " " << "-p mpi " << fileNameToExecute << endl;
339   return oss.str();
340 }
341
342 string MpiImpl_PRUN::halt()
343 {
344   return "";
345 }
346
347 string MpiImpl_PRUN::name()
348 {
349   return "prun";
350 }