1 // Copyright (C) 2007-2008 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
25 * Auteur : Ivan DUTKA-MALEN - EDF R&D
26 * Mail : mailto:ivan.dutka-malen@der.edf.fr
27 * Date : Fri Nov 14 11:00:39 2003
37 #include "Batch_Job_LSF.hxx"
45 Job_LSF::Job_LSF(const Job & job) : _p_submit(0)
47 Parametre P = job.getParametre();
48 _p_submit = ParametreToSubmitStruct(P);
56 if (_p_submit->jobName) delete [] _p_submit->jobName;
57 if (_p_submit->queue) delete [] _p_submit->queue;
58 if (_p_submit->askedHosts) {
59 delete [] *(_p_submit->askedHosts);
60 delete [] _p_submit->askedHosts;
62 if (_p_submit->resReq) delete [] _p_submit->resReq;
63 if (_p_submit->hostSpec) delete [] _p_submit->hostSpec;
64 if (_p_submit->dependCond) delete [] _p_submit->dependCond;
65 if (_p_submit->timeEvent) delete [] _p_submit->timeEvent;
66 if (_p_submit->inFile) delete [] _p_submit->inFile;
67 if (_p_submit->outFile) delete [] _p_submit->outFile;
68 if (_p_submit->errFile) delete [] _p_submit->errFile;
69 if (_p_submit->command) delete [] _p_submit->command;
70 if (_p_submit->newCommand) delete [] _p_submit->newCommand;
71 if (_p_submit->chkpntDir) delete [] _p_submit->chkpntDir;
72 if (_p_submit->xf) delete [] _p_submit->xf;
73 if (_p_submit->preExecCmd) delete [] _p_submit->preExecCmd;
74 if (_p_submit->mailUser) delete [] _p_submit->mailUser;
75 if (_p_submit->projectName) delete [] _p_submit->projectName;
76 if (_p_submit->loginShell) delete [] _p_submit->loginShell;
77 if (_p_submit->exceptList) delete [] _p_submit->exceptList;
84 struct submit * Job_LSF::getSubmitStruct()
90 char * Job_LSF::string2char(const string & s)
92 char * ch = new char [s.size() + 1];
93 memset(ch, 0, s.size() + 1);
94 strncat(ch, s.c_str(), s.size());
99 struct submit * Job_LSF::ParametreToSubmitStruct(const Parametre & P)
101 if (! _p_submit) _p_submit = new struct submit;
103 memset( (void *) _p_submit, 0, sizeof(struct submit));
105 struct submit & sub = * _p_submit;
109 sub.beginTime = 0; // job can run as soon as possible (default)
110 sub.termTime = 0; // job can run as long as it wishes (default)
112 sub.numProcessors = 1; // job can run on one single processor (default)
113 sub.maxNumProcessors = 1; // job can run on one single processor (default)
115 for(int i = 0; i< LSF_RLIM_NLIMITS; i++) sub.rLimits[i] = DEFAULT_RLIMIT;
117 typedef std::vector< struct xFile > XFTAB;
121 for(Parametre::const_iterator it = P.begin(); it != P.end(); it++) {
122 if ( (*it).first == ACCOUNT ) {
123 sub.options |= SUB_PROJECT_NAME;
124 st_second = (*it).second.str();
125 sub.projectName = string2char(st_second);
127 } else if ( (*it).first == CHECKPOINT ) {
128 if (static_cast< long >((*it).second))
129 sub.options |= SUB_CHKPNT_PERIOD;
131 sub.options &= ~ SUB_CHKPNT_PERIOD;
133 } else if ( (*it).first == CKPTINTERVAL ) {
134 sub.chkpntPeriod = static_cast< long >((*it).second);
136 } else if ( (*it).first == EXECUTABLE ) {
137 st_second = (*it).second.str();
138 sub.command = string2char(st_second);
140 } else if ( (*it).first == EXECUTIONHOST ) {
141 sub.options |= SUB_HOST;
142 if (! sub.numAskedHosts) {
143 sub.numAskedHosts = 1;
144 sub.askedHosts = new char* [1];
146 st_second = (*it).second.str();
147 sub.askedHosts[0] = string2char(st_second);
149 } else if ( (*it).first == HOLD ) {
150 if (static_cast< long >((*it).second))
151 sub.options2 |= SUB2_HOLD;
153 sub.options2 &= ~ SUB2_HOLD;
155 } else if ( (*it).first == INFILE ) {
156 Versatile V = (*it).second;
157 Versatile::iterator Vit;
159 for(Vit=V.begin(); Vit!=V.end(); Vit++) {
160 CoupleType cpt = *static_cast< CoupleType * >(*Vit);
162 string local = cp.getLocal();
163 string remote = cp.getRemote();
165 // 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
166 if (remote == "stdin"){
167 sub.options |= SUB_IN_FILE;
168 sub.inFile = string2char(local);
172 strncpy(xf.subFn, local.c_str(), MAXFILENAMELEN - 1); xf.subFn[MAXFILENAMELEN - 1] = 0;
173 strncpy(xf.execFn, remote.c_str(), MAXFILENAMELEN - 1); xf.execFn[MAXFILENAMELEN - 1] = 0;
174 xf.options = XF_OP_SUB2EXEC;
175 xf_tab.push_back(xf);
179 } else if ( (*it).first == MAIL ) {
180 sub.options |= SUB_MAIL_USER;
181 st_second = (*it).second.str();
182 sub.mailUser = string2char(st_second);
184 } else if ( (*it).first == MAXCPUTIME ) {
185 sub.rLimits[LSF_RLIMIT_CPU] = static_cast< long >((*it).second);
187 } else if ( (*it).first == MAXDISKSIZE ) {
188 sub.rLimits[LSF_RLIMIT_FSIZE] = static_cast< long >((*it).second);
190 } else if ( (*it).first == MAXRAMSIZE ) {
191 sub.rLimits[LSF_RLIMIT_SWAP] = static_cast< long >((*it).second);
193 } else if ( (*it).first == MAXWALLTIME ) {
194 sub.rLimits[LSF_RLIMIT_RUN] = static_cast< long >((*it).second);
196 } else if ( (*it).first == NAME ) {
197 sub.options |= SUB_JOB_NAME;
198 st_second = (*it).second.str();
199 sub.jobName = string2char(st_second);
201 } else if ( (*it).first == NBPROC ) {
202 sub.numProcessors = static_cast< long >((*it).second);
203 sub.maxNumProcessors = static_cast< long >((*it).second);
205 } else if ( (*it).first == OUTFILE ) {
206 Versatile V = (*it).second;
207 Versatile::iterator Vit;
209 for(Vit=V.begin(); Vit!=V.end(); Vit++) {
210 CoupleType cpt = *static_cast< CoupleType * >(*Vit);
212 string local = cp.getLocal();
213 string remote = cp.getRemote();
215 // 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
216 if (remote == "stdout"){
217 sub.options |= SUB_OUT_FILE;
218 sub.outFile = string2char(local);
220 } else if (remote == "stderr"){
221 sub.options |= SUB_ERR_FILE;
222 sub.errFile = string2char(local);
226 strncpy(xf.subFn, local.c_str(), MAXFILENAMELEN - 1); xf.subFn[MAXFILENAMELEN - 1] = 0;
227 strncpy(xf.execFn, remote.c_str(), MAXFILENAMELEN - 1); xf.execFn[MAXFILENAMELEN - 1] = 0;
228 xf.options = XF_OP_EXEC2SUB;
229 xf_tab.push_back(xf);
234 } else if ( (*it).first == QUEUE ) {
235 sub.options |= SUB_QUEUE;
236 st_second = (*it).second.str();
237 sub.queue = string2char(st_second);
239 } else if ( (*it).first == STARTTIME ) {
240 sub.beginTime = static_cast< long >((*it).second);
242 } else if ( (*it).first == TMPDIR ) {
245 } else if ( (*it).first == USER ) {
252 // Transfert de fichiers en entree et sortie
253 sub.options |= SUB_OTHER_FILES;
254 sub.nxf = xf_tab.size();
255 sub.xf = new struct xFile [sub.nxf];
257 for(XFTAB::const_iterator it_xf=xf_tab.begin(); it_xf != xf_tab.end(); it_xf++, ixf++)
258 sub.xf[ixf] = *it_xf; // *it_xf == xf_tab[ixf]