]> SALOME platform Git repositories - modules/kernel.git/blob - src/Batch/MpiImpl.cxx
Salome HOME
Merging from V4_1_0_maintainance for porting on Win32 Platform
[modules/kernel.git] / src / Batch / MpiImpl.cxx
1 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 // 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either 
7 // version 2.1 of the License.
8 // 
9 // This library is distributed in the hope that it will be useful 
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 // Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public  
15 // License along with this library; if not, write to the Free Software 
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 //
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 //
20 /*
21  * BatchManager.cxx : 
22  *
23  * Auteur : Bernard SECHER - CEA/DEN
24  * Date   : Juillet 2007
25  * Projet : SALOME
26  *
27  */
28
29 #include <iostream>
30 #include <sstream>
31 #include <string>
32 #include "MpiImpl.hxx"
33
34 using namespace std;
35
36 // Constructor
37 MpiImpl::MpiImpl()
38 {
39 }
40
41 // Destructor
42 MpiImpl::~MpiImpl()
43 {
44 }
45
46 // lam implementation
47 // Constructor
48 MpiImpl_LAM::MpiImpl_LAM() : MpiImpl()
49 {
50 }
51
52 // Destructor
53 MpiImpl_LAM::~MpiImpl_LAM()
54 {
55 }
56
57 string MpiImpl_LAM::size()
58 {
59   return "${LAMWORLD}";
60 }
61
62 string MpiImpl_LAM::rank()
63 {
64   return "${LAMRANK}";
65 }
66
67 string MpiImpl_LAM::boot(const string machinefile, const unsigned int nbnodes)
68 {
69   ostringstream oss;
70   oss << "lamboot " << machinefile << endl;
71   return oss.str();
72 }
73
74 string MpiImpl_LAM::run(const string machinefile, const unsigned int nbproc, const string fileNameToExecute)
75 {
76   ostringstream oss;
77   oss << "mpirun -np " << nbproc << " " << fileNameToExecute << endl;
78   return oss.str();
79 }
80
81 string MpiImpl_LAM::halt()
82 {
83   ostringstream oss;
84   oss << "lamhalt" << endl;
85   return oss.str();
86 }
87
88 // mpich1 implementation
89 // Constructor
90 MpiImpl_MPICH1::MpiImpl_MPICH1() : MpiImpl()
91 {
92 }
93
94 // Destructor
95 MpiImpl_MPICH1::~MpiImpl_MPICH1()
96 {
97 }
98
99 string MpiImpl_MPICH1::size()
100 {
101   throw MpiImplException("mpich1 doesn't work with this batch system to submit salome session");
102 }
103
104 string MpiImpl_MPICH1::rank()
105 {
106   throw MpiImplException("mpich1 doesn't work with this batch system to submit salome session");
107 }
108
109 string MpiImpl_MPICH1::boot(const string machinefile, const unsigned int nbnodes)
110 {
111   return "";
112 }
113
114 string MpiImpl_MPICH1::run(const string machinefile, const unsigned int nbproc, const string fileNameToExecute)
115 {
116   ostringstream oss;
117   oss << "mpirun -machinefile " << machinefile << " -np " << nbproc << " " << fileNameToExecute << endl;
118   return oss.str();
119 }
120
121 string MpiImpl_MPICH1::halt()
122 {
123   return "";
124 }
125
126 // mpich2 implementation
127 // Constructor
128 MpiImpl_MPICH2::MpiImpl_MPICH2() : MpiImpl()
129 {
130 }
131
132 // Destructor
133 MpiImpl_MPICH2::~MpiImpl_MPICH2()
134 {
135 }
136
137 string MpiImpl_MPICH2::size()
138 {
139   return "${PMI_SIZE}";
140 }
141
142 string MpiImpl_MPICH2::rank()
143 {
144   return "${PMI_RANK}";
145 }
146
147 string MpiImpl_MPICH2::boot(const string machinefile, const unsigned int nbnodes)
148 {
149   ostringstream oss;
150   oss << "mpdboot -n " << nbnodes << " -f " << machinefile << endl;
151   return oss.str();
152 }
153
154 string MpiImpl_MPICH2::run(const string machinefile, const unsigned int nbproc, const string fileNameToExecute)
155 {
156   ostringstream oss;
157   oss << "mpirun -np " << nbproc << " " << fileNameToExecute << endl;
158   return oss.str();
159 }
160
161 string MpiImpl_MPICH2::halt()
162 {
163   ostringstream oss;
164   oss << "mpdallexit" << endl;
165   return oss.str();
166 }
167
168 // openmpi implementation
169 // Constructor
170 MpiImpl_OPENMPI::MpiImpl_OPENMPI() : MpiImpl()
171 {
172 }
173
174 // Destructor
175 MpiImpl_OPENMPI::~MpiImpl_OPENMPI()
176 {
177 }
178
179 string MpiImpl_OPENMPI::size()
180 {
181   return "${OMPI_MCA_ns_nds_num_procs}";
182 }
183
184 string MpiImpl_OPENMPI::rank()
185 {
186   return "${OMPI_MCA_ns_nds_vpid}";
187 }
188
189 string MpiImpl_OPENMPI::boot(const string machinefile, const unsigned int nbnodes)
190 {
191   return "";
192 }
193
194 string MpiImpl_OPENMPI::run(const string machinefile, const unsigned int nbproc, const string fileNameToExecute)
195 {
196   ostringstream oss;
197   oss << "mpirun -hostfile " << machinefile << " -np " << nbproc << " " << fileNameToExecute << endl;
198   return oss.str();
199 }
200
201 string MpiImpl_OPENMPI::halt()
202 {
203   return "";
204 }
205
206 // slurm implementation
207 // Constructor
208 MpiImpl_SLURM::MpiImpl_SLURM() : MpiImpl()
209 {
210 }
211
212 // Destructor
213 MpiImpl_SLURM::~MpiImpl_SLURM()
214 {
215 }
216
217 string MpiImpl_SLURM::size()
218 {
219   return "${SLURM_NPROCS}";
220 }
221
222 string MpiImpl_SLURM::rank()
223 {
224   return "${SLURM_PROCID}";
225 }
226
227 string MpiImpl_SLURM::boot(const string machinefile, const unsigned int nbnodes)
228 {
229   return "";
230 }
231
232 string MpiImpl_SLURM::run(const string machinefile, const unsigned int nbproc, const string fileNameToExecute)
233 {
234   ostringstream oss;
235   oss << "srun " << fileNameToExecute << endl;
236   return oss.str();
237 }
238
239 string MpiImpl_SLURM::halt()
240 {
241   return "";
242 }
243