]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
- Adding home to PBS command file
authorribes <ribes>
Tue, 20 May 2008 10:10:43 +0000 (10:10 +0000)
committerribes <ribes>
Tue, 20 May 2008 10:10:43 +0000 (10:10 +0000)
src/Launcher/BatchLight_BatchManager.cxx
src/Launcher/BatchLight_BatchManager.hxx
src/Launcher/BatchLight_BatchManager_PBS.cxx
src/Launcher/BatchLight_BatchTest.cxx
src/Launcher/BatchLight_BatchTest.hxx
src/Launcher/BatchLight_Job.cxx
src/Launcher/BatchLight_Job.hxx

index 37def271e53710ab0efe5a6d419607fdc690abeb..5d7dc2f46730d5eb058c1ee497f0d440c175af68 100644 (file)
@@ -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");
index 7183c1d1bb8f6e7cfe94352050d86890ddf4d9af..c5d3c70c35978bcd95c430bb083944a7a7c33c0d 100644 (file)
@@ -32,6 +32,7 @@
 #include <vector>
 #include <map>
 #include <string>
+#include <fstream>
 #include "Utils_SALOME_Exception.hxx"
 #include <SALOMEconfig.h>
 #include <stdlib.h>
@@ -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;
index eec063a02ba05d25b7c896872a4f3614898d42fd..1eeefc2de0913d9378796a21baa270cd070ecb97 100644 (file)
@@ -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();
index b81688a38f83dd30091e2e0d9c3b63be2e1aeca9..5740a3c5f91e99f4b7a24e86b28a667d8c04f7e6 100644 (file)
@@ -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";
index b936a2854b91e6f5c67dbf8ccc057f87f298e6c3..0224965c7bda219d13684fbecee7d91ad7021eb9 100644 (file)
@@ -55,7 +55,6 @@ class BatchLight_BatchTest
     std::string _test_filename;
     std::string _base_filename;
     std::string _date;
-    std::string _home;
 };
 
 #endif
index 1980054a9abd0e2014eb1504362042e38e0fe8a1..ac818c4c77f223345bd1c70f0288d199993186fb 100644 (file)
@@ -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()
index e17e790b9192ede7f46caa541df4d83a239d5e7d..94cdd6a451905de65e72bd1bfad2b9b1a3c6883e 100644 (file)
@@ -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:
 
   };