-// Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
-//
-// This library is distributed in the hope that it will be useful
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
+// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
//
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
#include "SALOME_LoadRateManager.hxx"
-#include "utilities.h"
#include <iostream>
#include <map>
using namespace std;
-string SALOME_LoadRateManager::FindFirst(const Engines::MachineList& hosts)
+string LoadRateManagerFirst::Find(const vector<string>& hosts,
+ MapOfParserResourcesType& resList)
{
- MESSAGE("SALOME_LoadRateManager::FindFirst " << hosts.length());
-
- if (hosts.length() == 0)
+ if (hosts.size() == 0)
return string("");
return string(hosts[0]);
}
-string SALOME_LoadRateManager::FindNext(const Engines::MachineList& hosts,MapOfParserResourcesType& resList,SALOME_NamingService *ns)
+string LoadRateManagerCycl::Find(const vector<string>& hosts,
+ MapOfParserResourcesType& resList)
{
- MESSAGE("SALOME_LoadRateManager::FindNext " << hosts.length());
- map<string, int> machines;
+ static int imachine = 0;
+ static int iproc = 0;
- if (hosts.length() == 0)
+ // if empty list return empty string
+ if (hosts.size() == 0)
return string("");
+ else{
+ ParserResourcesType resource = resList[string(hosts[imachine])];
+ int nbproc = resource.DataForSort._nbOfProcPerNode * resource.DataForSort._nbOfNodes;
+ if( nbproc <= 0) nbproc = 1;
+ if( iproc < nbproc ){
+ iproc++;
+ return string(hosts[imachine]);
+ }
+ else{
+ iproc = 1;
+ imachine++;
+ if(imachine >= hosts.size())
+ imachine = 0;
+ return string(hosts[imachine]);
+ }
+ }
+}
- for(int i=0;i<hosts.length();i++)
- machines[string(hosts[i])] = 0;
+string LoadRateManagerAltCycl::Find(const vector<string>& hosts,
+ MapOfParserResourcesType& resList)
+{
+ if (hosts.size() == 0)
+ return string("");
- ns->Change_Directory("/Containers");
- vector<string> vec = ns->list_directory_recurs();
- Engines::Container_var cont;
- for(vector<string>::iterator iter = vec.begin();iter!=vec.end();iter++){
- try
- {
- CORBA::Object_var obj=ns->Resolve((*iter).c_str());
- cont=Engines::Container::_narrow(obj);
- }
- catch(CORBA::SystemException& ex)
- {
- MESSAGE("SALOME_LoadRateManager::FindNext CORBA::SystemException ignore it");
- continue;
- }
- if(!CORBA::is_nil(cont)){
- try
- {
- CORBA::String_var hostname = cont->getHostName();
- std::string mach=(const char*)hostname;
- machines[mach]++;
- }
- catch(CORBA::SystemException& ex)
+ std::string selected=hosts[0];
+ int uses=0;
+ if(_numberOfUses.count(selected) != 0)
+ uses=_numberOfUses[selected];
+ else
+ uses=0;
+
+ for (std::vector<std::string>::const_iterator iter = hosts.begin(); iter != hosts.end(); iter++)
+ {
+ std::string machine=*iter;
+ if(_numberOfUses.count(machine) == 0)
+ _numberOfUses[machine]=0;
+ if(_numberOfUses[machine] < uses)
{
- MESSAGE("SALOME_LoadRateManager::FindNext CORBA::SystemException ignore it");
- continue;
+ selected=machine;
+ uses=_numberOfUses[machine];
}
}
- }
- int imin = 0;
- ParserResourcesType resource = resList[string(hosts[0])];
- int nbproc = resource.DataForSort._nbOfProcPerNode * resource.DataForSort._nbOfNodes;
- int min = machines[string(hosts[0])]/nbproc;
- for(int i=1;i<hosts.length();i++){
- resource = resList[string(hosts[i])];
- nbproc = resource.DataForSort._nbOfProcPerNode * resource.DataForSort._nbOfNodes;
- if( machines[string(hosts[i])]/nbproc < min ){
- imin = i;
- min = machines[string(hosts[i])]/nbproc;
- }
- }
-
- return string(hosts[imin]);
+ _numberOfUses[selected]=_numberOfUses[selected]+1;
+ std::cerr << "selected: " << selected << " " << _numberOfUses[selected] << std::endl;
+ return selected;
}
-string SALOME_LoadRateManager::FindBest(const Engines::MachineList& hosts) throw (SALOME_Exception)
-{
- // for the moment then "maui" will be used for dynamic selection ...
- MESSAGE("SALOME_LoadRateManager::FindBest " << hosts.length());
- throw(SALOME_Exception(LOCALIZED("not yet implemented")));
- return string("");
-}