1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 * Batch_BatchManager_eLL.cxx :
25 * Created on: 25 nov. 2010
26 * Author : Renaud BARATE - EDF R&D
32 #include <Batch_NotYetImplementedException.hxx>
34 #include "Batch_BatchManager_eLL.hxx"
35 #include "Batch_JobInfo_eLL.hxx"
41 BatchManager_eLL::BatchManager_eLL(const FactBatchManager * parent, const char * host,
42 const char * username,
43 CommunicationProtocolType protocolType, const char * mpiImpl,
45 : BatchManager(parent, host),
46 BatchManager_eClient(parent, host, username, protocolType, mpiImpl)
51 BatchManager_eLL::~BatchManager_eLL()
56 // Method to submit a job to the batch manager
57 const JobId BatchManager_eLL::submitJob(const Job & job)
60 Parametre params = job.getParametre();
61 const string workDir = params[WORKDIR];
63 // export input files on cluster
64 exportInputFiles(job);
66 // build command file to submit the job and copy it on the server
67 string cmdFile = buildCommandFile(job);
69 // define name of log file (local)
70 string logFile = generateTemporaryFileName("LL-submitlog");
72 // define command to submit batch
73 string subCommand = string("cd ") + workDir + "; llsubmit " + cmdFile;
74 string command = _protocol.getExecCommand(subCommand, _hostname, _username);
77 cerr << command.c_str() << endl;
78 status = system(command.c_str());
81 ifstream error_message(logFile.c_str());
84 while(getline(error_message, temp))
86 error_message.close();
87 throw EmulationException("Error of connection on remote host, error was: " + mess);
90 // read id of submitted job in log file
92 ifstream idfile(logFile.c_str());
94 while (idfile && line.compare(0, 9, "llsubmit:") != 0)
95 getline(idfile, line);
97 if (line.compare(0, 9, "llsubmit:") == 0)
99 string::size_type p1 = line.find_first_of("\"");
100 string::size_type p2 = line.find_last_of("\"");
102 jobref = line.substr(p1 + 1, p2 - p1 - 1);
104 if (jobref.size() == 0)
105 throw EmulationException("Error in the submission of the job on the remote host");
107 JobId id(this, jobref);
112 * Create LoadLeveler command file and copy it on the server.
113 * Return the name of the remote file.
115 string BatchManager_eLL::buildCommandFile(const Job & job)
117 Parametre params = job.getParametre();
121 string fileToExecute = "";
124 // Mandatory parameters
125 if (params.find(WORKDIR) != params.end())
126 workDir = params[WORKDIR].str();
128 throw EmulationException("params[WORKDIR] is not defined. Please define it, cannot submit this job.");
129 if (params.find(EXECUTABLE) != params.end())
130 fileToExecute = params[EXECUTABLE].str();
132 throw EmulationException("params[EXECUTABLE] is not defined. Please define it, cannot submit this job.");
134 string::size_type p1 = fileToExecute.find_last_of("/");
135 string::size_type p2 = fileToExecute.find_last_of(".");
136 string rootNameToExecute = fileToExecute.substr(p1+1,p2-p1-1);
137 string fileNameToExecute = fileToExecute.substr(p1+1);
139 // Create batch submit file
140 ofstream tempOutputFile;
141 string tmpFileName = createAndOpenTemporaryFile("LL-script", tempOutputFile);
143 tempOutputFile << "#!/bin/bash" << endl;
144 tempOutputFile << "# @ output = " << workDir << "/logs/output.log." << rootNameToExecute << endl;
145 tempOutputFile << "# @ error = " << workDir << "/logs/error.log." << rootNameToExecute << endl;
147 // Optional parameters
148 if (params.find(MAXWALLTIME) != params.end())
149 tempOutputFile << "# @ wall_clock_limit = " << params[MAXWALLTIME] << ":00" << endl;
150 if (params.find(MAXRAMSIZE) != params.end())
151 tempOutputFile << "# @ as_limit = " << params[MAXRAMSIZE] << "mb" << endl;
152 if (params.find(QUEUE) != params.end())
153 tempOutputFile << "# @ class = " << params[QUEUE] << endl;
155 // Define environment for the job
156 Environnement env = job.getEnvironnement();
158 tempOutputFile << "# @ environment = ";
159 Environnement::const_iterator iter;
160 for (iter = env.begin() ; iter != env.end() ; ++iter) {
161 tempOutputFile << iter->first << "=" << iter->second << "; ";
163 tempOutputFile << endl;
166 tempOutputFile << "# @ job_type = bluegene" << endl;
167 tempOutputFile << "# @ queue" << endl;
169 // generate nodes file
170 tempOutputFile << "NODEFILE=`mktemp nodefile-XXXXXXXXXX` || exit 1" << endl;
171 tempOutputFile << "for node in $LOADL_PROCESSOR_LIST; do" << endl;
172 tempOutputFile << " echo $node >> $NODEFILE" << endl;
173 tempOutputFile << "done" << endl;
174 tempOutputFile << "export LIBBATCH_NODEFILE=$NODEFILE" << endl;
176 // Launch the executable
177 tempOutputFile << "cd " << workDir << endl;
178 tempOutputFile << "./" + fileNameToExecute << endl;
180 tempOutputFile.flush();
181 tempOutputFile.close();
183 cerr << "Batch script file generated is: " << tmpFileName << endl;
185 string remoteFileName = rootNameToExecute + "_LL.cmd";
186 int status = _protocol.copyFile(tmpFileName, "", "",
187 workDir + "/" + remoteFileName,
188 _hostname, _username);
190 throw EmulationException("Cannot copy command file on host " + _hostname);
192 return remoteFileName;
195 void BatchManager_eLL::deleteJob(const JobId & jobid)
197 // define command to delete job
198 string subCommand = "llcancel " + jobid.getReference();
199 string command = _protocol.getExecCommand(subCommand, _hostname, _username);
200 cerr << command.c_str() << endl;
202 int status = system(command.c_str());
204 throw EmulationException("Can't delete job " + jobid.getReference());
206 cerr << "job " << jobid.getReference() << " killed" << endl;
209 void BatchManager_eLL::holdJob(const JobId & jobid)
211 throw NotYetImplementedException("BatchManager_eLL::holdJob");
214 void BatchManager_eLL::releaseJob(const JobId & jobid)
216 throw NotYetImplementedException("BatchManager_eLL::releaseJob");
219 void BatchManager_eLL::alterJob(const JobId & jobid, const Parametre & param, const Environnement & env)
221 throw NotYetImplementedException("BatchManager_eLL::alterJob");
224 void BatchManager_eLL::alterJob(const JobId & jobid, const Parametre & param)
226 throw NotYetImplementedException("BatchManager_eLL::alterJob");
229 void BatchManager_eLL::alterJob(const JobId & jobid, const Environnement & env)
231 throw NotYetImplementedException("BatchManager_eLL::alterJob");
234 JobInfo BatchManager_eLL::queryJob(const JobId & jobid)
236 // define name of log file (local)
237 string logFile = generateTemporaryFileName("LL-querylog-" + jobid.getReference());
239 // define command to query batch
240 string subCommand = "llq -f %st " + jobid.getReference();
241 string command = _protocol.getExecCommand(subCommand, _hostname, _username);
244 cerr << command.c_str() << endl;
245 int status = system(command.c_str());
247 throw EmulationException("Can't query job " + jobid.getReference());
249 JobInfo_eLL jobinfo = JobInfo_eLL(jobid.getReference(), logFile);
253 const JobId BatchManager_eLL::addJob(const Job & job, const string reference)
255 throw NotYetImplementedException("BatchManager_eLL::addJob");