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
33 #include <Batch_NotYetImplementedException.hxx>
35 #include "Batch_BatchManager_eLL.hxx"
36 #include "Batch_JobInfo_eLL.hxx"
42 BatchManager_eLL::BatchManager_eLL(const FactBatchManager * parent, const char * host,
43 const char * username,
44 CommunicationProtocolType protocolType, const char * mpiImpl,
46 : BatchManager(parent, host),
47 BatchManager_eClient(parent, host, username, protocolType, mpiImpl),
48 _nb_proc_per_node(nb_proc_per_node)
53 BatchManager_eLL::~BatchManager_eLL()
58 // Method to submit a job to the batch manager
59 const JobId BatchManager_eLL::submitJob(const Job & job)
62 Parametre params = job.getParametre();
63 const string workDir = params[WORKDIR];
65 // export input files on cluster
66 exportInputFiles(job);
68 // build command file to submit the job and copy it on the server
69 string cmdFile = buildCommandFile(job);
71 // define name of log file (local)
72 string logFile = generateTemporaryFileName("LL-submitlog");
74 // define command to submit batch
75 string subCommand = string("cd ") + workDir + "; llsubmit " + cmdFile;
76 string command = _protocol.getExecCommand(subCommand, _hostname, _username);
79 cerr << command.c_str() << endl;
80 status = system(command.c_str());
83 ifstream error_message(logFile.c_str());
86 while(getline(error_message, temp))
88 error_message.close();
89 throw EmulationException("Error of connection on remote host, error was: " + mess);
92 // read id of submitted job in log file
94 ifstream idfile(logFile.c_str());
96 while (idfile && line.compare(0, 9, "llsubmit:") != 0)
97 getline(idfile, line);
99 if (line.compare(0, 9, "llsubmit:") == 0)
101 string::size_type p1 = line.find_first_of("\"");
102 string::size_type p2 = line.find_last_of("\"");
104 jobref = line.substr(p1 + 1, p2 - p1 - 1);
106 if (jobref.size() == 0)
107 throw EmulationException("Error in the submission of the job on the remote host");
109 JobId id(this, jobref);
114 * Create LoadLeveler command file and copy it on the server.
115 * Return the name of the remote file.
117 string BatchManager_eLL::buildCommandFile(const Job & job)
119 Parametre params = job.getParametre();
123 string fileToExecute = "";
126 // Mandatory parameters
127 if (params.find(WORKDIR) != params.end())
128 workDir = params[WORKDIR].str();
130 throw EmulationException("params[WORKDIR] is not defined. Please define it, cannot submit this job.");
131 if (params.find(EXECUTABLE) != params.end())
132 fileToExecute = params[EXECUTABLE].str();
134 throw EmulationException("params[EXECUTABLE] is not defined. Please define it, cannot submit this job.");
136 string::size_type p1 = fileToExecute.find_last_of("/");
137 string::size_type p2 = fileToExecute.find_last_of(".");
138 string rootNameToExecute = fileToExecute.substr(p1+1,p2-p1-1);
139 string fileNameToExecute = fileToExecute.substr(p1+1);
141 // Create batch submit file
142 ofstream tempOutputFile;
143 string tmpFileName = createAndOpenTemporaryFile("LL-script", tempOutputFile);
145 tempOutputFile << "#!/bin/bash" << endl;
146 tempOutputFile << "# @ output = " << workDir << "/logs/output.log." << rootNameToExecute << endl;
147 tempOutputFile << "# @ error = " << workDir << "/logs/error.log." << rootNameToExecute << endl;
148 tempOutputFile << "# @ node_usage = not_shared" << endl;
150 if (params.find(NAME) != params.end())
151 tempOutputFile << "# @ job_name = " << params[NAME] << endl;
153 // Optional parameters
155 if (params.find(NBPROC) != params.end())
156 nbproc = params[NBPROC];
158 // tempOutputFile << "# @ job_type = serial" << endl;
160 // tempOutputFile << "# @ job_type = parallel" << endl;
161 int nodes_requested = (nbproc + _nb_proc_per_node -1) / _nb_proc_per_node;
162 tempOutputFile << "# @ job_type = mpich" << endl;
163 tempOutputFile << "# @ node = " << nodes_requested << endl;
164 tempOutputFile << "# @ tasks_per_node = " << _nb_proc_per_node << endl;
166 //tempOutputFile << "# @ job_type = bluegene" << endl;
168 if (params.find(MAXWALLTIME) != params.end())
169 tempOutputFile << "# @ wall_clock_limit = " << params[MAXWALLTIME] << ":00" << endl;
170 if (params.find(MAXRAMSIZE) != params.end())
171 tempOutputFile << "# @ as_limit = " << params[MAXRAMSIZE] << "mb" << endl;
172 if (params.find(QUEUE) != params.end())
173 tempOutputFile << "# @ class = " << params[QUEUE] << endl;
175 // Define environment for the job
176 Environnement env = job.getEnvironnement();
178 tempOutputFile << "# @ environment = ";
179 Environnement::const_iterator iter;
180 for (iter = env.begin() ; iter != env.end() ; ++iter) {
181 tempOutputFile << iter->first << "=" << iter->second << "; ";
183 tempOutputFile << endl;
186 tempOutputFile << "# @ queue" << endl;
188 // generate nodes file
189 tempOutputFile << "NODEFILE=`mktemp nodefile-XXXXXXXXXX` || exit 1" << endl;
190 tempOutputFile << "for node in $LOADL_PROCESSOR_LIST; do" << endl;
191 tempOutputFile << " echo $node >> $NODEFILE" << endl;
192 tempOutputFile << "done" << endl;
193 tempOutputFile << "export LIBBATCH_NODEFILE=$NODEFILE" << endl;
195 // Launch the executable
196 tempOutputFile << "cd " << workDir << endl;
197 tempOutputFile << "./" + fileNameToExecute << endl;
199 tempOutputFile.flush();
200 tempOutputFile.close();
202 cerr << "Batch script file generated is: " << tmpFileName << endl;
204 string remoteFileName = rootNameToExecute + "_LL.cmd";
205 int status = _protocol.copyFile(tmpFileName, "", "",
206 workDir + "/" + remoteFileName,
207 _hostname, _username);
209 throw EmulationException("Cannot copy command file on host " + _hostname);
211 return remoteFileName;
214 void BatchManager_eLL::deleteJob(const JobId & jobid)
216 // define command to delete job
217 string subCommand = "llcancel " + jobid.getReference();
218 string command = _protocol.getExecCommand(subCommand, _hostname, _username);
219 cerr << command.c_str() << endl;
221 int status = system(command.c_str());
223 throw EmulationException("Can't delete job " + jobid.getReference());
225 cerr << "job " << jobid.getReference() << " killed" << endl;
228 void BatchManager_eLL::holdJob(const JobId & jobid)
230 throw NotYetImplementedException("BatchManager_eLL::holdJob");
233 void BatchManager_eLL::releaseJob(const JobId & jobid)
235 throw NotYetImplementedException("BatchManager_eLL::releaseJob");
238 void BatchManager_eLL::alterJob(const JobId & jobid, const Parametre & param, const Environnement & env)
240 throw NotYetImplementedException("BatchManager_eLL::alterJob");
243 void BatchManager_eLL::alterJob(const JobId & jobid, const Parametre & param)
245 throw NotYetImplementedException("BatchManager_eLL::alterJob");
248 void BatchManager_eLL::alterJob(const JobId & jobid, const Environnement & env)
250 throw NotYetImplementedException("BatchManager_eLL::alterJob");
253 JobInfo BatchManager_eLL::queryJob(const JobId & jobid)
255 // define name of log file (local)
256 string logFile = generateTemporaryFileName("LL-querylog-" + jobid.getReference());
258 // define command to query batch
259 string subCommand = "llq -f %st " + jobid.getReference();
260 string command = _protocol.getExecCommand(subCommand, _hostname, _username);
263 cerr << command.c_str() << endl;
264 int status = system(command.c_str());
266 throw EmulationException("Can't query job " + jobid.getReference());
268 JobInfo_eLL jobinfo = JobInfo_eLL(jobid.getReference(), logFile);
272 const JobId BatchManager_eLL::addJob(const Job & job, const string reference)
274 throw NotYetImplementedException("BatchManager_eLL::addJob");