]> SALOME platform Git repositories - modules/kernel.git/blob - src/ResourcesManager/SALOME_ResourcesCatalog_Parser.cxx
Salome HOME
PR: merge from branch BR_UnitTests tag mergeto_trunk_17oct05
[modules/kernel.git] / src / ResourcesManager / SALOME_ResourcesCatalog_Parser.cxx
1 #include "SALOME_ResourcesCatalog_Parser.hxx"
2 #include "utilities.h"
3 #include <iostream>
4
5 #define NULL_VALUE 0
6
7 using namespace std;
8
9 unsigned int ResourceDataToSort::_nbOfNodesWanted = NULL_VALUE;
10 unsigned int ResourceDataToSort::_nbOfProcPerNodeWanted = NULL_VALUE;
11 unsigned int ResourceDataToSort::_CPUFreqMHzWanted = NULL_VALUE;
12 unsigned int ResourceDataToSort::_memInMBWanted = NULL_VALUE;
13
14 ResourceDataToSort::ResourceDataToSort()
15 {}
16
17 ResourceDataToSort::ResourceDataToSort(const string& hostname,
18                                        unsigned int nbOfNodes,
19                                        unsigned int nbOfProcPerNode,
20                                        unsigned int CPUFreqMHz,
21                                        unsigned int memInMB):
22     _hostName(hostname),
23     _nbOfNodes(nbOfNodes),
24     _nbOfProcPerNode(nbOfProcPerNode),
25     _CPUFreqMHz(CPUFreqMHz),
26     _memInMB(memInMB)
27 {}
28
29 //! Method used by list::sort to sort the resources used in SALOME_ResourcesManager::GetResourcesFitting
30 bool ResourceDataToSort::operator< (const ResourceDataToSort& other) const
31   {
32     unsigned int nbPts = GetNumberOfPoints();
33     return nbPts < other.GetNumberOfPoints();
34   }
35
36 unsigned int ResourceDataToSort::GetNumberOfPoints() const
37   {
38     unsigned int ret = 0;
39     //priority 1 : Nb of nodes
40
41     if (_nbOfNodesWanted != NULL_VALUE)
42       {
43         if (_nbOfNodes == _nbOfNodesWanted)
44           ret += 3000;
45         else if (_nbOfNodes > _nbOfNodesWanted)
46           ret += 2000;
47         else
48           ret += 1000;
49       }
50
51     //priority 2 : Nb of proc by node
52     if (_nbOfProcPerNodeWanted != NULL_VALUE)
53       {
54         if (_nbOfProcPerNode == _nbOfProcPerNodeWanted)
55           ret += 300;
56         else if (_nbOfProcPerNode > _nbOfProcPerNodeWanted)
57           ret += 200;
58         else
59           ret += 100;
60       }
61
62     //priority 3 : Cpu freq
63     if (_CPUFreqMHzWanted != NULL_VALUE)
64       {
65         if (_CPUFreqMHz == _CPUFreqMHzWanted)
66           ret += 30;
67         else if (_CPUFreqMHz > _CPUFreqMHzWanted)
68           ret += 20;
69         else
70           ret += 10;
71       }
72
73     //priority 4 : memory
74     if (_memInMBWanted != NULL_VALUE)
75       {
76         if (_memInMB == _memInMBWanted)
77           ret += 3;
78         else if (_memInMB > _memInMBWanted)
79           ret += 2;
80         else
81           ret += 1;
82       }
83
84     return ret;
85   }
86
87 //! Method used for debug
88 void ResourceDataToSort::Print() const
89   {
90     SCRUTE(_nbOfNodes);
91     SCRUTE(_nbOfProcPerNode);
92     SCRUTE(_CPUFreqMHz);
93     SCRUTE(_memInMB);
94   }
95
96 void ParserResourcesType::Print()
97 {
98   MESSAGE("##############*****");
99   MESSAGE("HostName : " << DataForSort._hostName);
100   MESSAGE("Alias : " << Alias);
101   MESSAGE("Protocol : " << Protocol);
102   MESSAGE("Mode : " << Mode);
103   MESSAGE("UserName : " << UserName);
104   MESSAGE("Modules : ");
105   int i = 1;
106
107   for (std::map<std::string, std::string>::iterator iter = ModulesPath.begin();
108        iter != ModulesPath.end();
109        iter++)
110     {
111       MESSAGE("Module " << i++ << " called : " << (*iter).first
112               << " with path : " << (*iter).second);
113     }
114
115   MESSAGE("PreReqFilePath : " << PreReqFilePath);
116   MESSAGE("OS : " << OS);
117   DataForSort.Print();
118 }