1 // Copyright (C) 2007-2015 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"
24 #include "Utils_SALOME_Exception.hxx"
32 unsigned int ResourceDataToSort::_nbOfProcWanted = NULL_VALUE;
33 unsigned int ResourceDataToSort::_nbOfNodesWanted = NULL_VALUE;
34 unsigned int ResourceDataToSort::_nbOfProcPerNodeWanted = NULL_VALUE;
35 unsigned int ResourceDataToSort::_CPUFreqMHzWanted = NULL_VALUE;
36 unsigned int ResourceDataToSort::_memInMBWanted = NULL_VALUE;
38 ResourceDataToSort::ResourceDataToSort()
41 ResourceDataToSort::ResourceDataToSort(const std::string& name,
42 unsigned int nbOfNodes,
43 unsigned int nbOfProcPerNode,
44 unsigned int CPUFreqMHz,
45 unsigned int memInMB):
47 _nbOfNodes(nbOfNodes),
48 _nbOfProcPerNode(nbOfProcPerNode),
49 _CPUFreqMHz(CPUFreqMHz),
53 //! Method used by list::sort to sort the resources used in SALOME_ResourcesManager::GetResourcesFitting
54 bool ResourceDataToSort::operator< (const ResourceDataToSort& other) const
56 unsigned int nbPts = GetNumberOfPoints();
57 return nbPts < other.GetNumberOfPoints();
60 unsigned int ResourceDataToSort::GetNumberOfPoints() const
63 //priority 0 : Nb of proc
65 if (_nbOfProcWanted != NULL_VALUE)
67 unsigned int nb_proc = _nbOfNodes * _nbOfProcPerNode;
68 if (nb_proc == _nbOfProcWanted)
70 else if (nb_proc > _nbOfProcWanted)
76 //priority 1 : Nb of nodes
78 if (_nbOfNodesWanted != NULL_VALUE)
80 if (_nbOfNodes == _nbOfNodesWanted)
82 else if (_nbOfNodes > _nbOfNodesWanted)
88 //priority 2 : Nb of proc by node
89 if (_nbOfProcPerNodeWanted != NULL_VALUE)
91 if (_nbOfProcPerNode == _nbOfProcPerNodeWanted)
93 else if (_nbOfProcPerNode > _nbOfProcPerNodeWanted)
99 //priority 3 : Cpu freq
100 if (_CPUFreqMHzWanted != NULL_VALUE)
102 if (_CPUFreqMHz == _CPUFreqMHzWanted)
104 else if (_CPUFreqMHz > _CPUFreqMHzWanted)
110 //priority 4 : memory
111 if (_memInMBWanted != NULL_VALUE)
113 if (_memInMB == _memInMBWanted)
115 else if (_memInMB > _memInMBWanted)
121 //RES_MESSAGE("[GetNumberOfPoints] points number for resource: " << _Name << " " << ret);
125 //! Method used for debug
126 void ResourceDataToSort::Print() const
128 std::cout << _nbOfNodes << std::endl;
129 std::cout << _nbOfProcPerNode << std::endl;
130 std::cout << _CPUFreqMHz << std::endl;
131 std::cout << _memInMB << std::endl;
135 ParserResourcesType::ParserResourcesType()
136 : type(single_machine),
138 ClusterInternalProtocol(ssh),
142 can_launch_batch_jobs(false),
143 can_run_containers(false)
145 DataForSort._Name = "";
146 DataForSort._nbOfNodes = 1;
147 DataForSort._nbOfProcPerNode = 1;
148 DataForSort._CPUFreqMHz = 0;
149 DataForSort._memInMB = 0;
152 ParserResourcesType::~ParserResourcesType()
156 std::string ParserResourcesType::protocolToString(AccessProtocolType protocol)
173 throw SALOME_Exception("Unknown protocol");
177 AccessProtocolType ParserResourcesType::stringToProtocol(const std::string & protocolStr)
179 if (protocolStr == "sh")
181 else if (protocolStr == "rsh")
183 else if (protocolStr == "ssh")
185 else if (protocolStr == "srun")
187 else if (protocolStr == "pbsdsh")
189 else if (protocolStr == "blaunch")
192 throw SALOME_Exception((string("Unknown protocol ") + protocolStr).c_str());
195 ostream & operator<<(ostream &os, const ParserResourcesType &prt)
197 os << "Name: " << prt.Name << endl <<
198 "HostName: " << prt.HostName << endl <<
199 "Type: " << prt.getResourceTypeStr() << endl <<
200 "NbOfNodes: " << prt.DataForSort._nbOfNodes << endl <<
201 "NbOfProcPerNode: " << prt.DataForSort._nbOfProcPerNode << endl <<
202 "CPUFreqMHz: " << prt.DataForSort._CPUFreqMHz << endl <<
203 "MemInMB: " << prt.DataForSort._memInMB << endl <<
204 "Protocol: " << prt.getAccessProtocolTypeStr() << endl <<
205 "ClusterInternalProtocol: " << prt.getClusterInternalProtocolStr() << endl <<
206 "Batch: " << prt.getBatchTypeStr() << endl <<
207 "mpi: " << prt.getMpiImplTypeStr() << endl <<
208 "UserName: " << prt.UserName << endl <<
209 "AppliPath: " << prt.AppliPath << endl <<
210 "OS: " << prt.OS << endl <<
211 "batchQueue: " << prt.batchQueue << endl <<
212 "userCommands: " << prt.userCommands << endl <<
213 "use: " << prt.use << endl <<
214 "NbOfProc: " << prt.nbOfProc << endl <<
215 "Can Launch Batch Jobs: " << prt.can_launch_batch_jobs << endl <<
216 "Can Run Containers: " << prt.can_run_containers << endl <<
217 "Working Directory: " << prt.working_directory << endl;
219 for(unsigned int i=0 ; i<prt.ComponentsList.size() ; i++)
220 os << "Component " << i+1 << " called: " << prt.ComponentsList[i] << endl;
222 list<ParserResourcesType>::const_iterator it;
223 for(it = prt.ClusterMembersList.begin() ; it != prt.ClusterMembersList.end() ; it++)
225 os << "Cluster member called: " << (*it).HostName << endl;
231 ParserResourcesType::getAccessProtocolTypeStr() const
233 return protocolToString(Protocol);
237 ParserResourcesType::getClusterInternalProtocolStr() const
239 return protocolToString(ClusterInternalProtocol);
243 ParserResourcesType::getResourceTypeStr() const
250 return "single_machine";
252 throw SALOME_Exception("Unknown resource type");
257 ParserResourcesType::getBatchTypeStr() const
282 throw SALOME_Exception("Unknown batch type");
287 ParserResourcesType::getMpiImplTypeStr() const
308 throw SALOME_Exception("Unknown MPI implementation type");
312 string ParserResourcesType::getCanLaunchBatchJobsStr() const
314 return can_launch_batch_jobs ? "true" : "false";
317 string ParserResourcesType::getCanRunContainersStr() const
319 return can_run_containers ? "true" : "false";
322 void ParserResourcesType::setAccessProtocolTypeStr(const string & protocolTypeStr)
324 Protocol = stringToProtocol(protocolTypeStr);
327 void ParserResourcesType::setResourceTypeStr(const string & resourceTypeStr)
329 if (resourceTypeStr == "cluster")
331 else if (resourceTypeStr == "single_machine")
332 type = single_machine;
334 throw SALOME_Exception((string("Unknown resource type ") + resourceTypeStr).c_str());
337 void ParserResourcesType::setBatchTypeStr(const string & batchTypeStr)
339 if (batchTypeStr == "pbs")
341 else if (batchTypeStr == "lsf")
343 else if (batchTypeStr == "sge")
345 else if (batchTypeStr == "slurm")
347 else if (batchTypeStr == "ccc")
349 else if (batchTypeStr == "ll")
351 else if (batchTypeStr == "vishnu")
353 else if (batchTypeStr == "oar")
355 else if (batchTypeStr == "coorm")
357 else if (batchTypeStr == "" || batchTypeStr == "none" || batchTypeStr == "ssh_batch")
360 throw SALOME_Exception((string("Unknown batch type ") + batchTypeStr).c_str());
363 void ParserResourcesType::setMpiImplTypeStr(const string & mpiImplTypeStr)
365 if (mpiImplTypeStr == "lam")
367 else if (mpiImplTypeStr == "mpich1")
369 else if (mpiImplTypeStr == "mpich2")
371 else if (mpiImplTypeStr == "openmpi")
373 else if (mpiImplTypeStr == "ompi")
375 else if (mpiImplTypeStr == "slurmmpi")
377 else if (mpiImplTypeStr == "prun")
379 else if (mpiImplTypeStr == "" || mpiImplTypeStr == "no mpi")
382 throw SALOME_Exception((string("Unknown MPI implementation type ") + mpiImplTypeStr).c_str());
385 void ParserResourcesType::setClusterInternalProtocolStr(const string & internalProtocolTypeStr)
387 ClusterInternalProtocol = stringToProtocol(internalProtocolTypeStr);
390 void ParserResourcesType::setCanLaunchBatchJobsStr(const string & canLaunchBatchJobsStr)
392 if (canLaunchBatchJobsStr == "true")
393 can_launch_batch_jobs = true;
394 else if (canLaunchBatchJobsStr == "false")
395 can_launch_batch_jobs = false;
397 throw SALOME_Exception((string("Invalid boolean value for can_launch_batch_jobs: ") +
398 canLaunchBatchJobsStr).c_str());
401 void ParserResourcesType::setCanRunContainersStr(const string & canRunContainersStr)
403 if (canRunContainersStr == "true")
404 can_run_containers = true;
405 else if (canRunContainersStr == "false")
406 can_run_containers = false;
408 throw SALOME_Exception((string("Invalid boolean value for can_run_containers: ") +
409 canRunContainersStr).c_str());