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