Back to index

salome-kernel  6.5.0
SALOME_ResourcesCatalog_Parser.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_ResourcesCatalog_Parser.hxx"
00024 #include "Utils_SALOME_Exception.hxx"
00025 #include <iostream>
00026 #include <sstream>
00027 
00028 #define NULL_VALUE 0
00029 
00030 unsigned int ResourceDataToSort::_nbOfProcWanted = NULL_VALUE;
00031 unsigned int ResourceDataToSort::_nbOfNodesWanted = NULL_VALUE;
00032 unsigned int ResourceDataToSort::_nbOfProcPerNodeWanted = NULL_VALUE;
00033 unsigned int ResourceDataToSort::_CPUFreqMHzWanted = NULL_VALUE;
00034 unsigned int ResourceDataToSort::_memInMBWanted = NULL_VALUE;
00035 
00036 ResourceDataToSort::ResourceDataToSort()
00037 {}
00038 
00039 ResourceDataToSort::ResourceDataToSort(const std::string& name,
00040                                        unsigned int nbOfNodes,
00041                                        unsigned int nbOfProcPerNode,
00042                                        unsigned int CPUFreqMHz,
00043                                        unsigned int memInMB):
00044     _Name(name),
00045     _nbOfNodes(nbOfNodes),
00046     _nbOfProcPerNode(nbOfProcPerNode),
00047     _CPUFreqMHz(CPUFreqMHz),
00048     _memInMB(memInMB)
00049 {}
00050 
00052 bool ResourceDataToSort::operator< (const ResourceDataToSort& other) const
00053   {
00054     unsigned int nbPts = GetNumberOfPoints();
00055     return nbPts < other.GetNumberOfPoints();
00056   }
00057 
00058 unsigned int ResourceDataToSort::GetNumberOfPoints() const
00059   {
00060     unsigned int ret = 0;
00061     //priority 0 : Nb of proc
00062 
00063     if (_nbOfProcWanted != NULL_VALUE)
00064       {
00065         unsigned int nb_proc = _nbOfNodes * _nbOfProcPerNode;
00066         if (nb_proc == _nbOfProcWanted)
00067           ret += 30000;
00068         else if (nb_proc > _nbOfProcWanted)
00069           ret += 20000;
00070         else
00071           ret += 10000;
00072       }
00073 
00074     //priority 1 : Nb of nodes
00075 
00076     if (_nbOfNodesWanted != NULL_VALUE)
00077       {
00078         if (_nbOfNodes == _nbOfNodesWanted)
00079           ret += 3000;
00080         else if (_nbOfNodes > _nbOfNodesWanted)
00081           ret += 2000;
00082         else
00083           ret += 1000;
00084       }
00085 
00086     //priority 2 : Nb of proc by node
00087     if (_nbOfProcPerNodeWanted != NULL_VALUE)
00088       {
00089         if (_nbOfProcPerNode == _nbOfProcPerNodeWanted)
00090           ret += 300;
00091         else if (_nbOfProcPerNode > _nbOfProcPerNodeWanted)
00092           ret += 200;
00093         else
00094           ret += 100;
00095       }
00096 
00097     //priority 3 : Cpu freq
00098     if (_CPUFreqMHzWanted != NULL_VALUE)
00099       {
00100         if (_CPUFreqMHz == _CPUFreqMHzWanted)
00101           ret += 30;
00102         else if (_CPUFreqMHz > _CPUFreqMHzWanted)
00103           ret += 20;
00104         else
00105           ret += 10;
00106       }
00107 
00108     //priority 4 : memory
00109     if (_memInMBWanted != NULL_VALUE)
00110       {
00111         if (_memInMB == _memInMBWanted)
00112           ret += 3;
00113         else if (_memInMB > _memInMBWanted)
00114           ret += 2;
00115         else
00116           ret += 1;
00117       }
00118 
00119     //RES_MESSAGE("[GetNumberOfPoints] points number for resource: " << _Name << " " << ret);
00120     return ret;
00121   }
00122 
00124 void ResourceDataToSort::Print() const
00125   {
00126     std::cout << _nbOfNodes << std::endl;
00127     std::cout << _nbOfProcPerNode << std::endl;
00128     std::cout << _CPUFreqMHz << std::endl;
00129     std::cout << _memInMB << std::endl;
00130   }
00131 
00132 
00133 std::string ParserResourcesType::protocolToString(AccessProtocolType protocol)
00134 {
00135   switch (protocol)
00136   {
00137   case rsh:
00138     return "rsh";
00139   case ssh:
00140     return "ssh";
00141   case srun:
00142     return "srun";
00143   case pbsdsh:
00144     return "pbsdsh";
00145   case blaunch:
00146     return "blaunch";
00147   default:
00148     throw SALOME_Exception("Unknown protocol");
00149   }
00150 }
00151 
00152 AccessProtocolType ParserResourcesType::stringToProtocol(const std::string & protocolStr)
00153 {
00154   if (protocolStr == "rsh")
00155     return rsh;
00156   else if (protocolStr == "ssh")
00157     return ssh;
00158   else if (protocolStr == "srun")
00159     return srun;
00160   else if (protocolStr == "pbsdsh")
00161     return pbsdsh;
00162   else if (protocolStr == "blaunch")
00163     return blaunch;
00164   else
00165     throw SALOME_Exception("Unknown protocol");
00166 }
00167 
00168 void ParserResourcesType::Print()
00169 {
00170   std::ostringstream oss;
00171   oss << std::endl <<
00172     "Name : " << Name << std::endl <<
00173     "HostName : " << HostName << std::endl << 
00174     "NbOfNodes : " << DataForSort._nbOfNodes << std::endl <<
00175     "NbOfProcPerNode : " << DataForSort._nbOfProcPerNode << std::endl <<
00176     "CPUFreqMHz : " << DataForSort._CPUFreqMHz << std::endl <<
00177     "MemInMB : " << DataForSort._memInMB << std::endl <<
00178     "Protocol : " << protocolToString(Protocol) << std::endl <<
00179     "ClusterInternalProtocol : " << protocolToString(ClusterInternalProtocol) << std::endl <<
00180     "Mode : " << Mode << std::endl <<
00181     "Batch : " << Batch << std::endl <<
00182     "mpi : " << mpi << std::endl <<
00183     "UserName : " << UserName << std::endl <<
00184     "AppliPath : " << AppliPath << std::endl <<
00185     "OS : " << OS << std::endl <<
00186     "batchQueue : " << batchQueue << std::endl <<
00187     "userCommands : " << userCommands << std::endl <<
00188     "use : " << use << std::endl <<
00189     "NbOfProc : " << nbOfProc << std::endl <<
00190     "Modules : " << std::endl <<
00191     "Components : " << std::endl <<
00192     "Is Cluster Head: " << is_cluster_head << std::endl <<
00193     "Working Directory: " << working_directory << std::endl;
00194 
00195   for(unsigned int i=0;i<ComponentsList.size();i++)
00196     oss << "Component " << i+1 << " called : " << ComponentsList[i] << std::endl;
00197 
00198   
00199   std::list<ParserResourcesClusterMembersType>::iterator it;
00200   for(it = ClusterMembersList.begin(); 
00201       it != ClusterMembersList.end();
00202       it++)
00203   {
00204     oss << "Cluster member  called : " << (*it).HostName << std::endl;
00205   }
00206   std::cout << oss.str() << std::endl;
00207 }
00208 
00209 std::string
00210 ParserResourcesType::PrintAccessProtocolType() const
00211 {
00212   return protocolToString(Protocol);
00213 }
00214 
00215 std::string
00216 ParserResourcesType::PrintClusterInternalProtocol() const
00217 {
00218   return protocolToString(ClusterInternalProtocol);
00219 }
00220 
00221 std::string 
00222 ParserResourcesType::PrintAccessModeType() const
00223 {
00224   if (Mode == interactive)
00225     return "interactive";
00226   else
00227     return "batch";
00228 }
00229 
00230 std::string 
00231 ParserResourcesType::PrintBatchType() const
00232 {
00233   if (Batch == none)
00234     return "none";
00235   else if (Batch == pbs)
00236     return "pbs";
00237   else if (Batch == lsf)
00238     return "lsf";
00239   else if (Batch == sge)
00240     return "sge";
00241   else if (Batch == ccc)
00242     return "ccc";
00243   else if (Batch == slurm)
00244     return "slurm";
00245   else if (Batch == ll)
00246     return "ll";
00247   else if (Batch == vishnu)
00248     return "vishnu";
00249   else 
00250     return "ssh";
00251 }
00252 
00253 std::string 
00254 ParserResourcesType::PrintMpiImplType() const
00255 {
00256   if (mpi == nompi)
00257     return "no mpi";
00258   else if (mpi == lam)
00259     return "lam";
00260   else if (mpi == mpich1)
00261     return "mpich1";
00262   else if (mpi == mpich2)
00263     return "mpich2";
00264   else if (mpi == openmpi)
00265     return "openmpi";
00266   else if (mpi == slurmmpi)
00267     return "slurmmpi";
00268   else
00269     return "prun";
00270 }
00271 
00272 void ParserResourcesType::Clear()
00273 {
00274   Name = "";
00275   HostName = "";
00276   Protocol = rsh;
00277   ClusterInternalProtocol = rsh;
00278   Mode = interactive;
00279   Batch = none;
00280   mpi = nompi;
00281   UserName = "";
00282   AppliPath = "";
00283   batchQueue = "";
00284   userCommands = "";
00285   ComponentsList.clear();
00286   OS = "";
00287   use = "";
00288   ClusterMembersList.clear();
00289   nbOfProc = 1;
00290   is_cluster_head = false;
00291   working_directory = "";
00292 
00293   DataForSort._Name = "";
00294   DataForSort._nbOfNodes = 1;
00295   DataForSort._nbOfProcPerNode = 1;
00296   DataForSort._CPUFreqMHz = 0;
00297   DataForSort._memInMB = 0;
00298 }