// temporary directory on cluster to put input files for job
setDirForTmpFiles(job);
+ // Set Home director
+ setHomeDir(job);
+
// export input files on cluster
exportInputFiles(job);
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");
#include <vector>
#include <map>
#include <string>
+#include <fstream>
#include "Utils_SALOME_Exception.hxx"
#include <SALOMEconfig.h>
#include <stdlib.h>
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;
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 ){
// 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();
// Build command
command += protocol
+ " "
- + username + "@" + alias
- + " 'echo $HOME' > "
- + _test_filename + "_home";
+ + username + "@" + alias;
// Test
status = system(command.c_str());
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;
}
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;
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";
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;
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";
std::string _test_filename;
std::string _base_filename;
std::string _date;
- std::string _home;
};
#endif
_batch_params(batch_params)
{
_dirForTmpFiles = "/tmp/default_batch_tmp_directory";
- std::string _fileNameToExecute = "";
+ _home="";
}
Job::~Job()
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;
Engines::FilesList _filesToImport;
Engines::BatchParameters _batch_params;
std::string _dirForTmpFiles; // Tmp directory on the server
+ std::string _home; // Home directory on the server
private:
};