1 // Copyright (C) 2007-2012 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.
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"
30 unsigned int ResourceDataToSort::_nbOfProcWanted = NULL_VALUE;
31 unsigned int ResourceDataToSort::_nbOfNodesWanted = NULL_VALUE;
32 unsigned int ResourceDataToSort::_nbOfProcPerNodeWanted = NULL_VALUE;
33 unsigned int ResourceDataToSort::_CPUFreqMHzWanted = NULL_VALUE;
34 unsigned int ResourceDataToSort::_memInMBWanted = NULL_VALUE;
36 ResourceDataToSort::ResourceDataToSort()
39 ResourceDataToSort::ResourceDataToSort(const std::string& name,
40 unsigned int nbOfNodes,
41 unsigned int nbOfProcPerNode,
42 unsigned int CPUFreqMHz,
43 unsigned int memInMB):
45 _nbOfNodes(nbOfNodes),
46 _nbOfProcPerNode(nbOfProcPerNode),
47 _CPUFreqMHz(CPUFreqMHz),
51 //! Method used by list::sort to sort the resources used in SALOME_ResourcesManager::GetResourcesFitting
52 bool ResourceDataToSort::operator< (const ResourceDataToSort& other) const
54 unsigned int nbPts = GetNumberOfPoints();
55 return nbPts < other.GetNumberOfPoints();
58 unsigned int ResourceDataToSort::GetNumberOfPoints() const
61 //priority 0 : Nb of proc
63 if (_nbOfProcWanted != NULL_VALUE)
65 unsigned int nb_proc = _nbOfNodes * _nbOfProcPerNode;
66 if (nb_proc == _nbOfProcWanted)
68 else if (nb_proc > _nbOfProcWanted)
74 //priority 1 : Nb of nodes
76 if (_nbOfNodesWanted != NULL_VALUE)
78 if (_nbOfNodes == _nbOfNodesWanted)
80 else if (_nbOfNodes > _nbOfNodesWanted)
86 //priority 2 : Nb of proc by node
87 if (_nbOfProcPerNodeWanted != NULL_VALUE)
89 if (_nbOfProcPerNode == _nbOfProcPerNodeWanted)
91 else if (_nbOfProcPerNode > _nbOfProcPerNodeWanted)
97 //priority 3 : Cpu freq
98 if (_CPUFreqMHzWanted != NULL_VALUE)
100 if (_CPUFreqMHz == _CPUFreqMHzWanted)
102 else if (_CPUFreqMHz > _CPUFreqMHzWanted)
108 //priority 4 : memory
109 if (_memInMBWanted != NULL_VALUE)
111 if (_memInMB == _memInMBWanted)
113 else if (_memInMB > _memInMBWanted)
119 //RES_MESSAGE("[GetNumberOfPoints] points number for resource: " << _Name << " " << ret);
123 //! Method used for debug
124 void ResourceDataToSort::Print() const
126 std::cout << _nbOfNodes << std::endl;
127 std::cout << _nbOfProcPerNode << std::endl;
128 std::cout << _CPUFreqMHz << std::endl;
129 std::cout << _memInMB << std::endl;
133 std::string ParserResourcesType::protocolToString(AccessProtocolType protocol)
148 throw SALOME_Exception("Unknown protocol");
152 AccessProtocolType ParserResourcesType::stringToProtocol(const std::string & protocolStr)
154 if (protocolStr == "rsh")
156 else if (protocolStr == "ssh")
158 else if (protocolStr == "srun")
160 else if (protocolStr == "pbsdsh")
162 else if (protocolStr == "blaunch")
165 throw SALOME_Exception("Unknown protocol");
168 void ParserResourcesType::Print()
170 std::ostringstream oss;
172 "Name : " << Name << std::endl <<
173 "HostName : " << HostName << std::endl <<
174 "NbOfNodes : " << DataForSort._nbOfNodes << std::endl <<
175 "NbOfProcPerNode : " << DataForSort._nbOfProcPerNode << std::endl <<
176 "CPUFreqMHz : " << DataForSort._CPUFreqMHz << std::endl <<
177 "MemInMB : " << DataForSort._memInMB << std::endl <<
178 "Protocol : " << protocolToString(Protocol) << std::endl <<
179 "ClusterInternalProtocol : " << protocolToString(ClusterInternalProtocol) << std::endl <<
180 "Mode : " << Mode << std::endl <<
181 "Batch : " << Batch << std::endl <<
182 "mpi : " << mpi << std::endl <<
183 "UserName : " << UserName << std::endl <<
184 "AppliPath : " << AppliPath << std::endl <<
185 "OS : " << OS << std::endl <<
186 "batchQueue : " << batchQueue << std::endl <<
187 "userCommands : " << userCommands << std::endl <<
188 "use : " << use << std::endl <<
189 "NbOfProc : " << nbOfProc << std::endl <<
190 "Modules : " << std::endl <<
191 "Components : " << std::endl <<
192 "Is Cluster Head: " << is_cluster_head << std::endl <<
193 "Working Directory: " << working_directory << std::endl;
195 for(unsigned int i=0;i<ComponentsList.size();i++)
196 oss << "Component " << i+1 << " called : " << ComponentsList[i] << std::endl;
199 std::list<ParserResourcesClusterMembersType>::iterator it;
200 for(it = ClusterMembersList.begin();
201 it != ClusterMembersList.end();
204 oss << "Cluster member called : " << (*it).HostName << std::endl;
206 std::cout << oss.str() << std::endl;
210 ParserResourcesType::PrintAccessProtocolType() const
212 return protocolToString(Protocol);
216 ParserResourcesType::PrintClusterInternalProtocol() const
218 return protocolToString(ClusterInternalProtocol);
222 ParserResourcesType::PrintAccessModeType() const
224 if (Mode == interactive)
225 return "interactive";
231 ParserResourcesType::PrintBatchType() const
235 else if (Batch == pbs)
237 else if (Batch == lsf)
239 else if (Batch == sge)
241 else if (Batch == ccc)
243 else if (Batch == slurm)
245 else if (Batch == ll)
247 else if (Batch == vishnu)
254 ParserResourcesType::PrintMpiImplType() const
260 else if (mpi == mpich1)
262 else if (mpi == mpich2)
264 else if (mpi == openmpi)
266 else if (mpi == ompi)
268 else if (mpi == slurmmpi)
274 void ParserResourcesType::Clear()
279 ClusterInternalProtocol = rsh;
287 ComponentsList.clear();
290 ClusterMembersList.clear();
292 is_cluster_head = false;
293 working_directory = "";
295 DataForSort._Name = "";
296 DataForSort._nbOfNodes = 1;
297 DataForSort._nbOfProcPerNode = 1;
298 DataForSort._CPUFreqMHz = 0;
299 DataForSort._memInMB = 0;