Salome HOME
Fix compilation pb.
[modules/kernel.git] / src / ResourcesManager / SALOME_ResourcesCatalog_Parser.cxx
1 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 // 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either 
7 // version 2.1 of the License.
8 // 
9 // This library is distributed in the hope that it will be useful 
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 // Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public  
15 // License along with this library; if not, write to the Free Software 
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 //
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 //
20 #include "SALOME_ResourcesCatalog_Parser.hxx"
21 #include "utilities.h"
22 #include <iostream>
23
24 #define NULL_VALUE 0
25
26 using namespace std;
27
28 unsigned int ResourceDataToSort::_nbOfNodesWanted = NULL_VALUE;
29 unsigned int ResourceDataToSort::_nbOfProcPerNodeWanted = NULL_VALUE;
30 unsigned int ResourceDataToSort::_CPUFreqMHzWanted = NULL_VALUE;
31 unsigned int ResourceDataToSort::_memInMBWanted = NULL_VALUE;
32
33 ResourceDataToSort::ResourceDataToSort()
34 {}
35
36 ResourceDataToSort::ResourceDataToSort(const string& hostname,
37                                        unsigned int nbOfNodes,
38                                        unsigned int nbOfProcPerNode,
39                                        unsigned int CPUFreqMHz,
40                                        unsigned int memInMB):
41     _hostName(hostname),
42     _nbOfNodes(nbOfNodes),
43     _nbOfProcPerNode(nbOfProcPerNode),
44     _CPUFreqMHz(CPUFreqMHz),
45     _memInMB(memInMB)
46 {}
47
48 //! Method used by list::sort to sort the resources used in SALOME_ResourcesManager::GetResourcesFitting
49 bool ResourceDataToSort::operator< (const ResourceDataToSort& other) const
50   {
51     unsigned int nbPts = GetNumberOfPoints();
52     return nbPts < other.GetNumberOfPoints();
53   }
54
55 unsigned int ResourceDataToSort::GetNumberOfPoints() const
56   {
57     unsigned int ret = 0;
58     //priority 1 : Nb of nodes
59
60     if (_nbOfNodesWanted != NULL_VALUE)
61       {
62         if (_nbOfNodes == _nbOfNodesWanted)
63           ret += 3000;
64         else if (_nbOfNodes > _nbOfNodesWanted)
65           ret += 2000;
66         else
67           ret += 1000;
68       }
69
70     //priority 2 : Nb of proc by node
71     if (_nbOfProcPerNodeWanted != NULL_VALUE)
72       {
73         if (_nbOfProcPerNode == _nbOfProcPerNodeWanted)
74           ret += 300;
75         else if (_nbOfProcPerNode > _nbOfProcPerNodeWanted)
76           ret += 200;
77         else
78           ret += 100;
79       }
80
81     //priority 3 : Cpu freq
82     if (_CPUFreqMHzWanted != NULL_VALUE)
83       {
84         if (_CPUFreqMHz == _CPUFreqMHzWanted)
85           ret += 30;
86         else if (_CPUFreqMHz > _CPUFreqMHzWanted)
87           ret += 20;
88         else
89           ret += 10;
90       }
91
92     //priority 4 : memory
93     if (_memInMBWanted != NULL_VALUE)
94       {
95         if (_memInMB == _memInMBWanted)
96           ret += 3;
97         else if (_memInMB > _memInMBWanted)
98           ret += 2;
99         else
100           ret += 1;
101       }
102
103     return ret;
104   }
105
106 //! Method used for debug
107 void ResourceDataToSort::Print() const
108   {
109     SCRUTE(_nbOfNodes);
110     SCRUTE(_nbOfProcPerNode);
111     SCRUTE(_CPUFreqMHz);
112     SCRUTE(_memInMB);
113   }
114
115 void ParserResourcesType::Print() const
116 {
117   ostringstream oss;
118   oss << endl <<
119     "HostName : " << DataForSort._hostName << endl << 
120     "Alias : " << Alias << endl <<
121     "NbOfNodes : " << DataForSort._nbOfNodes << endl <<
122     "NbOfProcPerNode : " << DataForSort._nbOfProcPerNode << endl <<
123     "CPUFreqMHz : " << DataForSort._CPUFreqMHz << endl <<
124     "MemInMB : " << DataForSort._memInMB << endl <<
125     "Protocol : " << Protocol << endl <<
126     "Mode : " << Mode << endl <<
127     "Batch : " << Batch << endl <<
128     "mpi : " << mpi << endl <<
129     "UserName : " << UserName << endl <<
130     "AppliPath : " << AppliPath << endl <<
131     "OS : " << OS << endl <<
132     "Modules : " << endl;
133
134   for(int i=0;i<ModulesList.size();i++)
135     oss << "Module " << i+1 << " called : " << ModulesList[i] << endl;
136
137   MESSAGE(oss.str());
138
139 }
140
141 void ParserResourcesType::Clear()
142 {
143   DataForSort._hostName = "";
144   DataForSort._nbOfNodes = 1;
145   DataForSort._nbOfProcPerNode = 1;
146   DataForSort._CPUFreqMHz = 0;
147   DataForSort._memInMB = 0;
148   Alias = "";
149   Protocol = rsh;
150   Mode = interactive;
151   Batch = none;
152   mpi = indif;
153   UserName = "";
154   AppliPath = "";
155   ModulesList.clear();
156   OS = "";
157 }