Back to index

salome-kernel  6.5.0
SALOME_LoadRateManager.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 #include "SALOME_LoadRateManager.hxx"
00024 #include <iostream>
00025 #include <map>
00026 
00027 std::string LoadRateManagerFirst::Find(const std::vector<std::string>& hosts,
00028                                   MapOfParserResourcesType& resList)
00029 {
00030   if (hosts.size() == 0)
00031     return std::string("");
00032 
00033   return std::string(hosts[0]);
00034 }
00035 
00036 std::string LoadRateManagerCycl::Find(const std::vector<std::string>& hosts,
00037                                  MapOfParserResourcesType& resList)
00038 {
00039   static int imachine = 0;
00040   static int iproc = 0;
00041 
00042   // if empty list return empty string
00043   if (hosts.size() == 0)
00044     return std::string("");
00045   else{
00046     ParserResourcesType resource = resList[std::string(hosts[imachine])];
00047     int nbproc = resource.DataForSort._nbOfProcPerNode * resource.DataForSort._nbOfNodes;
00048     if( nbproc <= 0) nbproc = 1;
00049     if( iproc < nbproc ){
00050       iproc++;
00051       return std::string(hosts[imachine]);
00052     }
00053     else{
00054       iproc = 1;
00055       imachine++;
00056       if(imachine >= (int)hosts.size())
00057         imachine = 0;
00058       return std::string(hosts[imachine]);
00059     }
00060   }
00061 }
00062 
00063 std::string LoadRateManagerAltCycl::Find(const std::vector<std::string>& hosts,
00064                                     MapOfParserResourcesType& resList)
00065 {
00066   if (hosts.size() == 0)
00067     return std::string("");
00068 
00069   std::string selected=hosts[0];
00070   int uses=0;
00071   if(_numberOfUses.count(selected) != 0)
00072     uses=_numberOfUses[selected];
00073   else
00074     uses=0;
00075 
00076   for (std::vector<std::string>::const_iterator iter = hosts.begin(); iter != hosts.end(); iter++)
00077     {
00078       std::string machine=*iter;
00079       if(_numberOfUses.count(machine) == 0)
00080         _numberOfUses[machine]=0;
00081       if(_numberOfUses[machine] < uses)
00082         {
00083           selected=machine;
00084           uses=_numberOfUses[machine];
00085         }
00086     }
00087 
00088   _numberOfUses[selected]=_numberOfUses[selected]+1;
00089   //std::cerr << "selected: " << selected << " " << _numberOfUses[selected] << std::endl;
00090   return selected;
00091 }
00092