]> SALOME platform Git repositories - tools/libbatch.git/blobdiff - src/LoadLeveler/Batch_BatchManager_eLL.cxx
Salome HOME
Fixed nb_proc_per_node for LoadLeveler jobs
[tools/libbatch.git] / src / LoadLeveler / Batch_BatchManager_eLL.cxx
index 2c3a390922eade16e102e78cfed9ff229ab0561c..a04322add4eb6e1e2c32ec4a9af0f44d647a93b4 100644 (file)
  *  Author : Renaud BARATE - EDF R&D
  */
 
+#include <cstdlib>
 #include <iostream>
 #include <fstream>
 
 #include <Batch_NotYetImplementedException.hxx>
 
 #include "Batch_BatchManager_eLL.hxx"
+#include "Batch_JobInfo_eLL.hxx"
 
 using namespace std;
 
@@ -42,7 +44,8 @@ namespace Batch {
                                      CommunicationProtocolType protocolType, const char * mpiImpl,
                                      int nb_proc_per_node)
     : BatchManager(parent, host),
-      BatchManager_eClient(parent, host, username, protocolType, mpiImpl)
+      BatchManager_eClient(parent, host, username, protocolType, mpiImpl),
+      _nb_proc_per_node(nb_proc_per_node)
   {
     // Nothing to do
   }
