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