Salome HOME
Update copyrights
[tools/libbatch.git] / src / Core / Batch_MpiImpl.cxx
1 //  Copyright (C) 2007-2012  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.
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 "Batch_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 // mpich1 implementation
83 // Constructor
84 MpiImpl_MPICH1::MpiImpl_MPICH1() : MpiImpl()
85 {
86 }
87
88 // Destructor
89 MpiImpl_MPICH1::~MpiImpl_MPICH1()
90 {
91 }
92
93 string MpiImpl_MPICH1::size()
94 {
95   return "${MPIRUN_NPROCS}";
96 }
97
98 string MpiImpl_MPICH1::rank()
99 {
100   return "${MPIRUN_RANK}";
101 }
102
103 string MpiImpl_MPICH1::boot(const string machinefile, const unsigned int nbnodes)
104 {
105   return "";
106 }
107
108 string MpiImpl_MPICH1::run(const string machinefile, const unsigned int nbproc, const string fileNameToExecute)
109 {
110   ostringstream oss;
111   oss << "mpirun -machinefile " << machinefile << " -np " << nbproc << " " << fileNameToExecute << endl;
112   return oss.str();
113 }
114
115 string MpiImpl_MPICH1::halt()
116 {
117   return "";
118 }
119
120 // mpich2 implementation
121 // Constructor
122 MpiImpl_MPICH2::MpiImpl_MPICH2() : MpiImpl()
123 {
124 }
125
126 // Destructor
127 MpiImpl_MPICH2::~MpiImpl_MPICH2()
128 {
129 }
130
131 string MpiImpl_MPICH2::size()
132 {
133   return "${PMI_SIZE}";
134 }
135
136 string MpiImpl_MPICH2::rank()
137 {
138   return "${PMI_RANK}";
139 }
140
141 string MpiImpl_MPICH2::boot(const string machinefile, const unsigned int nbnodes)
142 {
143   ostringstream oss;
144   oss << "mpdboot" << " -n " << nbnodes;
145   if (machinefile!="")
146     oss  << " -f " << machinefile;
147   oss << endl;
148   return oss.str();
149 }
150
151 string MpiImpl_MPICH2::run(const string machinefile, const unsigned int nbproc, const string fileNameToExecute)
152 {
153   ostringstream oss;
154   oss << "mpirun -np " << nbproc << " " << fileNameToExecute << endl;
155   return oss.str();
156 }
157
158 string MpiImpl_MPICH2::halt()
159 {
160   ostringstream oss;
161   oss << "mpdallexit" << endl;
162   return oss.str();
163 }
164
165 // openmpi implementation
166 // Constructor
167 MpiImpl_OPENMPI::MpiImpl_OPENMPI() : MpiImpl()
168 {
169 }
170
171 // Destructor
172 MpiImpl_OPENMPI::~MpiImpl_OPENMPI()
173 {
174 }
175
176 string MpiImpl_OPENMPI::size()
177 {
178   return "${OMPI_MCA_ns_nds_num_procs}";
179 }
180
181 string MpiImpl_OPENMPI::rank()
182 {
183   return "${OMPI_MCA_ns_nds_vpid}";
184 }
185
186 string MpiImpl_OPENMPI::boot(const string machinefile, const unsigned int nbnodes)
187 {
188   return "";
189 }
190
191 string MpiImpl_OPENMPI::run(const string machinefile, const unsigned int nbproc, const string fileNameToExecute)
192 {
193   ostringstream oss;
194   oss << "mpirun -hostfile " << machinefile << " -np " << nbproc << " " << fileNameToExecute << endl;
195   return oss.str();
196 }
197
198 string MpiImpl_OPENMPI::halt()
199 {
200   return "";
201 }
202
203 // slurm implementation
204 // Constructor
205 MpiImpl_SLURM::MpiImpl_SLURM() : MpiImpl()
206 {
207 }
208
209 // Destructor
210 MpiImpl_SLURM::~MpiImpl_SLURM()
211 {
212 }
213
214 string MpiImpl_SLURM::size()
215 {
216   return "${SLURM_NPROCS}";
217 }
218
219 string MpiImpl_SLURM::rank()
220 {
221   return "${SLURM_PROCID}";
222 }
223
224 string MpiImpl_SLURM::boot(const string machinefile, const unsigned int nbnodes)
225 {
226   return "";
227 }
228
229 string MpiImpl_SLURM::run(const string machinefile, const unsigned int nbproc, const string fileNameToExecute)
230 {
231   ostringstream oss;
232   oss << "srun " << fileNameToExecute << endl;
233   return oss.str();
234 }
235
236 string MpiImpl_SLURM::halt()
237 {
238   return "";
239 }
240
241 // prun implementation
242 // Constructor
243 MpiImpl_PRUN::MpiImpl_PRUN() : MpiImpl()
244 {
245 }
246
247 // Destructor
248 MpiImpl_PRUN::~MpiImpl_PRUN()
249 {
250 }
251
252 string MpiImpl_PRUN::size()
253 {
254   return "${RMS_NPROCS}";
255 }
256
257 string MpiImpl_PRUN::rank()
258 {
259   return "${RMS_RANK}";
260 }
261
262 string MpiImpl_PRUN::boot(const string machinefile, const unsigned int nbnodes)
263 {
264   return "";
265 }
266
267 string MpiImpl_PRUN::run(const string machinefile, const unsigned int nbproc, const string fileNameToExecute)
268 {
269   ostringstream oss;
270   oss << "prun -n " << nbproc << " " << "-p mpi " << fileNameToExecute << endl;
271   return oss.str();
272 }
273
274 string MpiImpl_PRUN::halt()
275 {
276   return "";
277 }