Salome HOME
0022232: [CEA 837] Memory corruption in GEOM/SMESH that leads to segfault on debian64
[modules/kernel.git] / src / ResourcesManager / SALOME_LoadRateManager.cxx
1 // Copyright (C) 2007-2013  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
23 #include "SALOME_LoadRateManager.hxx"
24 #include <iostream>
25 #include <map>
26
27 std::string LoadRateManagerFirst::Find(const std::vector<std::string>& hosts,
28                                   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                                  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     ParserResourcesType resource = resList[std::string(hosts[imachine])];
47     int nbproc = resource.DataForSort._nbOfProcPerNode * resource.DataForSort._nbOfNodes;
48     if( nbproc <= 0) nbproc = 1;
49     if( iproc < nbproc ){
50       iproc++;
51       return std::string(hosts[imachine]);
52     }
53     else{
54       iproc = 1;
55       imachine++;
56       if(imachine >= (int)hosts.size())
57         imachine = 0;
58       return std::string(hosts[imachine]);
59     }
60   }
61 }
62
63 std::string LoadRateManagerAltCycl::Find(const std::vector<std::string>& hosts,
64                                     MapOfParserResourcesType& resList)
65 {
66   if (hosts.size() == 0)
67     return std::string("");
68
69   std::string selected=hosts[0];
70   int uses=0;
71   if(_numberOfUses.count(selected) != 0)
72     uses=_numberOfUses[selected];
73   else
74     uses=0;
75
76   for (std::vector<std::string>::const_iterator iter = hosts.begin(); iter != hosts.end(); iter++)
77     {
78       std::string machine=*iter;
79       if(_numberOfUses.count(machine) == 0)
80         _numberOfUses[machine]=0;
81       if(_numberOfUses[machine] < uses)
82         {
83           selected=machine;
84           uses=_numberOfUses[machine];
85         }
86     }
87
88   _numberOfUses[selected]=_numberOfUses[selected]+1;
89   //std::cerr << "selected: " << selected << " " << _numberOfUses[selected] << std::endl;
90   return selected;
91 }
92