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"
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)
172 throw ResourcesException("Unknown protocol");
176 AccessProtocolType ParserResourcesType::stringToProtocol(const std::string & protocolStr)
178 if (protocolStr == "sh")
180 else if (protocolStr == "rsh")
182 else if (protocolStr == "ssh")
184 else if (protocolStr == "srun")
186 else if (protocolStr == "pbsdsh")
188 else if (protocolStr == "blaunch")
191 throw ResourcesException((string("Unknown protocol ") + protocolStr).c_str());
194 ostream & operator<<(ostream &os, const ParserResourcesType &prt)
196 os << "Name: " << prt.Name << endl <<
197 "HostName: " << prt.HostName << endl <<
198 "Type: " << prt.getResourceTypeStr() << endl <<
199 "NbOfNodes: " << prt.DataForSort._nbOfNodes << endl <<
200 "NbOfProcPerNode: " << prt.DataForSort._nbOfProcPerNode << endl <<
201 "CPUFreqMHz: " << prt.DataForSort._CPUFreqMHz << endl <<
202 "MemInMB: " << prt.DataForSort._memInMB << endl <<
203 "Protocol: " << prt.getAccessProtocolTypeStr() << endl <<
204 "ClusterInternalProtocol: " << prt.getClusterInternalProtocolStr() << endl <<
205 "Batch: " << prt.getBatchTypeStr() << endl <<
206 "mpi: " << prt.getMpiImplTypeStr() << endl <<
207 "UserName: " << prt.UserName << endl <<
208 "AppliPath: " << prt.AppliPath << endl <<
209 "OS: " << prt.OS << endl <<
210 "batchQueue: " << prt.batchQueue << endl <<
211 "userCommands: " << prt.userCommands << endl <<
212 "use: " << prt.use << endl <<
213 "NbOfProc: " << prt.nbOfProc << endl <<
214 "Can Launch Batch Jobs: " << prt.can_launch_batch_jobs << endl <<
215 "Can Run Containers: " << prt.can_run_containers << endl <<
216 "Working Directory: " << prt.working_directory << endl;
218 for(unsigned int i=0 ; i<prt.ComponentsList.size() ; i++)
219 os << "Component " << i+1 << " called: " << prt.ComponentsList[i] << endl;
221 list<ParserResourcesType>::const_iterator it;
222 for(it = prt.ClusterMembersList.begin() ; it != prt.ClusterMembersList.end() ; it++)
224 os << "Cluster member called: " << (*it).HostName << endl;
230 ParserResourcesType::getAccessProtocolTypeStr() const
232 return protocolToString(Protocol);
236 ParserResourcesType::getClusterInternalProtocolStr() const
238 return protocolToString(ClusterInternalProtocol);
242 ParserResourcesType::getResourceTypeStr() const
249 return "single_machine";
251 throw ResourcesException("Unknown resource type");
256 ParserResourcesType::getBatchTypeStr() const
281 throw ResourcesException("Unknown batch type");
286 ParserResourcesType::getMpiImplTypeStr() const
307 throw ResourcesException("Unknown MPI implementation type");
311 string ParserResourcesType::getCanLaunchBatchJobsStr() const
313 return can_launch_batch_jobs ? "true" : "false";
316 string ParserResourcesType::getCanRunContainersStr() const
318 return can_run_containers ? "true" : "false";
321 void ParserResourcesType::setAccessProtocolTypeStr(const string & protocolTypeStr)
323 Protocol = stringToProtocol(protocolTypeStr);
326 void ParserResourcesType::setResourceTypeStr(const string & resourceTypeStr)
328 if (resourceTypeStr == "cluster")
330 else if (resourceTypeStr == "single_machine")
331 type = single_machine;
333 throw ResourcesException((string("Unknown resource type ") + resourceTypeStr).c_str());
336 void ParserResourcesType::setBatchTypeStr(const string & batchTypeStr)
338 if (batchTypeStr == "pbs")
340 else if (batchTypeStr == "lsf")
342 else if (batchTypeStr == "sge")
344 else if (batchTypeStr == "slurm")
346 else if (batchTypeStr == "ccc")
348 else if (batchTypeStr == "ll")
350 else if (batchTypeStr == "vishnu")
352 else if (batchTypeStr == "oar")
354 else if (batchTypeStr == "coorm")
356 else if (batchTypeStr == "" || batchTypeStr == "none" || batchTypeStr == "ssh_batch")
359 throw ResourcesException((string("Unknown batch type ") + batchTypeStr).c_str());
362 void ParserResourcesType::setMpiImplTypeStr(const string & mpiImplTypeStr)
364 if (mpiImplTypeStr == "lam")
366 else if (mpiImplTypeStr == "mpich1")
368 else if (mpiImplTypeStr == "mpich2")
370 else if (mpiImplTypeStr == "openmpi")
372 else if (mpiImplTypeStr == "ompi")
374 else if (mpiImplTypeStr == "slurmmpi")
376 else if (mpiImplTypeStr == "prun")
378 else if (mpiImplTypeStr == "" || mpiImplTypeStr == "no mpi")
381 throw ResourcesException((string("Unknown MPI implementation type ") + mpiImplTypeStr).c_str());
384 void ParserResourcesType::setClusterInternalProtocolStr(const string & internalProtocolTypeStr)
386 ClusterInternalProtocol = stringToProtocol(internalProtocolTypeStr);
389 void ParserResourcesType::setCanLaunchBatchJobsStr(const string & canLaunchBatchJobsStr)
391 if (canLaunchBatchJobsStr == "true")
392 can_launch_batch_jobs = true;
393 else if (canLaunchBatchJobsStr == "false")
394 can_launch_batch_jobs = false;
396 throw ResourcesException((string("Invalid boolean value for can_launch_batch_jobs: ") +
397 canLaunchBatchJobsStr).c_str());
400 void ParserResourcesType::setCanRunContainersStr(const string & canRunContainersStr)
402 if (canRunContainersStr == "true")
403 can_run_containers = true;
404 else if (canRunContainersStr == "false")
405 can_run_containers = false;
407 throw ResourcesException((string("Invalid boolean value for can_run_containers: ") +
408 canRunContainersStr).c_str());