4 * Auteur : Ivan DUTKA-MALEN - EDF R&D
5 * Mail : mailto:ivan.dutka-malen@der.edf.fr
6 * Date : Fri Nov 14 11:00:39 2003
16 #include "Batch_Job_LSF.hxx"
22 Job_LSF::Job_LSF(const Job & job) : _p_submit(0)
24 Parametre P = job.getParametre();
25 _p_submit = ParametreToSubmitStruct(P);
33 if (_p_submit->jobName) delete [] _p_submit->jobName;
34 if (_p_submit->queue) delete [] _p_submit->queue;
35 if (_p_submit->askedHosts) {
36 delete [] *(_p_submit->askedHosts);
37 delete [] _p_submit->askedHosts;
39 if (_p_submit->resReq) delete [] _p_submit->resReq;
40 if (_p_submit->hostSpec) delete [] _p_submit->hostSpec;
41 if (_p_submit->dependCond) delete [] _p_submit->dependCond;
42 if (_p_submit->timeEvent) delete [] _p_submit->timeEvent;
43 if (_p_submit->inFile) delete [] _p_submit->inFile;
44 if (_p_submit->outFile) delete [] _p_submit->outFile;
45 if (_p_submit->errFile) delete [] _p_submit->errFile;
46 if (_p_submit->command) delete [] _p_submit->command;
47 if (_p_submit->newCommand) delete [] _p_submit->newCommand;
48 if (_p_submit->chkpntDir) delete [] _p_submit->chkpntDir;
49 if (_p_submit->xf) delete [] _p_submit->xf;
50 if (_p_submit->preExecCmd) delete [] _p_submit->preExecCmd;
51 if (_p_submit->mailUser) delete [] _p_submit->mailUser;
52 if (_p_submit->projectName) delete [] _p_submit->projectName;
53 if (_p_submit->loginShell) delete [] _p_submit->loginShell;
54 if (_p_submit->exceptList) delete [] _p_submit->exceptList;
61 struct submit * Job_LSF::getSubmitStruct()
67 char * Job_LSF::string2char(const string & s)
69 char * ch = new char [s.size() + 1];
70 memset(ch, 0, s.size() + 1);
71 strncat(ch, s.c_str(), s.size());
76 struct submit * Job_LSF::ParametreToSubmitStruct(const Parametre & P)
78 if (! _p_submit) _p_submit = new struct submit;
80 memset( (void *) _p_submit, 0, sizeof(struct submit));
82 struct submit & sub = * _p_submit;
86 sub.beginTime = 0; // job can run as soon as possible (default)
87 sub.termTime = 0; // job can run as long as it wishes (default)
89 sub.numProcessors = 1; // job can run on one single processor (default)
90 sub.maxNumProcessors = 1; // job can run on one single processor (default)
92 for(int i = 0; i< LSF_RLIM_NLIMITS; i++) sub.rLimits[i] = DEFAULT_RLIMIT;
94 typedef std::vector< struct xFile > XFTAB;
98 for(Parametre::const_iterator it = P.begin(); it != P.end(); it++) {
99 if ( (*it).first == ACCOUNT ) {
100 sub.options |= SUB_PROJECT_NAME;
101 st_second = (*it).second.str();
102 sub.projectName = string2char(st_second);
104 } else if ( (*it).first == CHECKPOINT ) {
105 if (static_cast< long >((*it).second))
106 sub.options |= SUB_CHKPNT_PERIOD;
108 sub.options &= ~ SUB_CHKPNT_PERIOD;
110 } else if ( (*it).first == CKPTINTERVAL ) {
111 sub.chkpntPeriod = static_cast< long >((*it).second);
113 } else if ( (*it).first == EXECUTABLE ) {
114 st_second = (*it).second.str();
115 sub.command = string2char(st_second);
117 } else if ( (*it).first == EXECUTIONHOST ) {
118 sub.options |= SUB_HOST;
119 if (! sub.numAskedHosts) {
120 sub.numAskedHosts = 1;
121 sub.askedHosts = new char* [1];
123 st_second = (*it).second.str();
124 sub.askedHosts[0] = string2char(st_second);
126 } else if ( (*it).first == HOLD ) {
127 if (static_cast< long >((*it).second))
128 sub.options2 |= SUB2_HOLD;
130 sub.options2 &= ~ SUB2_HOLD;
132 } else if ( (*it).first == INFILE ) {
133 Versatile V = (*it).second;
134 Versatile::iterator Vit;
136 for(Vit=V.begin(); Vit!=V.end(); Vit++) {
137 CoupleType cpt = *static_cast< CoupleType * >(*Vit);
139 string local = cp.getLocal();
140 string remote = cp.getRemote();
142 // 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
143 if (remote == "stdin"){
144 sub.options |= SUB_IN_FILE;
145 sub.inFile = string2char(local);
149 strncpy(xf.subFn, local.c_str(), MAXFILENAMELEN - 1); xf.subFn[MAXFILENAMELEN - 1] = 0;
150 strncpy(xf.execFn, remote.c_str(), MAXFILENAMELEN - 1); xf.execFn[MAXFILENAMELEN - 1] = 0;
151 xf.options = XF_OP_SUB2EXEC;
152 xf_tab.push_back(xf);
156 } else if ( (*it).first == MAIL ) {
157 sub.options |= SUB_MAIL_USER;
158 st_second = (*it).second.str();
159 sub.mailUser = string2char(st_second);
161 } else if ( (*it).first == MAXCPUTIME ) {
162 sub.rLimits[LSF_RLIMIT_CPU] = static_cast< long >((*it).second);
164 } else if ( (*it).first == MAXDISKSIZE ) {
165 sub.rLimits[LSF_RLIMIT_FSIZE] = static_cast< long >((*it).second);
167 } else if ( (*it).first == MAXRAMSIZE ) {
168 sub.rLimits[LSF_RLIMIT_SWAP] = static_cast< long >((*it).second);
170 } else if ( (*it).first == MAXWALLTIME ) {
171 sub.rLimits[LSF_RLIMIT_RUN] = static_cast< long >((*it).second);
173 } else if ( (*it).first == NAME ) {
174 sub.options |= SUB_JOB_NAME;
175 st_second = (*it).second.str();
176 sub.jobName = string2char(st_second);
178 } else if ( (*it).first == NBPROC ) {
179 sub.numProcessors = static_cast< long >((*it).second);
180 sub.maxNumProcessors = static_cast< long >((*it).second);
182 } else if ( (*it).first == OUTFILE ) {
183 Versatile V = (*it).second;
184 Versatile::iterator Vit;
186 for(Vit=V.begin(); Vit!=V.end(); Vit++) {
187 CoupleType cpt = *static_cast< CoupleType * >(*Vit);
189 string local = cp.getLocal();
190 string remote = cp.getRemote();
192 // 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
193 if (remote == "stdout"){
194 sub.options |= SUB_OUT_FILE;
195 sub.outFile = string2char(local);
197 } else if (remote == "stderr"){
198 sub.options |= SUB_ERR_FILE;
199 sub.errFile = string2char(local);
203 strncpy(xf.subFn, local.c_str(), MAXFILENAMELEN - 1); xf.subFn[MAXFILENAMELEN - 1] = 0;
204 strncpy(xf.execFn, remote.c_str(), MAXFILENAMELEN - 1); xf.execFn[MAXFILENAMELEN - 1] = 0;
205 xf.options = XF_OP_EXEC2SUB;
206 xf_tab.push_back(xf);
211 } else if ( (*it).first == QUEUE ) {
212 sub.options |= SUB_QUEUE;
213 st_second = (*it).second.str();
214 sub.queue = string2char(st_second);
216 } else if ( (*it).first == STARTTIME ) {
217 sub.beginTime = static_cast< long >((*it).second);
219 } else if ( (*it).first == TMPDIR ) {
222 } else if ( (*it).first == USER ) {
229 // Transfert de fichiers en entree et sortie
230 sub.options |= SUB_OTHER_FILES;
231 sub.nxf = xf_tab.size();
232 sub.xf = new struct xFile [sub.nxf];
234 for(XFTAB::const_iterator it_xf=xf_tab.begin(); it_xf != xf_tab.end(); it_xf++, ixf++)
235 sub.xf[ixf] = *it_xf; // *it_xf == xf_tab[ixf]