Salome HOME
Try to kill Salome application when a YACS Launcher job is killed
[modules/kernel.git] / src / ResourcesManager / SALOME_ResourcesCatalog_Parser.cxx
1 // Copyright (C) 2007-2011  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #include "SALOME_ResourcesCatalog_Parser.hxx"
24 #include <iostream>
25 #include <sstream>
26
27 #define NULL_VALUE 0
28
29 unsigned int ResourceDataToSort::_nbOfProcWanted = NULL_VALUE;
30 unsigned int ResourceDataToSort::_nbOfNodesWanted = NULL_VALUE;
31 unsigned int ResourceDataToSort::_nbOfProcPerNodeWanted = NULL_VALUE;
32 unsigned int ResourceDataToSort::_CPUFreqMHzWanted = NULL_VALUE;
33 unsigned int ResourceDataToSort::_memInMBWanted = NULL_VALUE;
34
35 ResourceDataToSort::ResourceDataToSort()
36 {}
37
38 ResourceDataToSort::ResourceDataToSort(const std::string& name,
39                                        unsigned int nbOfNodes,
40                                        unsigned int nbOfProcPerNode,
41                                        unsigned int CPUFreqMHz,
42                                        unsigned int memInMB):
43     _Name(name),
44     _nbOfNodes(nbOfNodes),
45     _nbOfProcPerNode(nbOfProcPerNode),
46     _CPUFreqMHz(CPUFreqMHz),
47     _memInMB(memInMB)
48 {}
49
50 //! Method used by list::sort to sort the resources used in SALOME_ResourcesManager::GetResourcesFitting
51 bool ResourceDataToSort::operator< (const ResourceDataToSort& other) const
52   {
53     unsigned int nbPts = GetNumberOfPoints();
54     return nbPts < other.GetNumberOfPoints();
55   }
56
57 unsigned int ResourceDataToSort::GetNumberOfPoints() const
58   {
59     unsigned int ret = 0;
60     //priority 0 : Nb of proc
61
62     if (_nbOfProcWanted != NULL_VALUE)
63       {
64         unsigned int nb_proc = _nbOfNodes * _nbOfProcPerNode;
65         if (nb_proc == _nbOfProcWanted)
66           ret += 30000;
67         else if (nb_proc > _nbOfProcWanted)
68           ret += 20000;
69         else
70           ret += 10000;
71       }
72
73     //priority 1 : Nb of nodes
74
75     if (_nbOfNodesWanted != NULL_VALUE)
76       {
77         if (_nbOfNodes == _nbOfNodesWanted)
78           ret += 3000;
79         else if (_nbOfNodes > _nbOfNodesWanted)
80           ret += 2000;
81         else
82           ret += 1000;
83       }
84
85     //priority 2 : Nb of proc by node
86     if (_nbOfProcPerNodeWanted != NULL_VALUE)
87       {
88         if (_nbOfProcPerNode == _nbOfProcPerNodeWanted)
89           ret += 300;
90         else if (_nbOfProcPerNode > _nbOfProcPerNodeWanted)
91           ret += 200;
92         else
93           ret += 100;
94       }
95
96     //priority 3 : Cpu freq
97     if (_CPUFreqMHzWanted != NULL_VALUE)
98       {
99         if (_CPUFreqMHz == _CPUFreqMHzWanted)
100           ret += 30;
101         else if (_CPUFreqMHz > _CPUFreqMHzWanted)
102           ret += 20;
103         else
104           ret += 10;
105       }
106
107     //priority 4 : memory
108     if (_memInMBWanted != NULL_VALUE)
109       {
110         if (_memInMB == _memInMBWanted)
111           ret += 3;
112         else if (_memInMB > _memInMBWanted)
113           ret += 2;
114         else
115           ret += 1;
116       }
117
118     //RES_MESSAGE("[GetNumberOfPoints] points number for resource: " << _Name << " " << ret);
119     return ret;
120   }
121
122 //! Method used for debug
123 void ResourceDataToSort::Print() const
124   {
125     std::cout << _nbOfNodes << std::endl;
126     std::cout << _nbOfProcPerNode << std::endl;
127     std::cout << _CPUFreqMHz << std::endl;
128     std::cout << _memInMB << std::endl;
129   }
130
131 void ParserResourcesType::Print()
132 {
133   std::ostringstream oss;
134   oss << std::endl <<
135     "Name : " << Name << std::endl <<
136     "HostName : " << HostName << std::endl << 
137     "NbOfNodes : " << DataForSort._nbOfNodes << std::endl <<
138     "NbOfProcPerNode : " << DataForSort._nbOfProcPerNode << std::endl <<
139     "CPUFreqMHz : " << DataForSort._CPUFreqMHz << std::endl <<
140     "MemInMB : " << DataForSort._memInMB << std::endl <<
141     "Protocol : " << Protocol << std::endl <<
142     "ClusterInternalProtocol : " << ClusterInternalProtocol << std::endl <<
143     "Mode : " << Mode << std::endl <<
144     "Batch : " << Batch << std::endl <<
145     "mpi : " << mpi << std::endl <<
146     "UserName : " << UserName << std::endl <<
147     "AppliPath : " << AppliPath << std::endl <<
148     "OS : " << OS << std::endl <<
149     "batchQueue : " << batchQueue << std::endl <<
150     "userCommands : " << userCommands << std::endl <<
151     "use : " << use << std::endl <<
152     "NbOfProc : " << nbOfProc << std::endl <<
153     "Modules : " << std::endl <<
154     "Components : " << std::endl;
155
156   for(unsigned int i=0;i<ComponentsList.size();i++)
157     oss << "Component " << i+1 << " called : " << ComponentsList[i] << std::endl;
158
159   
160   std::list<ParserResourcesClusterMembersType>::iterator it;
161   for(it = ClusterMembersList.begin(); 
162       it != ClusterMembersList.end();
163       it++)
164   {
165     oss << "Cluster member  called : " << (*it).HostName << std::endl;
166   }
167   std::cout << oss.str() << std::endl;
168 }
169
170 std::string
171 ParserResourcesType::PrintAccessProtocolType() const
172 {
173   if (Protocol == rsh)
174     return "rsh";
175   else if (Protocol == srun)
176     return "srun";
177   else
178     return "ssh";
179 }
180
181 std::string
182 ParserResourcesType::PrintClusterInternalProtocol() const
183 {
184   if (ClusterInternalProtocol == rsh)
185     return "rsh";
186   else if (ClusterInternalProtocol == srun)
187     return "srun";
188   else
189     return "ssh";
190 }
191
192 std::string 
193 ParserResourcesType::PrintAccessModeType() const
194 {
195   if (Mode == interactive)
196     return "interactive";
197   else
198     return "batch";
199 }
200
201 std::string 
202 ParserResourcesType::PrintBatchType() const
203 {
204   if (Batch == none)
205     return "none";
206   else if (Batch == pbs)
207     return "pbs";
208   else if (Batch == lsf)
209     return "lsf";
210   else if (Batch == sge)
211     return "sge";
212   else if (Batch == ccc)
213     return "ccc";
214   else if (Batch == slurm)
215     return "slurm";
216   else if (Batch == ll)
217     return "ll";
218   else 
219     return "ssh";
220 }
221
222 std::string 
223 ParserResourcesType::PrintMpiImplType() const
224 {
225   if (mpi == nompi)
226     return "no mpi";
227   else if (mpi == lam)
228     return "lam";
229   else if (mpi == mpich1)
230     return "mpich1";
231   else if (mpi == mpich2)
232     return "mpich2";
233   else if (mpi == openmpi)
234     return "openmpi";
235   else if (mpi == slurmmpi)
236     return "slurmmpi";
237   else
238     return "prun";
239 }
240
241 void ParserResourcesType::Clear()
242 {
243   Name = "";
244   HostName = "";
245   Protocol = rsh;
246   ClusterInternalProtocol = rsh;
247   Mode = interactive;
248   Batch = none;
249   mpi = nompi;
250   UserName = "";
251   AppliPath = "";
252   batchQueue = "";
253   userCommands = "";
254   ComponentsList.clear();
255   OS = "";
256   use = "";
257   ClusterMembersList.clear();
258   nbOfProc = 1;
259
260   DataForSort._Name = "";
261   DataForSort._nbOfNodes = 1;
262   DataForSort._nbOfProcPerNode = 1;
263   DataForSort._CPUFreqMHz = 0;
264   DataForSort._memInMB = 0;
265 }