]> SALOME platform Git repositories - tools/libbatch.git/commitdiff
Salome HOME
New version of eClient - Adding default logs directory
authorribes <ribes>
Fri, 13 Nov 2009 15:06:39 +0000 (15:06 +0000)
committerribes <ribes>
Fri, 13 Nov 2009 15:06:39 +0000 (15:06 +0000)
New ePBS Client
First to handle cpu and nodes in submission

13 files changed:
src/Core/Batch_BatchManager_eClient.cxx
src/Core/Batch_Defines.hxx
src/Core/Batch_FactBatchManager_eClient.hxx
src/LSF/Batch_FactBatchManager_eLSF.cxx
src/LSF/Batch_FactBatchManager_eLSF.hxx
src/PBS/Batch_BatchManager_ePBS.cxx
src/PBS/Batch_BatchManager_ePBS.hxx
src/PBS/Batch_FactBatchManager_ePBS.cxx
src/PBS/Batch_FactBatchManager_ePBS.hxx
src/SGE/Batch_FactBatchManager_eSGE.cxx
src/SGE/Batch_FactBatchManager_eSGE.hxx
src/SSH/Batch_FactBatchManager_eSSH.cxx
src/SSH/Batch_FactBatchManager_eSSH.hxx

index 63801679b3389e7a035db8ba0bcce3d8ce972eff..81f03a34ed54cc3a00659ef7b3b2907c880c5229 100644 (file)
@@ -83,7 +83,7 @@ namespace Batch {
     Versatile::iterator Vit;
     _username = string(params[USER]);
 
-    string subCommand = string("mkdir -p ") + string(params[TMPDIR]);
+    string subCommand = string("mkdir -p ") + string(params[TMPDIR]) + string("/logs");
     string command = _protocol.getExecCommand(subCommand, _hostname, _username);
     cerr << command.c_str() << endl;
     status = system(command.c_str());
@@ -168,6 +168,17 @@ namespace Batch {
       }
     }
 
+    // Copy logs
+    int status = _protocol.copyFile(string(params[TMPDIR]) + string("/logs"), _hostname, _username,
+                                   directory, "", "");
+    if (status) {
+      std::string mess("Copy logs directory failed ! status is :");
+      ostringstream status_str;
+      status_str << status;
+      mess += status_str.str();
+      cerr << mess << endl;
+    }
+
   }
 
   MpiImpl *BatchManager_eClient::FactoryMpiImpl(string mpiImpl) throw(EmulationException)
index ab2a23716a7d82dee9cd6bf48297555b3f73f929..587e7d78759652b6bef5c9404a93bf1cc2c1556b 100644 (file)
 # define BATCH_EXPORT
 #endif
 
+#ifdef WIN32
+#define BATCH_CHMOD(name, mode) _chmod(name, mode)
+#else
+#define BATCH_CHMOD(name, mode) chmod(name, mode)
+#endif
+
 #endif
index d047f559f33022b256063f3753f3d7eb29ec8c30..0e4274f014bb44d87373de9f630f532913c3f42f 100644 (file)
@@ -49,7 +49,8 @@ namespace Batch {
 
     virtual Batch::BatchManager_eClient * operator() (const char * hostname,
                                                       CommunicationProtocolType protocolType,
-                                                      const char * mpi) const = 0;
+                                                      const char * mpi,
+                                                     int nb_proc_per_node = 1) const = 0;
 
   protected:
 
