From 033e2c6f85ad4e0b3e36ea51baa32d4baee078c3 Mon Sep 17 00:00:00 2001 From: ribes Date: Tue, 20 May 2008 10:10:43 +0000 Subject: [PATCH] - Adding home to PBS command file --- src/Launcher/BatchLight_BatchManager.cxx | 36 +++++++++++++++ src/Launcher/BatchLight_BatchManager.hxx | 2 + src/Launcher/BatchLight_BatchManager_PBS.cxx | 5 +- src/Launcher/BatchLight_BatchTest.cxx | 48 ++++++++------------ src/Launcher/BatchLight_BatchTest.hxx | 1 - src/Launcher/BatchLight_Job.cxx | 2 +- src/Launcher/BatchLight_Job.hxx | 3 ++ 7 files changed, 64 insertions(+), 33 deletions(-) diff --git a/src/Launcher/BatchLight_BatchManager.cxx b/src/Launcher/BatchLight_BatchManager.cxx index 37def271e..5d7dc2f46 100644 --- a/src/Launcher/BatchLight_BatchManager.cxx +++ b/src/Launcher/BatchLight_BatchManager.cxx @@ -72,6 +72,9 @@ namespace BatchLight { // temporary directory on cluster to put input files for job setDirForTmpFiles(job); + // Set Home director + setHomeDir(job); + // export input files on cluster exportInputFiles(job); @@ -112,6 +115,39 @@ namespace BatchLight { job->setDirForTmpFiles(dirForTmpFiles); } + void BatchManager::setHomeDir(BatchLight::Job* job) + { + std::string home; + std::string command; + const std::string dirForTmpFiles = job->getDirForTmpFiles(); + int idx = dirForTmpFiles.find("Batch/"); + std::string filelogtemp = dirForTmpFiles.substr(idx+6, dirForTmpFiles.length()); + filelogtemp = "/tmp/logs" + filelogtemp + "_home"; + + if( _params.protocol == "rsh" ) + command = "rsh "; + else if( _params.protocol == "ssh" ) + command = "ssh "; + else + throw SALOME_Exception("Unknown protocol"); + if (_params.username != ""){ + command += _params.username; + command += "@"; + } + command += _params.hostname; + command += " 'echo $HOME' > "; + command += filelogtemp; + SCRUTE(command.c_str()); + int status = system(command.c_str()); + if(status) + throw SALOME_Exception("Error of launching home command on remote host"); + + std::ifstream file_home(filelogtemp.c_str()); + std::getline(file_home, home); + file_home.close(); + job->setHomeDir(home); + } + void BatchManager::exportInputFiles(BatchLight::Job* job) throw(SALOME_Exception) { BEGIN_OF("BatchManager::exportInFiles"); diff --git a/src/Launcher/BatchLight_BatchManager.hxx b/src/Launcher/BatchLight_BatchManager.hxx index 7183c1d1b..c5d3c70c3 100644 --- a/src/Launcher/BatchLight_BatchManager.hxx +++ b/src/Launcher/BatchLight_BatchManager.hxx @@ -32,6 +32,7 @@ #include #include #include +#include #include "Utils_SALOME_Exception.hxx" #include #include @@ -73,6 +74,7 @@ namespace BatchLight { virtual int submit(BatchLight::Job* job) throw(SALOME_Exception) = 0; void setDirForTmpFiles(BatchLight::Job* job); + void setHomeDir(BatchLight::Job* job); void exportInputFiles(BatchLight::Job* job) throw(SALOME_Exception); virtual void buildSalomeCouplingScript(BatchLight::Job* job) throw(SALOME_Exception) = 0; virtual void buildSalomeBatchScript(BatchLight::Job* job) throw(SALOME_Exception) = 0; diff --git a/src/Launcher/BatchLight_BatchManager_PBS.cxx b/src/Launcher/BatchLight_BatchManager_PBS.cxx index eec063a02..1eeefc2de 100644 --- a/src/Launcher/BatchLight_BatchManager_PBS.cxx +++ b/src/Launcher/BatchLight_BatchManager_PBS.cxx @@ -321,6 +321,7 @@ namespace BatchLight { std::string fileNameToExecute = string(fileToExecute).substr(p1+1,p2-p1-1); int idx = dirForTmpFiles.find("Batch/"); std::string filelogtemp = dirForTmpFiles.substr(idx+6, dirForTmpFiles.length()); + const std::string home = job->getHomeDir(); int nbmaxproc = _params.nbnodes * _params.nbprocpernode; if( nbproc > nbmaxproc ){ @@ -351,8 +352,8 @@ namespace BatchLight { // like PBS_O_HOME for #PBS directives.... //tempOutputFile << "#PBS -o /$PBS_O_HOME/" << dirForTmpFiles << "/runSalome.output.log.${PBS_JOBID}" << endl ; //tempOutputFile << "#PBS -e /$PBS_O_HOME/" << dirForTmpFiles << "/runSalome.error.log.${PBS_JOBID}" << endl ; - tempOutputFile << "#PBS -o runSalome.output.log." << filelogtemp << endl ; - tempOutputFile << "#PBS -e runSalome.error.log." << filelogtemp << endl ; + tempOutputFile << "#PBS -o " << home << "/" << dirForTmpFiles << "/runSalome.output.log." << filelogtemp << endl ; + tempOutputFile << "#PBS -e " << home << "/" << dirForTmpFiles << "/runSalome.error.log." << filelogtemp << endl ; tempOutputFile << _mpiImpl->boot("${PBS_NODEFILE}",nbnodes); tempOutputFile << _mpiImpl->run("${PBS_NODEFILE}",nbproc,filenameToExecute.str()); tempOutputFile << _mpiImpl->halt(); diff --git a/src/Launcher/BatchLight_BatchTest.cxx b/src/Launcher/BatchLight_BatchTest.cxx index b81688a38..5740a3c5f 100644 --- a/src/Launcher/BatchLight_BatchTest.cxx +++ b/src/Launcher/BatchLight_BatchTest.cxx @@ -108,9 +108,7 @@ BatchLight_BatchTest::test_connection() // Build command command += protocol + " " - + username + "@" + alias - + " 'echo $HOME' > " - + _test_filename + "_home"; + + username + "@" + alias; // Test status = system(command.c_str()); @@ -122,16 +120,6 @@ BatchLight_BatchTest::test_connection() return result; } - std::string file_home_name = _test_filename + "_home"; - std::ifstream file_home(file_home_name.c_str()); - if (!file_home) - { - result += "Error in reading temporary file ! filename = " + file_home_name; - return result; - } - std::getline(file_home, _home); - file_home.close(); - result = "OK"; return result; } @@ -278,6 +266,13 @@ BatchLight_BatchTest::test_jobsubmit_simple() return result; } + // Getting home directory + std::string rst = get_home(&home); + if(rst != "") { + result += rst; + return result; + } + // PBS test std::string _test_file_simple = _test_filename + "_simple"; std::ofstream file; @@ -285,19 +280,13 @@ BatchLight_BatchTest::test_jobsubmit_simple() file << "#!/bin/bash\n" << "#PBS -l nodes=1\n" << "#PBS -l walltime=00:01:00\n" - << "#PBS -o " + _home + "/" + _date + "_simple_output.log\n" - << "#PBS -e " + _home + "/" + _date + "_simple_error.log\n" + << "#PBS -o " + home + "/" + _date + "_simple_output.log\n" + << "#PBS -e " + home + "/" + _date + "_simple_error.log\n" << "echo Bonjour\n" << "echo Error >&2\n"; file.flush(); file.close(); - // Getting home directory - std::string rst = get_home(&home); - if(rst != "") { - result += rst; - return result; - } // Build command for copy command = "scp"; @@ -442,6 +431,13 @@ BatchLight_BatchTest::test_jobsubmit_mpi() return result; } + // Getting home directory + std::string rst = get_home(&home); + if(rst != "") { + result += rst; + return result; + } + // MPI test std::string _test_file_script = _test_filename + "_script"; std::ofstream file_script; @@ -458,20 +454,14 @@ BatchLight_BatchTest::test_jobsubmit_mpi() file_mpi << "#!/bin/bash\n" << "#PBS -l nodes=1\n" << "#PBS -l walltime=00:01:00\n" - << "#PBS -o " << _home << "/" << _date << "_mpi_output.log\n" - << "#PBS -e " << _home << "/" << _date << "_mpi_error.log\n" + << "#PBS -o " << home << "/" << _date << "_mpi_output.log\n" + << "#PBS -e " << home << "/" << _date << "_mpi_error.log\n" << mpiImpl->boot("${PBS_NODEFILE}", 1) << mpiImpl->run("${PBS_NODEFILE}", 1, _base_filename + "_script") << mpiImpl->halt(); file_mpi.flush(); file_mpi.close(); - // Getting home directory - std::string rst = get_home(&home); - if(rst != "") { - result += rst; - return result; - } // Build command for copy command = "scp"; diff --git a/src/Launcher/BatchLight_BatchTest.hxx b/src/Launcher/BatchLight_BatchTest.hxx index b936a2854..0224965c7 100644 --- a/src/Launcher/BatchLight_BatchTest.hxx +++ b/src/Launcher/BatchLight_BatchTest.hxx @@ -55,7 +55,6 @@ class BatchLight_BatchTest std::string _test_filename; std::string _base_filename; std::string _date; - std::string _home; }; #endif diff --git a/src/Launcher/BatchLight_Job.cxx b/src/Launcher/BatchLight_Job.cxx index 1980054a9..ac818c4c7 100644 --- a/src/Launcher/BatchLight_Job.cxx +++ b/src/Launcher/BatchLight_Job.cxx @@ -41,7 +41,7 @@ Job::Job(const char *fileToExecute, _batch_params(batch_params) { _dirForTmpFiles = "/tmp/default_batch_tmp_directory"; - std::string _fileNameToExecute = ""; + _home=""; } Job::~Job() diff --git a/src/Launcher/BatchLight_Job.hxx b/src/Launcher/BatchLight_Job.hxx index e17e790b9..94cdd6a45 100644 --- a/src/Launcher/BatchLight_Job.hxx +++ b/src/Launcher/BatchLight_Job.hxx @@ -56,6 +56,8 @@ namespace BatchLight { const std::string getDirForTmpFiles() const { return _dirForTmpFiles;} void setDirForTmpFiles(std::string dirForTmpFiles) {_dirForTmpFiles = dirForTmpFiles; SCRUTE(_dirForTmpFiles);} + void setHomeDir(std::string home) {_home = home;SCRUTE(_dirForTmpFiles);} + const std::string getHomeDir() {return _home;} bool check(); protected: const char* _fileToExecute; @@ -63,6 +65,7 @@ namespace BatchLight { Engines::FilesList _filesToImport; Engines::BatchParameters _batch_params; std::string _dirForTmpFiles; // Tmp directory on the server + std::string _home; // Home directory on the server private: }; -- 2.39.2