Salome HOME
merge from branch BR_V5_DEV
[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::_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 string& hostname,
39                                        unsigned int nbOfNodes,
40                                        unsigned int nbOfProcPerNode,
41                                        unsigned int CPUFreqMHz,
42                                        unsigned int memInMB):
43     _hostName(hostname),
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 1 : Nb of nodes
61
62     if (_nbOfNodesWanted != NULL_VALUE)
63       {
64         if (_nbOfNodes == _nbOfNodesWanted)
65           ret += 3000;
66         else if (_nbOfNodes > _nbOfNodesWanted)
67           ret += 2000;
68         else
69           ret += 1000;
70       }
71
72     //priority 2 : Nb of proc by node
73     if (_nbOfProcPerNodeWanted != NULL_VALUE)
74       {
75         if (_nbOfProcPerNode == _nbOfProcPerNodeWanted)
76           ret += 300;
77         else if (_nbOfProcPerNode > _nbOfProcPerNodeWanted)
78           ret += 200;
79         else
80           ret += 100;
81       }
82
83     //priority 3 : Cpu freq
84     if (_CPUFreqMHzWanted != NULL_VALUE)
85       {
86         if (_CPUFreqMHz == _CPUFreqMHzWanted)
87           ret += 30;
88         else if (_CPUFreqMHz > _CPUFreqMHzWanted)
89           ret += 20;
90         else
91           ret += 10;
92       }
93
94     //priority 4 : memory
95     if (_memInMBWanted != NULL_VALUE)
96       {
97         if (_memInMB == _memInMBWanted)
98           ret += 3;
99         else if (_memInMB > _memInMBWanted)
100           ret += 2;
101         else
102           ret += 1;
103       }
104
105     return ret;
106   }
107
108 //! Method used for debug
109 void ResourceDataToSort::Print() const
110   {
111     cout << _nbOfNodes << endl;
112     cout << _nbOfProcPerNode << endl;
113     cout << _CPUFreqMHz << endl;
114     cout << _memInMB << endl;
115   }
116
117 void ParserResourcesType::Print() const
118 {
119   ostringstream oss;
120   oss << endl <<
121     "HostName : " << HostName << endl << 
122     "Alias : " << Alias << endl <<
123     "NbOfNodes : " << DataForSort._nbOfNodes << endl <<
124     "NbOfProcPerNode : " << DataForSort._nbOfProcPerNode << endl <<
125     "CPUFreqMHz : " << DataForSort._CPUFreqMHz << endl <<
126     "MemInMB : " << DataForSort._memInMB << endl <<
127     "Protocol : " << Protocol << endl <<
128     "Mode : " << Mode << endl <<
129     "Batch : " << Batch << endl <<
130     "mpi : " << mpi << endl <<
131     "UserName : " << UserName << endl <<
132     "AppliPath : " << AppliPath << endl <<
133     "OS : " << OS << endl <<
134     "batchQueue : " << batchQueue << endl <<
135     "userCommands : " << userCommands << endl <<
136     "Modules : " << endl;
137
138   for(int i=0;i<ModulesList.size();i++)
139     oss << "Module " << i+1 << " called : " << ModulesList[i] << endl;
140
141   cout << oss.str() << endl;
142
143 }
144
145 void ParserResourcesType::Clear()
146 {
147   DataForSort._hostName = "";
148   DataForSort._nbOfNodes = 1;
149   DataForSort._nbOfProcPerNode = 1;
150   DataForSort._CPUFreqMHz = 0;
151   DataForSort._memInMB = 0;
152   HostName = "";
153   Alias = "";
154   Protocol = rsh;
155   Mode = interactive;
156   Batch = none;
157   mpi = nompi;
158   UserName = "";
159   AppliPath = "";
160   batchQueue = "";
161   userCommands = "";
162   ModulesList.clear();
163   OS = "";
164 }