1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 #include <Batch/Batch_Date.hxx>
25 #include <Batch/Batch_FactBatchManager_eLSF.hxx>
26 #include <Batch/Batch_FactBatchManager_ePBS.hxx>
27 #include <Batch/Batch_BatchManager_eClient.hxx>
28 #include <Batch/Batch_FactBatchManager_eSGE.hxx>
31 #include "SALOME_Launcher_Handler.hxx"
32 #include "Launcher.hxx"
40 //=============================================================================
44 * Define a CORBA single thread policy for the server, which avoid to deal
45 * with non thread-safe usage like Change_Directory in SALOME naming service
47 //=============================================================================
49 Launcher_cpp::Launcher_cpp()
51 #if defined(_DEBUG_) || defined(_DEBUG)
52 cerr << "Launcher_cpp constructor" << endl;
56 //=============================================================================
60 //=============================================================================
62 Launcher_cpp::~Launcher_cpp()
64 #if defined(_DEBUG_) || defined(_DEBUG)
65 cerr << "Launcher_cpp destructor" << endl;
69 std::map < string, Batch::BatchManager_eClient * >::const_iterator it1;
70 for(it1=_batchmap.begin();it1!=_batchmap.end();it1++)
72 std::map < std::pair<std::string,long> , Batch::Job* >::const_iterator it2;
73 for(it2=_jobmap.begin();it2!=_jobmap.end();it2++)
78 //=============================================================================
80 * Submit a batch job on a cluster and returns the JobId
81 * \param xmlExecuteFile : to define the execution on the batch cluster
82 * \param clusterName : name of the batch cluster
84 //=============================================================================
85 long Launcher_cpp::submitJob( const std::string xmlExecuteFile,
86 const std::string clusterName) throw(LauncherException)
89 #if defined(_DEBUG_) || defined(_DEBUG)
90 cout << "BEGIN OF Launcher_cpp::submitJob" << endl;
93 vector<string> aMachineList;
96 throw LauncherException("You must set Resources Manager to Launcher!!");
98 // verify if cluster is in resources catalog
100 params.hostname = clusterName;
102 aMachineList = _ResManager->GetFittingResources(params);
104 catch(const ResourcesException &ex){
105 throw LauncherException(ex.msg.c_str());
107 if (aMachineList.size() == 0)
108 throw LauncherException("This cluster is not in resources catalog");
111 ParseXmlFile(xmlExecuteFile);
113 // verify if clustername is in xml file
114 map<std::string,MachineParameters>::const_iterator it1 = _launch.MachinesList.find(clusterName);
115 if(it1 == _launch.MachinesList.end())
116 throw LauncherException("This cluster is not in xml file");
118 ParserResourcesType p = _ResManager->GetResourcesList(aMachineList[0]);
119 string cname(p.Alias);
120 #if defined(_DEBUG_) || defined(_DEBUG)
121 cout << "Choose cluster: " << cname << endl;
124 // search batch manager for that cluster in map or instanciate one
125 map < string, Batch::BatchManager_eClient * >::const_iterator it2 = _batchmap.find(cname);
126 if(it2 == _batchmap.end())
128 _batchmap[cname] = FactoryBatchManager(p);
129 // TODO: Add a test for the cluster !
134 // directory on cluster to put files to execute
135 string remotedir = _launch.MachinesList[clusterName].WorkDirectory;
136 // local directory to get files to execute and to put results
137 string localdir = _launch.RefDirectory;
139 int idx1 = xmlExecuteFile.find_last_of("/");
140 if(idx1 == string::npos) idx1 = -1;
141 int idx2 = xmlExecuteFile.find(".xml");
142 string logfile = xmlExecuteFile.substr(idx1+1,idx2-idx1-1);
143 string ologfile = logfile + ".output.log";
144 string elogfile = logfile + ".error.log";
146 // create and submit job on cluster
147 Batch::Parametre param;
148 param[USER] = p.UserName;
149 param[EXECUTABLE] = "";
150 for(int i=0; i<_launch.InputFile.size();i++)
151 param[INFILE] += Batch::Couple( localdir + "/" + _launch.InputFile[i], remotedir + "/" + _launch.InputFile[i] );
152 for(int i=0; i<_launch.OutputFile.size();i++)
153 param[OUTFILE] += Batch::Couple( localdir + "/" + _launch.OutputFile[i], remotedir + "/" + _launch.OutputFile[i] );
154 param[OUTFILE] += Batch::Couple( localdir + "/" + ologfile, remotedir + "/" + ologfile );
155 param[OUTFILE] += Batch::Couple( localdir + "/" + elogfile, remotedir + "/" + elogfile );
156 param[NBPROC] = _launch.NbOfProcesses;
157 param[WORKDIR] = remotedir;
158 param[TMPDIR] = remotedir;
159 param[MAXWALLTIME] = getWallTime("");
160 param[MAXRAMSIZE] = getRamSize("");
163 Batch::Environnement env;
164 env["COMMAND"] = _launch.Command;
165 env["SOURCEFILE"] = _launch.MachinesList[clusterName].EnvFile;
166 env["LOGFILE"] = logfile;
168 Batch::Job* job = new Batch::Job(param,env);
170 // submit job on cluster
171 Batch::JobId jid = _batchmap[cname]->submitJob(*job);
173 // get job id in long
174 istringstream iss(jid.getReference());
177 _jobmap[ pair<string,long>(cname,jobId) ] = job;
179 catch(const Batch::EmulationException &ex){
180 throw LauncherException(ex.message.c_str());
185 throw LauncherException("Method Launcher_cpp::submitJob is not available "
186 "(libBatch was not present at compilation time)");
190 //=============================================================================
192 * Submit a batch job on a cluster and returns the JobId
193 * \param fileToExecute : .py/.exe/.sh/... to execute on the batch cluster
194 * \param filesToExport : to export on the batch cluster
195 * \param NumberOfProcessors : Number of processors needed on the batch cluster
196 * \param params : Constraints for the choice of the batch cluster
198 //=============================================================================
199 long Launcher_cpp::submitSalomeJob( const string fileToExecute ,
200 const vector<string>& filesToExport ,
201 const vector<string>& filesToImport ,
202 const batchParams& batch_params,
203 const machineParams& params) throw(LauncherException)
206 #if defined(_DEBUG_) || defined(_DEBUG)
207 cerr << "BEGIN OF Launcher_cpp::submitSalomeJob" << endl;
210 vector<string> aMachineList;
213 throw LauncherException("You must set Resources Manager to Launcher!!");
215 // check batch params
216 if ( !check(batch_params) )
217 throw LauncherException("Batch parameters are bad (see informations above)");
219 // find a cluster matching the structure params
221 aMachineList = _ResManager->GetFittingResources(params);
223 catch(const ResourcesException &ex){
224 throw LauncherException(ex.msg.c_str());
226 if (aMachineList.size() == 0)
227 throw LauncherException("No resources have been found with your parameters");
229 ParserResourcesType p = _ResManager->GetResourcesList(aMachineList[0]);
230 string clustername(p.Alias);
231 #if defined(_DEBUG_) || defined(_DEBUG)
232 cerr << "Choose cluster: " << clustername << endl;
235 // search batch manager for that cluster in map or instanciate one
236 map < string, Batch::BatchManager_eClient * >::const_iterator it = _batchmap.find(clustername);
237 if(it == _batchmap.end())
239 _batchmap[clustername] = FactoryBatchManager(p);
240 // TODO: Add a test for the cluster !
244 // tmp directory on cluster to put files to execute
245 string tmpdir = getTmpDirForBatchFiles();
247 // create and submit job on cluster
248 Batch::Parametre param;
249 param[USER] = p.UserName;
250 param[EXECUTABLE] = buildSalomeCouplingScript(fileToExecute,tmpdir,p);
251 param[INFILE] = Batch::Couple( fileToExecute, getRemoteFile(tmpdir,fileToExecute) );
252 for(int i=0;i<filesToExport.size();i++)
253 param[INFILE] += Batch::Couple( filesToExport[i], getRemoteFile(tmpdir,filesToExport[i]) );
255 param[OUTFILE] = Batch::Couple( "", "~/" + tmpdir + "/" + "output.log*" );
256 param[OUTFILE] += Batch::Couple( "", "~/" + tmpdir + "/" + "error.log*" );
257 param[OUTFILE] += Batch::Couple( "", "~/" + tmpdir + "/" + "YACS_Server*" );
258 for(int i=0;i<filesToImport.size();i++)
259 param[OUTFILE] += Batch::Couple( "", "~/" + tmpdir + "/" + filesToImport[i] );
261 param[NBPROC] = batch_params.nb_proc;
262 param[WORKDIR] = batch_params.batch_directory;
263 param[TMPDIR] = tmpdir;
264 param[MAXWALLTIME] = getWallTime(batch_params.expected_during_time);
265 param[MAXRAMSIZE] = getRamSize(batch_params.mem);
266 param[HOMEDIR] = getHomeDir(p, tmpdir);
267 param[QUEUE] = p.batchQueue;
269 Batch::Environnement env;
271 Batch::Job* job = new Batch::Job(param,env);
273 // submit job on cluster
274 Batch::JobId jid = _batchmap[clustername]->submitJob(*job);
276 // get job id in long
277 istringstream iss(jid.getReference());
280 _jobmap[ pair<string,long>(clustername,jobId) ] = job;
282 catch(const Batch::EmulationException &ex){
283 throw LauncherException(ex.message.c_str());
288 throw LauncherException("Method Launcher_cpp::submitSalomeJob is not available "
289 "(libBatch was not present at compilation time)");
293 //=============================================================================
295 * Query a batch job on a cluster and returns the status of job
296 * \param jobId : identification of Salome job
297 * \param params : Constraints for the choice of the batch cluster
299 //=============================================================================
300 string Launcher_cpp::queryJob( long id,
301 const machineParams& params) throw(LauncherException)
305 throw LauncherException("You must set Resources Manager to Launcher!!");
307 // find a cluster matching params structure
308 vector<string> aMachineList = _ResManager->GetFittingResources( params ) ;
309 ParserResourcesType p = _ResManager->GetResourcesList(aMachineList[0]);
310 string clustername(p.Alias);
312 // search batch manager for that cluster in map
313 std::map < string, Batch::BatchManager_eClient * >::const_iterator it = _batchmap.find(clustername);
314 if(it == _batchmap.end())
315 throw LauncherException("no batchmanager for that cluster");
317 Batch::Parametre par;
321 Batch::JobId jobId( _batchmap[clustername], oss.str() );
323 Batch::JobInfo jinfo = jobId.queryJob();
324 par = jinfo.getParametre();
326 catch(const Batch::EmulationException &ex){
327 throw LauncherException(ex.message.c_str());
332 throw LauncherException("Method Launcher_cpp::queryJob is not available "
333 "(libBatch was not present at compilation time)");
337 string Launcher_cpp::queryJob( long id,
338 const std::string clusterName) throw (LauncherException)
340 machineParams params;
341 params.hostname = clusterName;
342 return queryJob(id,params);
345 //=============================================================================
347 * Delete a batch job on a cluster
348 * \param jobId : identification of Salome job
349 * \param params : Constraints for the choice of the batch cluster
351 //=============================================================================
352 void Launcher_cpp::deleteJob( const long id,
353 const machineParams& params) throw(LauncherException)
357 throw LauncherException("You must set Resources Manager to Launcher!!");
359 // find a cluster matching params structure
360 vector<string> aMachineList = _ResManager->GetFittingResources( params ) ;
361 ParserResourcesType p = _ResManager->GetResourcesList(aMachineList[0]);
362 string clustername(p.Alias);
364 // search batch manager for that cluster in map
365 map < string, Batch::BatchManager_eClient * >::const_iterator it = _batchmap.find(clustername);
366 if(it == _batchmap.end())
367 throw LauncherException("no batchmanager for that cluster");
371 Batch::JobId jobId( _batchmap[clustername], oss.str() );
375 throw LauncherException("Method Launcher_cpp::deleteJob is not available "
376 "(libBatch was not present at compilation time)");
380 void Launcher_cpp::deleteJob( long id,
381 const std::string clusterName) throw (LauncherException)
383 machineParams params;
384 params.hostname = clusterName;
385 deleteJob(id,params);
388 //=============================================================================
390 * Get result files of job on a cluster
391 * \param jobId : identification of Salome job
392 * \param params : Constraints for the choice of the batch cluster
394 //=============================================================================
395 void Launcher_cpp::getResultsJob( const string directory,
397 const machineParams& params) throw(LauncherException)
401 throw LauncherException("You must set Resources Manager to Launcher!!");
403 vector<string> aMachineList = _ResManager->GetFittingResources( params ) ;
404 ParserResourcesType p = _ResManager->GetResourcesList(aMachineList[0]);
405 string clustername(p.Alias);
407 // search batch manager for that cluster in map
408 map < string, Batch::BatchManager_eClient * >::const_iterator it = _batchmap.find(clustername);
409 if(it == _batchmap.end())
410 throw LauncherException("no batchmanager for that cluster");
412 Batch::Job* job = _jobmap[ pair<string,long>(clustername,id) ];
414 _batchmap[clustername]->importOutputFiles( *job, directory );
416 throw LauncherException("Method Launcher_cpp::getResultsJob is not available "
417 "(libBatch was not present at compilation time)");
421 void Launcher_cpp::getResultsJob( const std::string directory,
423 const std::string clusterName) throw (LauncherException)
425 machineParams params;
426 params.hostname = clusterName;
427 getResultsJob(directory,id,params);
430 //=============================================================================
432 * Factory to instanciate the good batch manager for choosen cluster.
434 //=============================================================================
436 Batch::BatchManager_eClient *Launcher_cpp::FactoryBatchManager( const ParserResourcesType& params ) throw(LauncherException)
439 std::string hostname, mpi;
440 Batch::CommunicationProtocolType protocol;
441 Batch::FactBatchManager_eClient* fact;
443 hostname = params.Alias;
444 switch(params.Protocol){
446 protocol = Batch::RSH;
449 protocol = Batch::SSH;
452 throw LauncherException("unknown protocol");
475 throw LauncherException("you must specified an mpi implementation for batch manager");
478 throw LauncherException("unknown mpi implementation");
481 #if defined(_DEBUG_) || defined(_DEBUG)
482 cerr << "Instanciation of batch manager" << endl;
484 switch( params.Batch ){
486 #if defined(_DEBUG_) || defined(_DEBUG)
487 cerr << "Instantiation of PBS batch manager" << endl;
489 fact = new Batch::FactBatchManager_ePBS;
492 #if defined(_DEBUG_) || defined(_DEBUG)
493 cerr << "Instantiation of LSF batch manager" << endl;
495 fact = new Batch::FactBatchManager_eLSF;
498 #if defined(_DEBUG_) || defined(_DEBUG)
499 cout << "Instantiation of SGE batch manager" << endl;
501 fact = new Batch::FactBatchManager_eSGE;
504 #if defined(_DEBUG_) || defined(_DEBUG)
505 cerr << "BATCH = " << params.Batch << endl;
507 throw LauncherException("no batchmanager for that cluster");
509 return (*fact)(hostname.c_str(), protocol, mpi.c_str());
511 throw LauncherException("Method Launcher_cpp::FactoryBatchManager is not available "
512 "(libBatch was not present at compilation time)");
516 string Launcher_cpp::buildSalomeCouplingScript(const string fileToExecute, const string dirForTmpFiles, const ParserResourcesType& params)
519 #ifndef WIN32 //TODO: need for porting on Windows
520 int idx = dirForTmpFiles.find("Batch/");
521 std::string filelogtemp = dirForTmpFiles.substr(idx+6, dirForTmpFiles.length());
522 std::string dfilelogtemp = params.AppliPath + "/" + filelogtemp;
524 string::size_type p1 = fileToExecute.find_last_of("/");
525 string::size_type p2 = fileToExecute.find_last_of(".");
526 std::string fileNameToExecute = fileToExecute.substr(p1+1,p2-p1-1);
527 std::string TmpFileName = "/tmp/runSalome_" + fileNameToExecute + ".sh";
529 MpiImpl* mpiImpl = FactoryMpiImpl(params.mpi);
531 ofstream tempOutputFile;
532 tempOutputFile.open(TmpFileName.c_str(), ofstream::out );
535 tempOutputFile << "#! /bin/sh -f" << endl ;
536 tempOutputFile << "cd ~/" ;
537 tempOutputFile << dirForTmpFiles << endl ;
538 tempOutputFile << "export SALOME_BATCH=1\n";
539 tempOutputFile << "export PYTHONPATH=~/" ;
540 tempOutputFile << dirForTmpFiles ;
541 tempOutputFile << ":$PYTHONPATH" << endl ;
543 // Adding user script
544 std::string script = params.userCommands;
546 tempOutputFile << script << endl;
548 tempOutputFile << "if test \"" ;
549 tempOutputFile << mpiImpl->rank() ;
550 tempOutputFile << "\" = \"0\"; then" << endl ;
552 // -----------------------------------------------
553 // Code for rank 0 : launch runAppli and a container
555 if(params.ModulesList.size()>0)
556 tempOutputFile << " " << params.AppliPath << "/runAppli --terminal --modules=" ;
558 tempOutputFile << " " << params.AppliPath << "/runAppli --terminal ";
559 for ( int i = 0 ; i < params.ModulesList.size() ; i++ ) {
560 tempOutputFile << params.ModulesList[i] ;
561 if ( i != params.ModulesList.size()-1 )
562 tempOutputFile << "," ;
564 tempOutputFile << " --standalone=registry,study,moduleCatalog --ns-port-log="
568 // Wait NamingService
569 tempOutputFile << " current=0\n"
571 << " while ! test -f " << dfilelogtemp << "\n"
574 << " let current=current+1\n"
575 << " if [ \"$current\" -eq \"$stop\" ] ; then\n"
576 << " echo Error Naming Service failed ! >&2"
580 << " port=`cat " << dfilelogtemp << "`\n";
582 // Wait other containers
583 tempOutputFile << " for ((ip=1; ip < ";
584 tempOutputFile << mpiImpl->size();
585 tempOutputFile << " ; ip++))" << endl;
586 tempOutputFile << " do" << endl ;
587 tempOutputFile << " arglist=\"$arglist YACS_Server_\"$ip" << endl ;
588 tempOutputFile << " done" << endl ;
589 tempOutputFile << " sleep 5" << endl ;
590 tempOutputFile << " " << params.AppliPath << "/runSession waitContainers.py $arglist" << endl ;
592 // Launch user script
593 tempOutputFile << " " << params.AppliPath << "/runSession python ~/" << dirForTmpFiles << "/" << fileNameToExecute << ".py" << endl;
596 tempOutputFile << " rm " << dfilelogtemp << "\n"
597 << " " << params.AppliPath << "/runSession shutdownSalome.py" << endl;
599 // -------------------------------------
600 // Other nodes launch a container
601 tempOutputFile << "else" << endl ;
603 // Wait NamingService
604 tempOutputFile << " current=0\n"
606 << " while ! test -f " << dfilelogtemp << "\n"
609 << " let current=current+1\n"
610 << " if [ \"$current\" -eq \"$stop\" ] ; then\n"
611 << " echo Error Naming Service failed ! >&2"
615 << " port=`cat " << dfilelogtemp << "`\n";
617 // Launching container
618 tempOutputFile << " " << params.AppliPath << "/runSession SALOME_Container YACS_Server_";
619 tempOutputFile << mpiImpl->rank()
620 << " > ~/" << dirForTmpFiles << "/YACS_Server_"
621 << mpiImpl->rank() << "_container_log." << filelogtemp
623 tempOutputFile << "fi" << endl ;
624 tempOutputFile.flush();
625 tempOutputFile.close();
626 chmod(TmpFileName.c_str(), 0x1ED);
627 #if defined(_DEBUG_) || defined(_DEBUG)
628 cerr << TmpFileName.c_str() << endl;
639 throw LauncherException("Method Launcher_cpp::buildSalomeCouplingScript is not available "
640 "(libBatch was not present at compilation time)");
644 MpiImpl *Launcher_cpp::FactoryMpiImpl(MpiImplType mpi) throw(LauncherException)
649 return new MpiImpl_LAM();
651 return new MpiImpl_MPICH1();
653 return new MpiImpl_MPICH2();
655 return new MpiImpl_OPENMPI();
657 return new MpiImpl_SLURM();
659 return new MpiImpl_PRUN();
661 throw LauncherException("you must specify an mpi implementation for batch manager");
664 oss << mpi << " : not yet implemented";
665 throw LauncherException(oss.str().c_str());
668 throw LauncherException("Method Launcher_cpp::FactoryMpiImpl is not available "
669 "(libBatch was not present at compilation time)");
673 string Launcher_cpp::getTmpDirForBatchFiles()
679 // Adding date to the directory name
680 Batch::Date date = Batch::Date(time(0));
681 thedate = date.str();
682 int lend = thedate.size() ;
685 if ( thedate[i] == '/' || thedate[i] == '-' || thedate[i] == ':' ) {
691 ret = string("Batch/");
695 throw LauncherException("Method Launcher_cpp::getTmpDirForBatchFiles is not available "
696 "(libBatch was not present at compilation time)");
700 string Launcher_cpp::getRemoteFile( std::string remoteDir, std::string localFile )
702 string::size_type pos = localFile.find_last_of("/") + 1;
703 int ln = localFile.length() - pos;
704 string remoteFile = remoteDir + "/" + localFile.substr(pos,ln);
708 bool Launcher_cpp::check(const batchParams& batch_params)
711 #if defined(_DEBUG_) || defined(_DEBUG)
712 cerr << "Job parameters are :" << endl;
713 cerr << "Directory : $HOME/Batch/$date" << endl;
716 // check expected_during_time (check the format)
717 std::string edt_info = batch_params.expected_during_time;
718 std::string edt_value = batch_params.expected_during_time;
719 if (edt_value != "") {
720 std::string begin_edt_value = edt_value.substr(0, 2);
721 std::string mid_edt_value = edt_value.substr(2, 1);
722 std::string end_edt_value = edt_value.substr(3);
725 std::istringstream iss(begin_edt_value);
726 if (!(iss >> value)) {
727 edt_info = "Error on definition ! : " + edt_value;
730 else if (value < 0) {
731 edt_info = "Error on definition time is negative ! : " + value;
734 std::istringstream iss_2(end_edt_value);
735 if (!(iss_2 >> value)) {
736 edt_info = "Error on definition ! : " + edt_value;
739 else if (value < 0) {
740 edt_info = "Error on definition time is negative ! : " + value;
743 if (mid_edt_value != ":") {
744 edt_info = "Error on definition ! :" + edt_value;
749 edt_info = "No value given";
751 #if defined(_DEBUG_) || defined(_DEBUG)
752 cerr << "Expected during time : " << edt_info << endl;;
755 // check memory (check the format)
756 std::string mem_info;
757 std::string mem_value = batch_params.mem;
758 if (mem_value != "") {
759 std::string begin_mem_value = mem_value.substr(0, mem_value.length()-2);
761 std::istringstream iss(begin_mem_value);
762 if (!(iss >> re_mem_value)) {
763 mem_info = "Error on definition ! : " + mem_value;
766 else if (re_mem_value <= 0) {
767 mem_info = "Error on definition memory is negative ! : " + mem_value;
770 std::string end_mem_value = mem_value.substr(mem_value.length()-2);
771 if (end_mem_value != "gb" && end_mem_value != "mb") {
772 mem_info = "Error on definition, type is bad ! " + mem_value;
777 mem_info = "No value given";
779 #if defined(_DEBUG_) || defined(_DEBUG)
780 cerr << "Memory : " << mem_info << endl;
784 std::string nb_proc_info;
785 ostringstream nb_proc_value;
786 nb_proc_value << batch_params.nb_proc;
787 if(batch_params.nb_proc <= 0) {
788 nb_proc_info = "Bad value ! nb_proc = ";
789 nb_proc_info += nb_proc_value.str();
793 nb_proc_info = nb_proc_value.str();
795 #if defined(_DEBUG_) || defined(_DEBUG)
796 cerr << "Nb of processors : " << nb_proc_info << endl;
802 long Launcher_cpp::getWallTime(std::string edt)
806 if( edt.size() == 0 )
809 string::size_type pos = edt.find(":");
810 string h = edt.substr(0,pos);
811 string m = edt.substr(pos+1,edt.size()-pos+1);
812 istringstream issh(h);
814 istringstream issm(m);
820 long Launcher_cpp::getRamSize(std::string mem)
824 if( mem.size() == 0 )
827 string ram = mem.substr(0,mem.size()-2);
828 istringstream iss(ram);
830 string unity = mem.substr(mem.size()-2,2);
831 if( (unity.find("gb") != string::npos) || (unity.find("GB") != string::npos) )
833 else if( (unity.find("mb") != string::npos) || (unity.find("MB") != string::npos) )
835 else if( (unity.find("kb") != string::npos) || (unity.find("KB") != string::npos) )
837 else if( (unity.find("b") != string::npos) || (unity.find("B") != string::npos) )
838 return mv/(1024*1024);
843 void Launcher_cpp::ParseXmlFile(string xmlExecuteFile)
845 SALOME_Launcher_Handler* handler = new SALOME_Launcher_Handler(_launch);
847 const char* aFilePath = xmlExecuteFile.c_str();
848 FILE* aFile = fopen(aFilePath, "r");
852 xmlDocPtr aDoc = xmlReadFile(aFilePath, NULL, 0);
855 handler->ProcessXmlDocument(aDoc);
857 #if defined(_DEBUG_) || defined(_DEBUG)
858 cout << "ResourcesManager_cpp: could not parse file "<< aFilePath << endl;
868 #if defined(_DEBUG_) || defined(_DEBUG)
869 cout << "Launcher_cpp: file "<<aFilePath<<" is not readable." << endl;
877 std::string Launcher_cpp::getHomeDir(const ParserResourcesType& p, const std::string& tmpdir)
881 int idx = tmpdir.find("Batch/");
882 std::string filelogtemp = tmpdir.substr(idx+6, tmpdir.length());
883 filelogtemp = "/tmp/logs" + filelogtemp + "_home";
885 if( p.Protocol == rsh )
887 else if( p.Protocol == ssh )
890 throw LauncherException("Unknown protocol");
891 if (p.UserName != ""){
892 command += p.UserName;
896 command += " 'echo $HOME' > ";
897 command += filelogtemp;
898 #if defined(_DEBUG_) || defined(_DEBUG)
899 std::cerr << command.c_str() << std::endl;
901 int status = system(command.c_str());
903 throw LauncherException("Error of launching home command on remote host");
905 std::ifstream file_home(filelogtemp.c_str());
906 std::getline(file_home, home);