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(QUEUE) != params.end())
151 tempOutputFile << "# @ class = " << params[QUEUE] << endl;
153 // Define environment for the job
154 Environnement env = job.getEnvironnement();
156 tempOutputFile << "# @ environment = ";
157 Environnement::const_iterator iter;
158 for (iter = env.begin() ; iter != env.end() ; ++iter) {
159 tempOutputFile << iter->first << "=" << iter->second << "; ";
161 tempOutputFile << endl;
164 tempOutputFile << "# @ job_type = bluegene" << endl;
165 tempOutputFile << "# @ queue" << endl;
167 // generate nodes file
168 tempOutputFile << "NODEFILE=`mktemp nodefile-XXXXXXXXXX` || exit 1" << endl;
169 tempOutputFile << "for node in $LOADL_PROCESSOR_LIST; do" << endl;
170 tempOutputFile << " echo $node >> $NODEFILE" << endl;
171 tempOutputFile << "done" << endl;
172 tempOutputFile << "export LIBBATCH_NODEFILE=$NODEFILE" << endl;
174 // Launch the executable
175 tempOutputFile << "cd " << workDir << endl;
176 tempOutputFile << "./" + fileNameToExecute << endl;
178 tempOutputFile.flush();
179 tempOutputFile.close();
181 cerr << "Batch script file generated is: " << tmpFileName << endl;
183 string remoteFileName = rootNameToExecute + "_LL.cmd";
184 int status = _protocol.copyFile(tmpFileName, "", "",
185 workDir + "/" + remoteFileName,
186 _hostname, _username);
188 throw EmulationException("Cannot copy command file on host " + _hostname);
190 return remoteFileName;
193 void BatchManager_eLL::deleteJob(const JobId & jobid)
195 // define command to delete job
196 string subCommand = "llcancel " + jobid.getReference();
197 string command = _protocol.getExecCommand(subCommand, _hostname, _username);
198 cerr << command.c_str() << endl;
200 int status = system(command.c_str());
202 throw EmulationException("Can't delete job " + jobid.getReference());
204 cerr << "job " << jobid.getReference() << " killed" << endl;
207 void BatchManager_eLL::holdJob(const JobId & jobid)
209 throw NotYetImplementedException("BatchManager_eLL::holdJob");
212 void BatchManager_eLL::releaseJob(const JobId & jobid)
214 throw NotYetImplementedException("BatchManager_eLL::releaseJob");
217 void BatchManager_eLL::alterJob(const JobId & jobid, const Parametre & param, const Environnement & env)
219 throw NotYetImplementedException("BatchManager_eLL::alterJob");
222 void BatchManager_eLL::alterJob(const JobId & jobid, const Parametre & param)
224 throw NotYetImplementedException("BatchManager_eLL::alterJob");
227 void BatchManager_eLL::alterJob(const JobId & jobid, const Environnement & env)
229 throw NotYetImplementedException("BatchManager_eLL::alterJob");
232 JobInfo BatchManager_eLL::queryJob(const JobId & jobid)
234 // define name of log file (local)
235 string logFile = generateTemporaryFileName("LL-querylog-" + jobid.getReference());
237 // define command to query batch
238 string subCommand = "llq -f %st " + jobid.getReference();
239 string command = _protocol.getExecCommand(subCommand, _hostname, _username);
242 cerr << command.c_str() << endl;
243 int status = system(command.c_str());
245 throw EmulationException("Can't query job " + jobid.getReference());
247 JobInfo_eLL jobinfo = JobInfo_eLL(jobid.getReference(), logFile);
251 const JobId BatchManager_eLL::addJob(const Job & job, const string reference)
253 throw NotYetImplementedException("BatchManager_eLL::addJob");