1 // Copyright (C) 2007-2019 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "SALOME_ResourcesCatalog_Parser.hxx"
31 unsigned int ResourceDataToSort::_nbOfProcWanted = NULL_VALUE;
32 unsigned int ResourceDataToSort::_nbOfNodesWanted = NULL_VALUE;
33 unsigned int ResourceDataToSort::_nbOfProcPerNodeWanted = NULL_VALUE;
34 unsigned int ResourceDataToSort::_CPUFreqMHzWanted = NULL_VALUE;
35 unsigned int ResourceDataToSort::_memInMBWanted = NULL_VALUE;
37 ResourceDataToSort::ResourceDataToSort()
40 ResourceDataToSort::ResourceDataToSort(const std::string& name,
41 unsigned int nbOfNodes,
42 unsigned int nbOfProcPerNode,
43 unsigned int CPUFreqMHz,
44 unsigned int memInMB):
46 _nbOfNodes(nbOfNodes),
47 _nbOfProcPerNode(nbOfProcPerNode),
48 _CPUFreqMHz(CPUFreqMHz),
52 //! Method used by list::sort to sort the resources used in SALOME_ResourcesManager::GetResourcesFitting
53 bool ResourceDataToSort::operator< (const ResourceDataToSort& other) const
55 unsigned int nbPts = GetNumberOfPoints();
56 return nbPts < other.GetNumberOfPoints();
59 unsigned int ResourceDataToSort::GetNumberOfPoints() const
62 //priority 0 : Nb of proc
64 if (_nbOfProcWanted != NULL_VALUE)
66 unsigned int nb_proc = _nbOfNodes * _nbOfProcPerNode;
67 if (nb_proc == _nbOfProcWanted)
69 else if (nb_proc > _nbOfProcWanted)
75 //priority 1 : Nb of nodes
77 if (_nbOfNodesWanted != NULL_VALUE)
79 if (_nbOfNodes == _nbOfNodesWanted)
81 else if (_nbOfNodes > _nbOfNodesWanted)
87 //priority 2 : Nb of proc by node
88 if (_nbOfProcPerNodeWanted != NULL_VALUE)
90 if (_nbOfProcPerNode == _nbOfProcPerNodeWanted)
92 else if (_nbOfProcPerNode > _nbOfProcPerNodeWanted)
98 //priority 3 : Cpu freq
99 if (_CPUFreqMHzWanted != NULL_VALUE)
101 if (_CPUFreqMHz == _CPUFreqMHzWanted)
103 else if (_CPUFreqMHz > _CPUFreqMHzWanted)
109 //priority 4 : memory
110 if (_memInMBWanted != NULL_VALUE)
112 if (_memInMB == _memInMBWanted)
114 else if (_memInMB > _memInMBWanted)
120 //RES_MESSAGE("[GetNumberOfPoints] points number for resource: " << _Name << " " << ret);
124 //! Method used for debug
125 void ResourceDataToSort::Print() const
127 std::cout << _nbOfNodes << std::endl;
128 std::cout << _nbOfProcPerNode << std::endl;
129 std::cout << _CPUFreqMHz << std::endl;
130 std::cout << _memInMB << std::endl;
134 ParserResourcesType::ParserResourcesType()
135 : type(single_machine),
137 ClusterInternalProtocol(ssh),
141 can_launch_batch_jobs(false),
142 can_run_containers(false)
144 DataForSort._Name = "";
145 DataForSort._nbOfNodes = 1;
146 DataForSort._nbOfProcPerNode = 1;
147 DataForSort._CPUFreqMHz = 0;
148 DataForSort._memInMB = 0;
151 ParserResourcesType::~ParserResourcesType()
155 std::string ParserResourcesType::protocolToString(AccessProtocolType protocol)
174 throw ResourcesException("Unknown protocol");
178 AccessProtocolType ParserResourcesType::stringToProtocol(const std::string & protocolStr)
180 if (protocolStr == "sh")
182 else if (protocolStr == "rsh")
184 else if (protocolStr == "ssh")
186 else if (protocolStr == "srun")
188 else if (protocolStr == "pbsdsh")
190 else if (protocolStr == "blaunch")
192 else if (protocolStr == "rsync")
195 throw ResourcesException((string("Unknown protocol ") + protocolStr).c_str());
198 ostream & operator<<(ostream &os, const ParserResourcesType &prt)
200 os << "Name: " << prt.Name << endl <<
201 "HostName: " << prt.HostName << endl <<
202 "Type: " << prt.getResourceTypeStr() << endl <<
203 "NbOfNodes: " << prt.DataForSort._nbOfNodes << endl <<
204 "NbOfProcPerNode: " << prt.DataForSort._nbOfProcPerNode << endl <<
205 "CPUFreqMHz: " << prt.DataForSort._CPUFreqMHz << endl <<
206 "MemInMB: " << prt.DataForSort._memInMB << endl <<
207 "Protocol: " << prt.getAccessProtocolTypeStr() << endl <<
208 "ClusterInternalProtocol: " << prt.getClusterInternalProtocolStr() << endl <<
209 "Batch: " << prt.getBatchTypeStr() << endl <<
210 "mpi: " << prt.getMpiImplTypeStr() << endl <<
211 "UserName: " << prt.UserName << endl <<
212 "AppliPath: " << prt.AppliPath << endl <<
213 "OS: " << prt.OS << endl <<
214 "batchQueue: " << prt.batchQueue << endl <<
215 "userCommands: " << prt.userCommands << endl <<
216 "use: " << prt.use << endl <<
217 "NbOfProc: " << prt.nbOfProc << endl <<
218 "Can Launch Batch Jobs: " << prt.can_launch_batch_jobs << endl <<
219 "Can Run Containers: " << prt.can_run_containers << endl <<
220 "Working Directory: " << prt.working_directory << endl;
222 for(unsigned int i=0 ; i<prt.ComponentsList.size() ; i++)
223 os << "Component " << i+1 << " called: " << prt.ComponentsList[i] << endl;
225 list<ParserResourcesType>::const_iterator it;
226 for(it = prt.ClusterMembersList.begin() ; it != prt.ClusterMembersList.end() ; it++)
228 os << "Cluster member called: " << (*it).HostName << endl;
234 ParserResourcesType::getAccessProtocolTypeStr() const
236 return protocolToString(Protocol);
240 ParserResourcesType::getClusterInternalProtocolStr() const
242 return protocolToString(ClusterInternalProtocol);
246 ParserResourcesType::getResourceTypeStr() const
253 return "single_machine";
255 throw ResourcesException("Unknown resource type");
260 ParserResourcesType::getBatchTypeStr() const
285 throw ResourcesException("Unknown batch type");
290 ParserResourcesType::getMpiImplTypeStr() const
311 throw ResourcesException("Unknown MPI implementation type");
315 string ParserResourcesType::getCanLaunchBatchJobsStr() const
317 return can_launch_batch_jobs ? "true" : "false";
320 string ParserResourcesType::getCanRunContainersStr() const
322 return can_run_containers ? "true" : "false";
325 void ParserResourcesType::setAccessProtocolTypeStr(const string & protocolTypeStr)
327 Protocol = stringToProtocol(protocolTypeStr);
330 void ParserResourcesType::setResourceTypeStr(const string & resourceTypeStr)
332 if (resourceTypeStr == "cluster")
334 else if (resourceTypeStr == "single_machine")
335 type = single_machine;
337 throw ResourcesException((string("Unknown resource type ") + resourceTypeStr).c_str());
340 void ParserResourcesType::setBatchTypeStr(const string & batchTypeStr)
342 if (batchTypeStr == "pbs")
344 else if (batchTypeStr == "lsf")
346 else if (batchTypeStr == "sge")
348 else if (batchTypeStr == "slurm")
350 else if (batchTypeStr == "ccc")
352 else if (batchTypeStr == "ll")
354 else if (batchTypeStr == "vishnu")
356 else if (batchTypeStr == "oar")
358 else if (batchTypeStr == "coorm")
360 else if (batchTypeStr == "" || batchTypeStr == "none" || batchTypeStr == "ssh_batch")
363 throw ResourcesException((string("Unknown batch type ") + batchTypeStr).c_str());
366 void ParserResourcesType::setMpiImplTypeStr(const string & mpiImplTypeStr)
368 if (mpiImplTypeStr == "lam")
370 else if (mpiImplTypeStr == "mpich1")
372 else if (mpiImplTypeStr == "mpich2")
374 else if (mpiImplTypeStr == "openmpi")
376 else if (mpiImplTypeStr == "ompi")
378 else if (mpiImplTypeStr == "slurmmpi")
380 else if (mpiImplTypeStr == "prun")
382 else if (mpiImplTypeStr == "" || mpiImplTypeStr == "no mpi")
385 throw ResourcesException((string("Unknown MPI implementation type ") + mpiImplTypeStr).c_str());
388 void ParserResourcesType::setClusterInternalProtocolStr(const string & internalProtocolTypeStr)
390 ClusterInternalProtocol = stringToProtocol(internalProtocolTypeStr);
393 void ParserResourcesType::setCanLaunchBatchJobsStr(const string & canLaunchBatchJobsStr)
395 if (canLaunchBatchJobsStr == "true")
396 can_launch_batch_jobs = true;
397 else if (canLaunchBatchJobsStr == "false")
398 can_launch_batch_jobs = false;
400 throw ResourcesException((string("Invalid boolean value for can_launch_batch_jobs: ") +
401 canLaunchBatchJobsStr).c_str());
404 void ParserResourcesType::setCanRunContainersStr(const string & canRunContainersStr)
406 if (canRunContainersStr == "true")
407 can_run_containers = true;
408 else if (canRunContainersStr == "false")
409 can_run_containers = false;
411 throw ResourcesException((string("Invalid boolean value for can_run_containers: ") +
412 canRunContainersStr).c_str());