index f79992225f822b3595ed24465979939efe0232a5..afece453c4d98fd85ebc9773086d41fd8c4126c5 100644 (file)
@@ -54,7 +54,8 @@ namespace Batch {
 
   BatchManager_eClient * FactBatchManager_eLSF::operator() (const char * hostname,
                                                             CommunicationProtocolType protocolType,
-                                                            const char * mpiImpl) const
+                                                            const char * mpiImpl,
+                                                           int nb_proc_per_node) const
   {
     // MESSAGE("Building new BatchManager_LSF on host '" << hostname << "'");
     return new BatchManager_eLSF(this, hostname, protocolType, mpiImpl);
index 9144f649f5d289ccec555d66feca8b56885e4e22..3f3c604e4261b8189634f78a42e196c3f6d6fce0 100644 (file)
@@ -47,7 +47,8 @@ namespace Batch {
     virtual BatchManager * operator() (const char * hostname) const;
     virtual BatchManager_eClient * operator() (const char * hostname,
                                                CommunicationProtocolType protocolType,
-                                               const char * mpiImpl) const;
+                                               const char * mpiImpl,
+                                              int nb_proc_per_node = 1) const;
 
   protected:
 
index e676860a9c71661ddf9af743f781a6c50bdf9996..8e4d1beb1b1908f84421e77567e57ccc82ca0791 100644 (file)
@@ -55,11 +55,13 @@ using namespace std;
 namespace Batch {
 
   BatchManager_ePBS::BatchManager_ePBS(const FactBatchManager * parent, const char * host,
-                                       CommunicationProtocolType protocolType, const char * mpiImpl)
+                                       CommunicationProtocolType protocolType, const char * mpiImpl, 
+                                      int nb_proc_per_node)
     : BatchManager_eClient(parent, host, protocolType, mpiImpl),
     BatchManager(parent, host)
   {
     // Nothing to do
+    _nb_proc_per_node = nb_proc_per_node;
   }
 
   // Destructeur
@@ -73,7 +75,7 @@ namespace Batch {
   {
     int status;
     Parametre params = job.getParametre();
-    const std::string dirForTmpFiles = params[TMPDIR];
+    const std::string workDir = params[WORKDIR];
     const string fileToExecute = params[EXECUTABLE];
     string::size_type p1 = fileToExecute.find_last_of("/");
     string::size_type p2 = fileToExecute.find_last_of(".");
@@ -89,8 +91,7 @@ namespace Batch {
     string logFile = generateTemporaryFileName("PBS-submitlog");
 
     // define command to submit batch
-    string subCommand = string("cd ") + dirForTmpFiles + "; qsub " +
-                        fileNameToExecute + "_Batch.sh";
+    string subCommand = string("cd ") + workDir + "; qsub " + fileNameToExecute + "_Batch.sh";
     string command = _protocol.getExecCommand(subCommand, _hostname, _username);
     command += " > ";
     command += logFile;
@@ -199,6 +200,76 @@ namespace Batch {
   }
 
   void BatchManager_ePBS::buildBatchScript(const Job & job)
+  {
+    std::cerr << "BuildBatchScript" << std::endl;
+    Parametre params = job.getParametre();
+
+    // Job Parameters
+    string workDir       = "";
+    string fileToExecute = "";
+    int nbproc          = 0;
+    int edt             = 0;
+    int mem              = 0;
+    string queue         = "";
+
+    // Mandatory parameters
+    if (params.find(WORKDIR) != params.end()) 
+      workDir = params[WORKDIR].str();
+    else 
+      throw EmulationException("params[WORKDIR] is not defined ! Please defined it, cannot submit this job");
+    if (params.find(EXECUTABLE) != params.end()) 
+      fileToExecute = params[EXECUTABLE].str();
+    else 
+      throw EmulationException("params[EXECUTABLE] is not defined ! Please defined it, cannot submit this job");
+
+    // Optional parameters
+    if (params.find(NBPROC) != params.end()) 
+      nbproc = params[NBPROC];
+    if (params.find(MAXWALLTIME) != params.end()) 
+      edt = params[MAXWALLTIME];
+    if (params.find(MAXRAMSIZE) != params.end()) 
+      mem = params[MAXRAMSIZE];
+
+    string::size_type p1 = fileToExecute.find_last_of("/");
+    string::size_type p2 = fileToExecute.find_last_of(".");
+    string rootNameToExecute = fileToExecute.substr(p1+1,p2-p1-1);
+    string fileNameToExecute = fileToExecute.substr(p1+1);
+
+    // Create batch submit file
+    ofstream tempOutputFile;
+    std::string TmpFileName = createAndOpenTemporaryFile("PBS-script", tempOutputFile);
+
+    tempOutputFile << "#! /bin/sh -f" << endl;
+    if (nbproc > 0)
+    {
+    // Division - arrondi supérieur
+      int nodes_requested = (nbproc + _nb_proc_per_node -1) / _nb_proc_per_node;
+      tempOutputFile << "#PBS -l nodes=" << nodes_requested << endl;
+    }
+    if (queue != "")
+      tempOutputFile << "#BSUB -q " << queue << endl;
+    if( edt > 0 )
+      tempOutputFile << "#PBS -l walltime=" << edt*60 << endl;
+    if( mem > 0 )
+      tempOutputFile << "#PBS -l mem=" << mem << "mb" << endl;
+    tempOutputFile << "#PBS -o " << workDir << "/logs/output.log." << rootNameToExecute << endl ;
+    tempOutputFile << "#PBS -e " << workDir << "/logs/error.log."  << rootNameToExecute << endl ;
+    tempOutputFile << "cd " << workDir << endl ;
+    tempOutputFile << "./" + fileNameToExecute << endl;;
+    tempOutputFile.flush();
+    tempOutputFile.close();
+
+    BATCH_CHMOD(TmpFileName.c_str(), 0x1ED);
+    cerr << "Batch script file generated is: " << TmpFileName.c_str() << endl;
+
+    int status = _protocol.copyFile(TmpFileName, "", "",
+                                    workDir + "/" + rootNameToExecute + "_Batch.sh",
+                                    _hostname, _username);
+    if (status)
+      throw EmulationException("Error of connection on remote host, cannot copy batch submission file");
+  }
+
+  void BatchManager_ePBS::oldbuildBatchScript(const Job & job)
   {
     Parametre params = job.getParametre();
     Environnement env = job.getEnvironnement();
index a2f94576a8f42e1264b5b952d3f590bf6d6de13f..73b49479e8b225372036b084a35da2f50f3bf580 100644 (file)
@@ -45,7 +45,8 @@ namespace Batch {
   public:
     // Constructeur et destructeur
     BatchManager_ePBS(const FactBatchManager * parent, const char * host="localhost",
-                      CommunicationProtocolType protocolType = SSH, const char * mpiImpl="nompi"); // connexion a la machine host
+                      CommunicationProtocolType protocolType = SSH, const char * mpiImpl="nompi",
+                     int nb_proc_per_node=1); // connexion a la machine host
     virtual ~BatchManager_ePBS();
 
     // Recupere le nom du serveur par defaut
@@ -68,8 +69,10 @@ namespace Batch {
 
   protected:
     void buildBatchScript(const Job & job);
+    void oldbuildBatchScript(const Job & job);
 
   private:
+    int _nb_proc_per_node;
 
 #ifdef SWIG
   public:
index 2984a3c077bf6066f55b605ce7f80e9330a1e4b3..e017f2fff4565046431ecccd61b4b59cbd85b83f 100644 (file)
@@ -58,10 +58,11 @@ namespace Batch {
 
   BatchManager_eClient * FactBatchManager_ePBS::operator() (const char * hostname,
                                                             CommunicationProtocolType protocolType,
-                                                            const char * mpiImpl) const
+                                                            const char * mpiImpl,
+                                                           int nb_proc_per_node) const
   {
     // MESSAGE("Building new BatchManager_PBS on host '" << hostname << "'");
-    return new BatchManager_ePBS(this, hostname, protocolType, mpiImpl);
+    return new BatchManager_ePBS(this, hostname, protocolType, mpiImpl, nb_proc_per_node);
   }
 
 
index 930552d9c3fb3c6e7db5c65e5de1524e3b811aef..3cf5d3a492aa951d3d91b323962a39da4edcbd4a 100644 (file)
@@ -52,7 +52,8 @@ namespace Batch {
     virtual BatchManager * operator() (const char * hostname) const;
     virtual BatchManager_eClient * operator() (const char * hostname,
                                                CommunicationProtocolType protocolType,
-                                               const char * mpiImpl) const;
+                                               const char * mpiImpl,
+                                              int nb_proc_per_node = 1) const;
 
   protected:
 
index 7bc44c02d50610839ab489777868351ceca9e22b..a1bdcc28b65472b4365792f052303f3ad4db796c 100644 (file)
@@ -56,7 +56,8 @@ namespace Batch {
 
   BatchManager_eClient * FactBatchManager_eSGE::operator() (const char * hostname,
                                                             CommunicationProtocolType protocolType,
-                                                            const char * mpiImpl) const
+                                                            const char * mpiImpl,
+                                                           int nb_proc_per_node) const
   {
     // MESSAGE("Building new BatchManager_SGE on host '" << hostname << "'");
     return new BatchManager_eSGE(this, hostname, protocolType, mpiImpl);
index 6dae360b09f7220f628d611569d981e9c972d211..509220ad039e2e74fae23b1c419d901b789d2451 100644 (file)
@@ -48,7 +48,8 @@ namespace Batch {
     virtual BatchManager * operator() (const char * hostname) const;
     virtual BatchManager_eClient * operator() (const char * hostname,
                                                CommunicationProtocolType protocolType,
-                                               const char * mpiImpl) const;
+                                               const char * mpiImpl,
+                                              int nb_proc_per_node = 1) const;
 
   protected:
 
index 28b70829ea6de86b3b920873fad06595d6d33c7b..0c8d153e4e12540ef241231ed161486e1278bbcd 100644 (file)
@@ -43,7 +43,8 @@ Batch::FactBatchManager_eSSH::operator() (const char * hostname) const
 Batch::BatchManager_eClient * 
 Batch::FactBatchManager_eSSH::operator() (const char * hostname,
                                   CommunicationProtocolType protocolType,
-                                  const char * mpiImpl) const
+                                  const char * mpiImpl,
+                                  int nb_proc_per_node) const
 {
   //protocolType and mpiImpl are ignored.
   std::cerr << "[Batch::FactBatchManager_eSSH] creating new Batch::BatchManager_eSSH with hostname = " << hostname << std::endl;
index 5014cd4de2aa29320d83d595e1c908ab1c091b42..f3210e6af327cf6b850cdbaf3a8f83b2d4032421 100644 (file)
@@ -49,7 +49,8 @@ namespace Batch {
     virtual BatchManager * operator() (const char * hostname) const; // From FactBacthManager
     virtual BatchManager_eClient * operator() (const char * hostname,
                                                CommunicationProtocolType protocolType,
-                                               const char * mpiImpl) const; // From FactBatchManager_eClient
+                                               const char * mpiImpl,
+                                              int nb_proc_per_node = 1) const; // From FactBatchManager_eClient
   };
 }