*
*/
-#include <stdlib.h>
-#include <string.h>
-
-#include <iostream>
+#include <cstdlib>
#include <fstream>
#include <sstream>
-#include <sys/stat.h>
-
-#include <stdlib.h>
-#include <string.h>
-#include <Batch_config.h>
-#ifdef MSVC
-#include <io.h>
-#else
-#include <libgen.h>
-#endif
+#include <Batch_Constants.hxx>
+#include <Batch_Utils.hxx>
-#include "Batch_Constants.hxx"
#include "Batch_BatchManager_ePBS.hxx"
#include "Batch_JobInfo_ePBS.hxx"
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
- _nb_proc_per_node = nb_proc_per_node;
}
// Destructeur
// Methode pour le controle des jobs : soumet un job au gestionnaire
const JobId BatchManager_ePBS::submitJob(const Job & job)
{
- int status;
Parametre params = job.getParametre();
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(".");
- std::string fileNameToExecute = fileToExecute.substr(p1+1,p2-p1-1);
// export input files on cluster
exportInputFiles(job);
// build batch script for job
- buildBatchScript(job);
-
- // define name of log file (local)
- string logFile = generateTemporaryFileName("PBS-submitlog");
+ string scriptFile = buildSubmissionScript(job);
// define command to submit batch
- string subCommand = string("cd ") + workDir + "; qsub " + fileNameToExecute + "_Batch.sh";
+ string subCommand = string("cd ") + workDir + "; qsub " + scriptFile;
string command = _protocol.getExecCommand(subCommand, _hostname, _username);
- command += " > ";
- command += logFile;
command += " 2>&1";
cerr << command.c_str() << endl;
- status = system(command.c_str());
- if(status)
- {
- ifstream error_message(logFile.c_str());
- std::string mess;
- std::string temp;
- while(std::getline(error_message, temp))
- mess += temp;
- error_message.close();
- throw EmulationException("Error of connection on remote host, error was: " + mess);
- }
- // read id of submitted job in log file
- ifstream idfile(logFile.c_str());
- string sline;
- idfile >> sline;
- idfile.close();
- if (sline.size() == 0)
- throw EmulationException("Error in the submission of the job on the remote host");
+ // submit job
+ string output;
+ int status = Utils::getCommandOutput(command, output);
+ cout << output;
+ if (status != 0) throw EmulationException("Can't submit job, error was: " + output);
+
+ // normally output contains only id of submitted job, we just need to remove the final \n
+ string jobref = output.substr(0, output.size() - 1);
+ JobId id(this, jobref);
- JobId id(this, sline);
return id;
}
istringstream iss(jobid.getReference());
iss >> id;
- // define name of log file (local)
- string logFile = generateTemporaryFileName(string("PBS-querylog-id") + jobid.getReference());
-
// define command to query batch
string subCommand = string("qstat -f ") + iss.str();
string command = _protocol.getExecCommand(subCommand, _hostname, _username);
- command += " > ";
- command += logFile;
cerr << command.c_str() << endl;
- int status = system(command.c_str());
+
+ string output;
+ int status = Utils::getCommandOutput(command, output);
if(status && status != 153 && status != 256*153)
throw EmulationException("Error of connection on remote host");
- JobInfo_ePBS ji = JobInfo_ePBS(id,logFile);
+ JobInfo_ePBS ji = JobInfo_ePBS(id, output);
return ji;
}
throw EmulationException("Not yet implemented");
}
- void BatchManager_ePBS::buildBatchScript(const Job & job)
+ std::string BatchManager_ePBS::buildSubmissionScript(const Job & job)
{
- std::cerr << "BuildBatchScript" << std::endl;
Parametre params = job.getParametre();
Environnement env = job.getEnvironnement();
std::string TmpFileName = createAndOpenTemporaryFile("PBS-script", tempOutputFile);
tempOutputFile << "#! /bin/sh -f" << endl;
+ if (params.find(NAME) != params.end()) {
+ tempOutputFile << "#PBS -N " << params[NAME] << endl;
+ }
+
if (nbproc > 0)
{
int nb_full_nodes = nbproc / _nb_proc_per_node;
tempOutputFile.flush();
tempOutputFile.close();
- BATCH_CHMOD(TmpFileName.c_str(), 0x1ED);
cerr << "Batch script file generated is: " << TmpFileName.c_str() << endl;
+ string remoteFileName = rootNameToExecute + "_Batch.sh";
int status = _protocol.copyFile(TmpFileName, "", "",
- workDir + "/" + rootNameToExecute + "_Batch.sh",
+ workDir + "/" + remoteFileName,
_hostname, _username);
if (status)
throw EmulationException("Error of connection on remote host, cannot copy batch submission file");
+ return remoteFileName;
}
}
#include <cstdio>
#include <iostream>
-#include <fstream>
#include <sstream>
-#include "Batch_Constants.hxx"
-#include "Batch_Parametre.hxx"
-#include "Batch_Environnement.hxx"
-#include "Batch_RunTimeException.hxx"
-#include "Batch_APIInternalFailureException.hxx"
+#include <Batch_Constants.hxx>
#include "Batch_JobInfo_ePBS.hxx"
using namespace std;
namespace Batch {
// Constructeurs
- JobInfo_ePBS::JobInfo_ePBS(int id, string logFile) : JobInfo()
+ JobInfo_ePBS::JobInfo_ePBS(int id, string queryOutput) : JobInfo()
{
- // On remplit les membres _param et _env
+ // Fill ID parameter
ostringstream oss;
oss << id;
_param[ID] = oss.str();
- // read of log file
- char line[128];
- ifstream fp(logFile.c_str(),ios::in);
-
- string sline;
+ // read query output
+ istringstream queryIss(queryOutput);
+ string line;
size_t pos = string::npos;
- while( (pos == string::npos) && fp.getline(line,80,'\n') ){
- sline = string(line);
- pos = sline.find("job_state");
- };
+ while( (pos == string::npos) && getline(queryIss, line) ) {
+ pos = line.find("job_state");
+ }
if(pos!=string::npos){
string status;
- istringstream iss(sline);
+ istringstream iss(line);
iss >> status;
iss >> status;
iss >> status;