Salome HOME
Copyrights update
[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/
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()
116 {
117   MESSAGE("##############*****");
118   MESSAGE("HostName : " << DataForSort._hostName);
119   MESSAGE("Alias : " << Alias);
120   MESSAGE("Protocol : " << Protocol);
121   MESSAGE("Mode : " << Mode);
122   MESSAGE("UserName : " << UserName);
123   MESSAGE("Modules : ");
124   int i = 1;
125
126   for (std::map<std::string, std::string>::iterator iter = ModulesPath.begin();
127        iter != ModulesPath.end();
128        iter++)
129     {
130       MESSAGE("Module " << i++ << " called : " << (*iter).first
131               << " with path : " << (*iter).second);
132     }
133
134   MESSAGE("PreReqFilePath : " << PreReqFilePath);
135   MESSAGE("OS : " << OS);
136   DataForSort.Print();
137 }