1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 * Auteur : Ivan DUTKA-MALEN - EDF R&D
24 * Mail : mailto:ivan.dutka-malen@der.edf.fr
25 * Date : Fri Nov 14 11:00:39 2003
35 #include "Batch_Job_LSF.hxx"
43 Job_LSF::Job_LSF(const Job & job) : _p_submit(0)
45 Parametre P = job.getParametre();
46 _p_submit = ParametreToSubmitStruct(P);
54 if (_p_submit->jobName) delete [] _p_submit->jobName;
55 if (_p_submit->queue) delete [] _p_submit->queue;
56 if (_p_submit->askedHosts) {
57 delete [] *(_p_submit->askedHosts);
58 delete [] _p_submit->askedHosts;
60 if (_p_submit->resReq) delete [] _p_submit->resReq;
61 if (_p_submit->hostSpec) delete [] _p_submit->hostSpec;
62 if (_p_submit->dependCond) delete [] _p_submit->dependCond;
63 if (_p_submit->timeEvent) delete [] _p_submit->timeEvent;
64 if (_p_submit->inFile) delete [] _p_submit->inFile;
65 if (_p_submit->outFile) delete [] _p_submit->outFile;
66 if (_p_submit->errFile) delete [] _p_submit->errFile;
67 if (_p_submit->command) delete [] _p_submit->command;
68 if (_p_submit->newCommand) delete [] _p_submit->newCommand;
69 if (_p_submit->chkpntDir) delete [] _p_submit->chkpntDir;
70 if (_p_submit->xf) delete [] _p_submit->xf;
71 if (_p_submit->preExecCmd) delete [] _p_submit->preExecCmd;
72 if (_p_submit->mailUser) delete [] _p_submit->mailUser;
73 if (_p_submit->projectName) delete [] _p_submit->projectName;
74 if (_p_submit->loginShell) delete [] _p_submit->loginShell;
75 if (_p_submit->exceptList) delete [] _p_submit->exceptList;
82 struct submit * Job_LSF::getSubmitStruct()
88 char * Job_LSF::string2char(const string & s)
90 char * ch = new char [s.size() + 1];
91 memset(ch, 0, s.size() + 1);
92 strncat(ch, s.c_str(), s.size());
97 struct submit * Job_LSF::ParametreToSubmitStruct(const Parametre & P)
99 if (! _p_submit) _p_submit = new struct submit;
101 memset( (void *) _p_submit, 0, sizeof(struct submit));
103 struct submit & sub = * _p_submit;
107 sub.beginTime = 0; // job can run as soon as possible (default)
108 sub.termTime = 0; // job can run as long as it wishes (default)
110 sub.numProcessors = 1; // job can run on one single processor (default)
111 sub.maxNumProcessors = 1; // job can run on one single processor (default)
113 for(int i = 0; i< LSF_RLIM_NLIMITS; i++) sub.rLimits[i] = DEFAULT_RLIMIT;
115 typedef std::vector< struct xFile > XFTAB;
119 for(Parametre::const_iterator it = P.begin(); it != P.end(); it++) {
120 if ( (*it).first == ACCOUNT ) {
121 sub.options |= SUB_PROJECT_NAME;
122 st_second = (*it).second.str();
123 sub.projectName = string2char(st_second);
125 } else if ( (*it).first == CHECKPOINT ) {
126 if (static_cast< long >((*it).second))
127 sub.options |= SUB_CHKPNT_PERIOD;
129 sub.options &= ~ SUB_CHKPNT_PERIOD;
131 } else if ( (*it).first == CKPTINTERVAL ) {
132 sub.chkpntPeriod = static_cast< long >((*it).second);
134 } else if ( (*it).first == EXECUTABLE ) {
135 st_second = (*it).second.str();
136 sub.command = string2char(st_second);
138 } else if ( (*it).first == EXECUTIONHOST ) {
139 sub.options |= SUB_HOST;
140 if (! sub.numAskedHosts) {
141 sub.numAskedHosts = 1;
142 sub.askedHosts = new char* [1];
144 st_second = (*it).second.str();
145 sub.askedHosts[0] = string2char(st_second);
147 } else if ( (*it).first == HOLD ) {
148 if (static_cast< long >((*it).second))
149 sub.options2 |= SUB2_HOLD;
151 sub.options2 &= ~ SUB2_HOLD;
153 } else if ( (*it).first == INFILE ) {
154 Versatile V = (*it).second;
155 Versatile::iterator Vit;
157 for(Vit=V.begin(); Vit!=V.end(); Vit++) {
158 CoupleType cpt = *static_cast< CoupleType * >(*Vit);
160 string local = cp.getLocal();
161 string remote = cp.getRemote();
163 // ATTENTION : les notions de fichier "local" ou "remote" sont inverses de celle de PBS qui a un point de vue serveur et non pas utilisateur
164 if (remote == "stdin"){
165 sub.options |= SUB_IN_FILE;
166 sub.inFile = string2char(local);
170 strncpy(xf.subFn, local.c_str(), MAXFILENAMELEN - 1); xf.subFn[MAXFILENAMELEN - 1] = 0;
171 strncpy(xf.execFn, remote.c_str(), MAXFILENAMELEN - 1); xf.execFn[MAXFILENAMELEN - 1] = 0;
172 xf.options = XF_OP_SUB2EXEC;
173 xf_tab.push_back(xf);
177 } else if ( (*it).first == MAIL ) {
178 sub.options |= SUB_MAIL_USER;
179 st_second = (*it).second.str();
180 sub.mailUser = string2char(st_second);
182 } else if ( (*it).first == MAXCPUTIME ) {
183 sub.rLimits[LSF_RLIMIT_CPU] = static_cast< long >((*it).second);
185 } else if ( (*it).first == MAXDISKSIZE ) {
186 sub.rLimits[LSF_RLIMIT_FSIZE] = static_cast< long >((*it).second);
188 } else if ( (*it).first == MAXRAMSIZE ) {
189 sub.rLimits[LSF_RLIMIT_SWAP] = static_cast< long >((*it).second);
191 } else if ( (*it).first == MAXWALLTIME ) {
192 sub.rLimits[LSF_RLIMIT_RUN] = static_cast< long >((*it).second);
194 } else if ( (*it).first == NAME ) {
195 sub.options |= SUB_JOB_NAME;
196 st_second = (*it).second.str();
197 sub.jobName = string2char(st_second);
199 } else if ( (*it).first == NBPROC ) {
200 sub.numProcessors = static_cast< long >((*it).second);
201 sub.maxNumProcessors = static_cast< long >((*it).second);
203 } else if ( (*it).first == OUTFILE ) {
204 Versatile V = (*it).second;
205 Versatile::iterator Vit;
207 for(Vit=V.begin(); Vit!=V.end(); Vit++) {
208 CoupleType cpt = *static_cast< CoupleType * >(*Vit);
210 string local = cp.getLocal();
211 string remote = cp.getRemote();
213 // ATTENTION : les notions de fichier "local" ou "remote" sont inverses de celle de PBS qui a un point de vue serveur et non pas utilisateur
214 if (remote == "stdout"){
215 sub.options |= SUB_OUT_FILE;
216 sub.outFile = string2char(local);
218 } else if (remote == "stderr"){
219 sub.options |= SUB_ERR_FILE;
220 sub.errFile = string2char(local);
224 strncpy(xf.subFn, local.c_str(), MAXFILENAMELEN - 1); xf.subFn[MAXFILENAMELEN - 1] = 0;
225 strncpy(xf.execFn, remote.c_str(), MAXFILENAMELEN - 1); xf.execFn[MAXFILENAMELEN - 1] = 0;
226 xf.options = XF_OP_EXEC2SUB;
227 xf_tab.push_back(xf);
232 } else if ( (*it).first == QUEUE ) {
233 sub.options |= SUB_QUEUE;
234 st_second = (*it).second.str();
235 sub.queue = string2char(st_second);
237 } else if ( (*it).first == STARTTIME ) {
238 sub.beginTime = static_cast< long >((*it).second);
240 } else if ( (*it).first == TMPDIR ) {
243 } else if ( (*it).first == USER ) {
250 // Transfert de fichiers en entree et sortie
251 sub.options |= SUB_OTHER_FILES;
252 sub.nxf = xf_tab.size();
253 sub.xf = new struct xFile [sub.nxf];
255 for(XFTAB::const_iterator it_xf=xf_tab.begin(); it_xf != xf_tab.end(); it_xf++, ixf++)
256 sub.xf[ixf] = *it_xf; // *it_xf == xf_tab[ixf]