@@ -75,13 +78,13 @@ namespace Batch {
     command += logFile;
     cerr << command.c_str() << endl;
     status = system(command.c_str());
-    if(status)
+    if (status)
     {
       ifstream error_message(logFile.c_str());
       string mess;
       string temp;
-      while(std::getline(error_message, temp))
-          mess += temp;
+      while(getline(error_message, temp))
+        mess += temp;
       error_message.close();
       throw EmulationException("Error of connection on remote host, error was: " + mess);
     }
@@ -89,15 +92,12 @@ namespace Batch {
     // read id of submitted job in log file
     string jobref;
     ifstream idfile(logFile.c_str());
-    unsigned int linebufsize = 1024;
-    char linebuf[linebufsize];
-    idfile.getline(linebuf, linebufsize);
-    while (!idfile.eof() && strncmp(linebuf, "llsubmit:", 9) != 0)
-      idfile.getline(linebuf, linebufsize);
+    string line;
+    while (idfile && line.compare(0, 9, "llsubmit:") != 0)
+      getline(idfile, line);
     idfile.close();
-    if (strncmp(linebuf, "llsubmit:", 9) == 0)
+    if (line.compare(0, 9, "llsubmit:") == 0)
     {
-      string line(linebuf);
       string::size_type p1 = line.find_first_of("\"");
       string::size_type p2 = line.find_last_of("\"");
       if (p1 != p2)
@@ -127,15 +127,11 @@ namespace Batch {
     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");
+      throw EmulationException("params[WORKDIR] is not defined. Please define 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(QUEUE) != params.end()) 
-      queue = params[QUEUE].str();
+      throw EmulationException("params[EXECUTABLE] is not defined. Please define it, cannot submit this job.");
 
     string::size_type p1 = fileToExecute.find_last_of("/");
     string::size_type p2 = fileToExecute.find_last_of(".");
@@ -144,34 +140,89 @@ namespace Batch {
 
     // Create batch submit file
     ofstream tempOutputFile;
-    std::string tmpFileName = createAndOpenTemporaryFile("LL-script", tempOutputFile);
+    string tmpFileName = createAndOpenTemporaryFile("LL-script", tempOutputFile);
 
-    tempOutputFile << "# @ executable = " << fileNameToExecute << endl;
+    tempOutputFile << "#!/bin/bash" << endl;
     tempOutputFile << "# @ output = " << workDir << "/logs/output.log." << rootNameToExecute << endl;
     tempOutputFile << "# @ error = " << workDir << "/logs/error.log." << rootNameToExecute << endl;
-    if (queue != "")
-      tempOutputFile << "# @ class = " << queue << endl;
-    tempOutputFile << "# @ job_type = bluegene" << endl;
+    tempOutputFile << "# @ node_usage = not_shared" << endl;
+
+    if (params.find(NAME) != params.end())
+      tempOutputFile << "# @ job_name = " << params[NAME] << endl;
+
+    // Optional parameters
+    int nbproc = 1;
+    if (params.find(NBPROC) != params.end())
+      nbproc = params[NBPROC];
+    //if (nbproc == 1)
+    //  tempOutputFile << "# @ job_type = serial" << endl;
+    //else {
+      //  tempOutputFile << "# @ job_type = parallel" << endl;
+      int nodes_requested = (nbproc + _nb_proc_per_node -1) / _nb_proc_per_node;
+      tempOutputFile << "# @ job_type = mpich" << endl;
+      tempOutputFile << "# @ node = " << nodes_requested << endl;
+      tempOutputFile << "# @ tasks_per_node = " << _nb_proc_per_node << endl;
+    //}
+    //tempOutputFile << "# @ job_type = bluegene" << endl;
+
+    if (params.find(MAXWALLTIME) != params.end())
+      tempOutputFile << "# @ wall_clock_limit = " << params[MAXWALLTIME] << ":00" << endl;
+    if (params.find(MAXRAMSIZE) != params.end())
+      tempOutputFile << "# @ as_limit = " << params[MAXRAMSIZE] << "mb" << endl;
+    if (params.find(QUEUE) != params.end())
+      tempOutputFile << "# @ class = " << params[QUEUE] << endl;
+
+    // Define environment for the job
+    Environnement env = job.getEnvironnement();
+    if (!env.empty()) {
+      tempOutputFile << "# @ environment = ";
+      Environnement::const_iterator iter;
+      for (iter = env.begin() ; iter != env.end() ; ++iter) {
+        tempOutputFile << iter->first << "=" << iter->second << "; ";
+      }
+      tempOutputFile << endl;
+    }
+
     tempOutputFile << "# @ queue" << endl;
 
+    // generate nodes file
+    tempOutputFile << "NODEFILE=`mktemp nodefile-XXXXXXXXXX` || exit 1" << endl;
+    tempOutputFile << "for node in $LOADL_PROCESSOR_LIST; do" << endl;
+    tempOutputFile << "  echo $node >> $NODEFILE" << endl;
+    tempOutputFile << "done" << endl;
+    tempOutputFile << "export LIBBATCH_NODEFILE=$NODEFILE" << endl;
+
+    // Launch the executable
+    tempOutputFile << "cd " << workDir << endl;
+    tempOutputFile << "./" + fileNameToExecute << endl;
+
     tempOutputFile.flush();
     tempOutputFile.close();
 
-    cerr << "Batch script file generated is: " << tmpFileName.c_str() << endl;
+    cerr << "Batch script file generated is: " << tmpFileName << endl;
 
     string remoteFileName = rootNameToExecute + "_LL.cmd";
     int status = _protocol.copyFile(tmpFileName, "", "",
                                     workDir + "/" + remoteFileName,
                                     _hostname, _username);
     if (status)
-      throw EmulationException("Error of connection on remote host, cannot copy batch submission file");
+      throw EmulationException("Cannot copy command file on host " + _hostname);
 
     return remoteFileName;
   }
 
   void BatchManager_eLL::deleteJob(const JobId & jobid)
   {
-    throw NotYetImplementedException("BatchManager_eLL::deleteJob");
+    // define command to delete job
+    string subCommand = "llcancel " + jobid.getReference();
+    string command = _protocol.getExecCommand(subCommand, _hostname, _username);
+    cerr << command.c_str() << endl;
+
+    int status = system(command.c_str());
+    if (status)
+      throw EmulationException("Can't delete job " + jobid.getReference());
+
+    cerr << "job " << jobid.getReference() << " killed" << endl;
   }
 
   void BatchManager_eLL::holdJob(const JobId & jobid)
@@ -201,7 +252,21 @@ namespace Batch {
 
   JobInfo BatchManager_eLL::queryJob(const JobId & jobid)
   {
-    throw NotYetImplementedException("BatchManager_eLL::queryJob");
+    // define name of log file (local)
+    string logFile = generateTemporaryFileName("LL-querylog-" + jobid.getReference());
+
+    // define command to query batch
+    string subCommand = "llq -f %st " + jobid.getReference();
+    string command = _protocol.getExecCommand(subCommand, _hostname, _username);
+    command += " > ";
+    command += logFile;
+    cerr << command.c_str() << endl;
+    int status = system(command.c_str());
+    if (status != 0)
+      throw EmulationException("Can't query job " + jobid.getReference());
+
+    JobInfo_eLL jobinfo = JobInfo_eLL(jobid.getReference(), logFile);
+    return jobinfo;
   }
 
   const JobId BatchManager_eLL::addJob(const Job & job, const string reference)