-// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
//
// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
#include <fstream>
#include <cstring>
+#include <Batch_Constants.hxx>
#include <Batch_Job.hxx>
#include <Batch_BatchManagerCatalog.hxx>
#include <Batch_FactBatchManager.hxx>
#include <SimpleParser.hxx>
-#ifdef WIN32
-#include <Windows.h>
-#define sleep(seconds) Sleep((seconds)*1000)
-#define usleep(useconds) Sleep((useconds)/1000)
-#endif
-
using namespace std;
using namespace Batch;
-const int MAX_SLEEP_TIME = 600;
-
void print_usage()
{
cout << "usage: Test_ePBS PROTOCOL" << endl;
Job job;
// ... and its parameters ...
Parametre p;
- p["EXECUTABLE"] = "./test-script.sh";
- p["NAME"] = string("Test_ePBS_") + argv[1];
- p["WORKDIR"] = homedir + "/tmp/Batch";
- p["INFILE"] = Couple("seta.sh", "tmp/Batch/seta.sh");
- p["INFILE"] += Couple("setb.sh", "tmp/Batch/setb.sh");
- p["OUTFILE"] = Couple("result.txt", "tmp/Batch/result.txt");
- p["TMPDIR"] = "tmp/Batch/";
- p["USER"] = user;
- p["NBPROC"] = 1;
- p["MAXWALLTIME"] = 1;
- p["MAXRAMSIZE"] = 1000;
- p["HOMEDIR"] = homedir;
- p["QUEUE"] = queue;
+ p[EXECUTABLE] = "./test-script.sh";
+ p[NAME] = string("Test_ePBS_") + argv[1];
+ p[WORKDIR] = homedir + "/tmp/Batch";
+ p[INFILE] = Couple("seta.sh", "tmp/Batch/seta.sh");
+ p[INFILE] += Couple("setb.sh", "tmp/Batch/setb.sh");
+ p[OUTFILE] = Couple("result.txt", "tmp/Batch/result.txt");
+ p[TMPDIR] = "tmp/Batch/";
+ p[NBPROC] = 1;
+ p[MAXWALLTIME] = 1;
+ p[MAXRAMSIZE] = 1;
+ p[HOMEDIR] = homedir;
+ p[QUEUE] = queue;
job.setParametre(p);
// ... and its environment
Environnement e;
// Create a BatchManager of type ePBS on localhost
FactBatchManager_eClient * fbm = (FactBatchManager_eClient *)(c("ePBS"));
- BatchManager_eClient * bm = (*fbm)(host.c_str(), protocol, "lam");
+ BatchManager_eClient * bm = (*fbm)(host.c_str(), user.c_str(), protocol, "nompi", 8);
// Submit the job to the BatchManager
JobId jobid = bm->submitJob(job);
cout << jobid.__repr__() << endl;
// Wait for the end of the job
- int time = 0;
- int sleeptime = 1;
- bool testTimeout = (timeout > -1);
- bool timeoutReached = (testTimeout && time >= timeout);
- JobInfo jinfo = jobid.queryJob();
- string state = jinfo.getParametre()["STATE"].str();
- cout << "State is \"" << state << "\"";
- while (!timeoutReached && state != "U" && state != "C") {
- cout << ", sleeping " << sleeptime << "s..." << endl;
- sleep(sleeptime);
- time += sleeptime;
- timeoutReached = (testTimeout && time >= timeout);
- sleeptime *= 2;
- if (testTimeout && sleeptime > timeout - time)
- sleeptime = timeout - time;
- if (sleeptime > MAX_SLEEP_TIME)
- sleeptime = MAX_SLEEP_TIME;
- jinfo = jobid.queryJob();
- state = jinfo.getParametre()["STATE"].str();
- cout << "State is \"" << state << "\"";
- }
- cout << endl;
+ string state = bm->waitForJobEnd(jobid, timeout);
- if (state == "U" || state == "C") {
+ if (state == FINISHED || state == FAILED) {
cout << "Job " << jobid.__repr__() << " is done" << endl;
- bm->importOutputFiles(job, ".");
+ bm->importOutputFiles(job, "resultdir/seconddirname");
} else {
cerr << "Timeout while executing job" << endl;
return 1;
// test the result file
try {
SimpleParser resultParser;
- resultParser.parse("result.txt");
+ resultParser.parse("resultdir/seconddirname/result.txt");
cout << "Result:" << endl << resultParser;
const string & envvar = resultParser.getValue("MYENVVAR");
int result = resultParser.getValueAsInt("c");