Salome HOME
CCAR:
[modules/kernel.git] / src / ResourcesManager / SALOME_LoadRateManager.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_LoadRateManager.hxx"
23 #include <iostream>
24 #include <map>
25
26 using namespace std;
27
28 string LoadRateManagerFirst::Find(const vector<string>& hosts,
29                                   MapOfParserResourcesType& resList)
30 {
31   if (hosts.size() == 0)
32     return string("");
33
34   return string(hosts[0]);
35 }
36
37 string LoadRateManagerCycl::Find(const vector<string>& hosts,
38                                  MapOfParserResourcesType& resList)
39 {
40   static int imachine = 0;
41   static int iproc = 0;
42
43   // if empty list return empty string
44   if (hosts.size() == 0)
45     return string("");
46   else{
47     ParserResourcesType resource = resList[string(hosts[imachine])];
48     int nbproc = resource.DataForSort._nbOfProcPerNode * resource.DataForSort._nbOfNodes;
49     if( nbproc <= 0) nbproc = 1;
50     if( iproc < nbproc ){
51       iproc++;
52       return string(hosts[imachine]);
53     }
54     else{
55       iproc = 1;
56       imachine++;
57       if(imachine >= hosts.size())
58         imachine = 0;
59       return string(hosts[imachine]);
60     }
61   }
62 }
63
64 string LoadRateManagerAltCycl::Find(const vector<string>& hosts,
65                                     MapOfParserResourcesType& resList)
66 {
67   if (hosts.size() == 0)
68     return string("");
69
70   std::string selected=hosts[0];
71   int uses=0;
72   if(_numberOfUses.count(selected) != 0)
73     uses=_numberOfUses[selected];
74   else
75     uses=0;
76
77   for (std::vector<std::string>::const_iterator iter = hosts.begin(); iter != hosts.end(); iter++)
78     {
79       std::string machine=*iter;
80       if(_numberOfUses.count(machine) == 0)
81         _numberOfUses[machine]=0;
82       if(_numberOfUses[machine] < uses)
83         {
84           selected=machine;
85           uses=_numberOfUses[machine];
86         }
87     }
88
89   _numberOfUses[selected]=_numberOfUses[selected]+1;
90   std::cerr << "selected: " << selected << " " << _numberOfUses[selected] << std::endl;
91   return selected;
92 }
93