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 ostringstream file_name_output;
256 file_name_output << "~/" << tmpdir << "/" << "output.log*";
257 ostringstream file_name_error;
258 file_name_error << "~/" << tmpdir << "/" << "error.log*";
259 ostringstream file_container_log;
260 file_container_log << "~/" << tmpdir << "/" << "YACS_Server*";
261 param[OUTFILE] = Batch::Couple( "", file_name_output.str());
262 param[OUTFILE] += Batch::Couple( "", file_name_error.str());
263 param[OUTFILE] += Batch::Couple( "", file_container_log.str());
265 for(int i=0;i<filesToImport.size();i++)
266 param[OUTFILE] += Batch::Couple( "", filesToImport[i] );
268 param[NBPROC] = batch_params.nb_proc;
269 param[WORKDIR] = batch_params.batch_directory;
270 param[TMPDIR] = tmpdir;
271 param[MAXWALLTIME] = getWallTime(batch_params.expected_during_time);
272 param[MAXRAMSIZE] = getRamSize(batch_params.mem);
273 param[HOMEDIR] = getHomeDir(p, tmpdir);
274 param[QUEUE] = p.batchQueue;
276 Batch::Environnement env;
278 Batch::Job* job = new Batch::Job(param,env);
280 // submit job on cluster
281 Batch::JobId jid = _batchmap[clustername]->submitJob(*job);
283 // get job id in long
284 istringstream iss(jid.getReference());
287 _jobmap[ pair<string,long>(clustername,jobId) ] = job;
289 catch(const Batch::EmulationException &ex){
290 throw LauncherException(ex.message.c_str());
295 throw LauncherException("Method Launcher_cpp::submitSalomeJob is not available "
296 "(libBatch was not present at compilation time)");
300 //=============================================================================
302 * Query a batch job on a cluster and returns the status of job
303 * \param jobId : identification of Salome job
304 * \param params : Constraints for the choice of the batch cluster
306 //=============================================================================
307 string Launcher_cpp::queryJob( long id,
308 const machineParams& params) throw(LauncherException)
312 throw LauncherException("You must set Resources Manager to Launcher!!");
314 // find a cluster matching params structure
315 vector<string> aMachineList = _ResManager->GetFittingResources( params ) ;
316 ParserResourcesType p = _ResManager->GetResourcesList(aMachineList[0]);
317 string clustername(p.Alias);
319 // search batch manager for that cluster in map
320 std::map < string, Batch::BatchManager_eClient * >::const_iterator it = _batchmap.find(clustername);
321 if(it == _batchmap.end())
322 throw LauncherException("no batchmanager for that cluster");
324 Batch::Parametre par;
328 Batch::JobId jobId( _batchmap[clustername], oss.str() );
330 Batch::JobInfo jinfo = jobId.queryJob();
331 par = jinfo.getParametre();
333 catch(const Batch::EmulationException &ex){
334 throw LauncherException(ex.message.c_str());
339 throw LauncherException("Method Launcher_cpp::queryJob is not available "
340 "(libBatch was not present at compilation time)");
344 string Launcher_cpp::queryJob( long id,
345 const std::string clusterName) throw (LauncherException)
347 machineParams params;
348 params.hostname = clusterName;
349 return queryJob(id,params);
352 //=============================================================================
354 * Delete a batch job on a cluster
355 * \param jobId : identification of Salome job
356 * \param params : Constraints for the choice of the batch cluster
358 //=============================================================================
359 void Launcher_cpp::deleteJob( const long id,
360 const machineParams& params) throw(LauncherException)
364 throw LauncherException("You must set Resources Manager to Launcher!!");
366 // find a cluster matching params structure
367 vector<string> aMachineList = _ResManager->GetFittingResources( params ) ;
368 ParserResourcesType p = _ResManager->GetResourcesList(aMachineList[0]);
369 string clustername(p.Alias);
371 // search batch manager for that cluster in map
372 map < string, Batch::BatchManager_eClient * >::const_iterator it = _batchmap.find(clustername);
373 if(it == _batchmap.end())
374 throw LauncherException("no batchmanager for that cluster");
378 Batch::JobId jobId( _batchmap[clustername], oss.str() );
382 throw LauncherException("Method Launcher_cpp::deleteJob is not available "
383 "(libBatch was not present at compilation time)");
387 void Launcher_cpp::deleteJob( long id,
388 const std::string clusterName) throw (LauncherException)
390 machineParams params;
391 params.hostname = clusterName;
392 deleteJob(id,params);
395 //=============================================================================
397 * Get result files of job on a cluster
398 * \param jobId : identification of Salome job
399 * \param params : Constraints for the choice of the batch cluster
401 //=============================================================================
402 void Launcher_cpp::getResultsJob( const string directory,
404 const machineParams& params) throw(LauncherException)
408 throw LauncherException("You must set Resources Manager to Launcher!!");
410 vector<string> aMachineList = _ResManager->GetFittingResources( params ) ;
411 ParserResourcesType p = _ResManager->GetResourcesList(aMachineList[0]);
412 string clustername(p.Alias);
414 // search batch manager for that cluster in map
415 map < string, Batch::BatchManager_eClient * >::const_iterator it = _batchmap.find(clustername);
416 if(it == _batchmap.end())
417 throw LauncherException("no batchmanager for that cluster");
419 Batch::Job* job = _jobmap[ pair<string,long>(clustername,id) ];
421 _batchmap[clustername]->importOutputFiles( *job, directory );
423 throw LauncherException("Method Launcher_cpp::getResultsJob is not available "
424 "(libBatch was not present at compilation time)");
428 void Launcher_cpp::getResultsJob( const std::string directory,
430 const std::string clusterName) throw (LauncherException)
432 machineParams params;
433 params.hostname = clusterName;
434 getResultsJob(directory,id,params);
437 //=============================================================================
439 * Factory to instanciate the good batch manager for choosen cluster.
441 //=============================================================================
443 Batch::BatchManager_eClient *Launcher_cpp::FactoryBatchManager( const ParserResourcesType& params ) throw(LauncherException)
446 std::string hostname, mpi;
447 Batch::CommunicationProtocolType protocol;
448 Batch::FactBatchManager_eClient* fact;
450 hostname = params.Alias;
451 switch(params.Protocol){
453 protocol = Batch::RSH;
456 protocol = Batch::SSH;
459 throw LauncherException("unknown protocol");
482 throw LauncherException("you must specified an mpi implementation for batch manager");
485 throw LauncherException("unknown mpi implementation");
488 #if defined(_DEBUG_) || defined(_DEBUG)
489 cerr << "Instanciation of batch manager" << endl;
491 switch( params.Batch ){
493 #if defined(_DEBUG_) || defined(_DEBUG)
494 cerr << "Instantiation of PBS batch manager" << endl;
496 fact = new Batch::FactBatchManager_ePBS;
499 #if defined(_DEBUG_) || defined(_DEBUG)
500 cerr << "Instantiation of LSF batch manager" << endl;
502 fact = new Batch::FactBatchManager_eLSF;
505 #if defined(_DEBUG_) || defined(_DEBUG)
506 cout << "Instantiation of SGE batch manager" << endl;
508 fact = new Batch::FactBatchManager_eSGE;
511 #if defined(_DEBUG_) || defined(_DEBUG)
512 cerr << "BATCH = " << params.Batch << endl;
514 throw LauncherException("no batchmanager for that cluster");
516 return (*fact)(hostname.c_str(), protocol, mpi.c_str());
518 throw LauncherException("Method Launcher_cpp::FactoryBatchManager is not available "
519 "(libBatch was not present at compilation time)");
523 string Launcher_cpp::buildSalomeCouplingScript(const string fileToExecute, const string dirForTmpFiles, const ParserResourcesType& params)
526 #ifndef WIN32 //TODO: need for porting on Windows
527 int idx = dirForTmpFiles.find("Batch/");
528 std::string filelogtemp = dirForTmpFiles.substr(idx+6, dirForTmpFiles.length());
529 std::string dfilelogtemp = params.AppliPath + "/" + filelogtemp;
531 string::size_type p1 = fileToExecute.find_last_of("/");
532 string::size_type p2 = fileToExecute.find_last_of(".");
533 std::string fileNameToExecute = fileToExecute.substr(p1+1,p2-p1-1);
534 std::string TmpFileName = "/tmp/runSalome_" + fileNameToExecute + ".sh";
536 MpiImpl* mpiImpl = FactoryMpiImpl(params.mpi);
538 ofstream tempOutputFile;
539 tempOutputFile.open(TmpFileName.c_str(), ofstream::out );
542 tempOutputFile << "#! /bin/sh -f" << endl ;
543 tempOutputFile << "cd ~/" ;
544 tempOutputFile << dirForTmpFiles << endl ;
545 tempOutputFile << "export SALOME_BATCH=1\n";
546 tempOutputFile << "export PYTHONPATH=~/" ;
547 tempOutputFile << dirForTmpFiles ;
548 tempOutputFile << ":$PYTHONPATH" << endl ;
550 // Adding user script
551 std::string script = params.userCommands;
553 tempOutputFile << script << endl;
555 tempOutputFile << "if test \"" ;
556 tempOutputFile << mpiImpl->rank() ;
557 tempOutputFile << "\" = \"0\"; then" << endl ;
559 // -----------------------------------------------
560 // Code for rank 0 : launch runAppli and a container
562 if(params.ModulesList.size()>0)
563 tempOutputFile << " " << params.AppliPath << "/runAppli --terminal --modules=" ;
565 tempOutputFile << " " << params.AppliPath << "/runAppli --terminal ";
566 for ( int i = 0 ; i < params.ModulesList.size() ; i++ ) {
567 tempOutputFile << params.ModulesList[i] ;
568 if ( i != params.ModulesList.size()-1 )
569 tempOutputFile << "," ;
571 tempOutputFile << " --standalone=registry,study,moduleCatalog --ns-port-log="
575 // Wait NamingService
576 tempOutputFile << " current=0\n"
578 << " while ! test -f " << dfilelogtemp << "\n"
581 << " let current=current+1\n"
582 << " if [ \"$current\" -eq \"$stop\" ] ; then\n"
583 << " echo Error Naming Service failed ! >&2"
587 << " port=`cat " << dfilelogtemp << "`\n";
589 // Wait other containers
590 tempOutputFile << " for ((ip=1; ip < ";
591 tempOutputFile << mpiImpl->size();
592 tempOutputFile << " ; ip++))" << endl;
593 tempOutputFile << " do" << endl ;
594 tempOutputFile << " arglist=\"$arglist YACS_Server_\"$ip" << endl ;
595 tempOutputFile << " done" << endl ;
596 tempOutputFile << " sleep 5" << endl ;
597 tempOutputFile << " " << params.AppliPath << "/runSession waitContainers.py $arglist" << endl ;
599 // Launch user script
600 tempOutputFile << " " << params.AppliPath << "/runSession python ~/" << dirForTmpFiles << "/" << fileNameToExecute << ".py" << endl;
603 tempOutputFile << " rm " << dfilelogtemp << "\n"
604 << " " << params.AppliPath << "/runSession shutdownSalome.py" << endl;
606 // -------------------------------------
607 // Other nodes launch a container
608 tempOutputFile << "else" << endl ;
610 // Wait NamingService
611 tempOutputFile << " current=0\n"
613 << " while ! test -f " << dfilelogtemp << "\n"
616 << " let current=current+1\n"
617 << " if [ \"$current\" -eq \"$stop\" ] ; then\n"
618 << " echo Error Naming Service failed ! >&2"
622 << " port=`cat " << dfilelogtemp << "`\n";
624 // Launching container
625 tempOutputFile << " " << params.AppliPath << "/runSession SALOME_Container YACS_Server_";
626 tempOutputFile << mpiImpl->rank()
627 << " > ~/" << dirForTmpFiles << "/YACS_Server_"
628 << mpiImpl->rank() << "_container_log." << filelogtemp
630 tempOutputFile << "fi" << endl ;
631 tempOutputFile.flush();
632 tempOutputFile.close();
633 chmod(TmpFileName.c_str(), 0x1ED);
634 #if defined(_DEBUG_) || defined(_DEBUG)
635 cerr << TmpFileName.c_str() << endl;
646 throw LauncherException("Method Launcher_cpp::buildSalomeCouplingScript is not available "
647 "(libBatch was not present at compilation time)");
651 MpiImpl *Launcher_cpp::FactoryMpiImpl(MpiImplType mpi) throw(LauncherException)
656 return new MpiImpl_LAM();
658 return new MpiImpl_MPICH1();
660 return new MpiImpl_MPICH2();
662 return new MpiImpl_OPENMPI();
664 return new MpiImpl_SLURM();
666 return new MpiImpl_PRUN();
668 throw LauncherException("you must specify an mpi implementation for batch manager");
671 oss << mpi << " : not yet implemented";
672 throw LauncherException(oss.str().c_str());
675 throw LauncherException("Method Launcher_cpp::FactoryMpiImpl is not available "
676 "(libBatch was not present at compilation time)");
680 string Launcher_cpp::getTmpDirForBatchFiles()
686 // Adding date to the directory name
687 Batch::Date date = Batch::Date(time(0));
688 thedate = date.str();
689 int lend = thedate.size() ;
692 if ( thedate[i] == '/' || thedate[i] == '-' || thedate[i] == ':' ) {
698 ret = string("Batch/");
702 throw LauncherException("Method Launcher_cpp::getTmpDirForBatchFiles is not available "
703 "(libBatch was not present at compilation time)");
707 string Launcher_cpp::getRemoteFile( std::string remoteDir, std::string localFile )
709 string::size_type pos = localFile.find_last_of("/") + 1;
710 int ln = localFile.length() - pos;
711 string remoteFile = remoteDir + "/" + localFile.substr(pos,ln);
715 bool Launcher_cpp::check(const batchParams& batch_params)
718 #if defined(_DEBUG_) || defined(_DEBUG)
719 cerr << "Job parameters are :" << endl;
720 cerr << "Directory : $HOME/Batch/$date" << endl;
723 // check expected_during_time (check the format)
724 std::string edt_info = batch_params.expected_during_time;
725 std::string edt_value = batch_params.expected_during_time;
726 if (edt_value != "") {
727 std::string begin_edt_value = edt_value.substr(0, 2);
728 std::string mid_edt_value = edt_value.substr(2, 1);
729 std::string end_edt_value = edt_value.substr(3);
732 std::istringstream iss(begin_edt_value);
733 if (!(iss >> value)) {
734 edt_info = "Error on definition ! : " + edt_value;
737 else if (value < 0) {
738 edt_info = "Error on definition time is negative ! : " + value;
741 std::istringstream iss_2(end_edt_value);
742 if (!(iss_2 >> value)) {
743 edt_info = "Error on definition ! : " + edt_value;
746 else if (value < 0) {
747 edt_info = "Error on definition time is negative ! : " + value;
750 if (mid_edt_value != ":") {
751 edt_info = "Error on definition ! :" + edt_value;
756 edt_info = "No value given";
758 #if defined(_DEBUG_) || defined(_DEBUG)
759 cerr << "Expected during time : " << edt_info << endl;;
762 // check memory (check the format)
763 std::string mem_info;
764 std::string mem_value = batch_params.mem;
765 if (mem_value != "") {
766 std::string begin_mem_value = mem_value.substr(0, mem_value.length()-2);
768 std::istringstream iss(begin_mem_value);
769 if (!(iss >> re_mem_value)) {
770 mem_info = "Error on definition ! : " + mem_value;
773 else if (re_mem_value <= 0) {
774 mem_info = "Error on definition memory is negative ! : " + mem_value;
777 std::string end_mem_value = mem_value.substr(mem_value.length()-2);
778 if (end_mem_value != "gb" && end_mem_value != "mb") {
779 mem_info = "Error on definition, type is bad ! " + mem_value;
784 mem_info = "No value given";
786 #if defined(_DEBUG_) || defined(_DEBUG)
787 cerr << "Memory : " << mem_info << endl;
791 std::string nb_proc_info;
792 ostringstream nb_proc_value;
793 nb_proc_value << batch_params.nb_proc;
794 if(batch_params.nb_proc <= 0) {
795 nb_proc_info = "Bad value ! nb_proc = ";
796 nb_proc_info += nb_proc_value.str();
800 nb_proc_info = nb_proc_value.str();
802 #if defined(_DEBUG_) || defined(_DEBUG)
803 cerr << "Nb of processors : " << nb_proc_info << endl;
809 long Launcher_cpp::getWallTime(std::string edt)
813 if( edt.size() == 0 )
816 string::size_type pos = edt.find(":");
817 string h = edt.substr(0,pos);
818 string m = edt.substr(pos+1,edt.size()-pos+1);
819 istringstream issh(h);
821 istringstream issm(m);
827 long Launcher_cpp::getRamSize(std::string mem)
831 if( mem.size() == 0 )
834 string ram = mem.substr(0,mem.size()-2);
835 istringstream iss(ram);
837 string unity = mem.substr(mem.size()-2,2);
838 if( (unity.find("gb") != string::npos) || (unity.find("GB") != string::npos) )
840 else if( (unity.find("mb") != string::npos) || (unity.find("MB") != string::npos) )
842 else if( (unity.find("kb") != string::npos) || (unity.find("KB") != string::npos) )
844 else if( (unity.find("b") != string::npos) || (unity.find("B") != string::npos) )
845 return mv/(1024*1024);
850 void Launcher_cpp::ParseXmlFile(string xmlExecuteFile)
852 SALOME_Launcher_Handler* handler = new SALOME_Launcher_Handler(_launch);
854 const char* aFilePath = xmlExecuteFile.c_str();
855 FILE* aFile = fopen(aFilePath, "r");
859 xmlDocPtr aDoc = xmlReadFile(aFilePath, NULL, 0);
862 handler->ProcessXmlDocument(aDoc);
864 #if defined(_DEBUG_) || defined(_DEBUG)
865 cout << "ResourcesManager_cpp: could not parse file "<< aFilePath << endl;
875 #if defined(_DEBUG_) || defined(_DEBUG)
876 cout << "Launcher_cpp: file "<<aFilePath<<" is not readable." << endl;
884 std::string Launcher_cpp::getHomeDir(const ParserResourcesType& p, const std::string& tmpdir)
888 int idx = tmpdir.find("Batch/");
889 std::string filelogtemp = tmpdir.substr(idx+6, tmpdir.length());
890 filelogtemp = "/tmp/logs" + filelogtemp + "_home";
892 if( p.Protocol == rsh )
894 else if( p.Protocol == ssh )
897 throw LauncherException("Unknown protocol");
898 if (p.UserName != ""){
899 command += p.UserName;
903 command += " 'echo $HOME' > ";
904 command += filelogtemp;
905 #if defined(_DEBUG_) || defined(_DEBUG)
906 std::cerr << command.c_str() << std::endl;
908 int status = system(command.c_str());
910 throw LauncherException("Error of launching home command on remote host");
912 std::ifstream file_home(filelogtemp.c_str());
913 std::getline(file_home, home);