Show More
@@ -331,15 +331,11 b' class PBSEngineSet(BatchEngineSet):' | |||
|
331 | 331 | def __init__(self, template_file, **kwargs): |
|
332 | 332 | BatchEngineSet.__init__(self, template_file, **kwargs) |
|
333 | 333 | |
|
334 |
class SGEEngineSet( |
|
|
335 | ||
|
336 | submit_command = 'qsub' | |
|
337 | delete_command = 'qdel' | |
|
338 | job_id_regexp = '\d+' | |
|
334 | class SGEEngineSet(PBSEngineSet): | |
|
339 | 335 | |
|
340 | 336 | def __init__(self, template_file, **kwargs): |
|
341 | 337 | BatchEngineSet.__init__(self, template_file, **kwargs) |
|
342 |
self. |
|
|
338 | self._temp_file = None | |
|
343 | 339 | |
|
344 | 340 | def parse_job_id(self, output): |
|
345 | 341 | m = re.search(self.job_id_regexp, output) |
@@ -347,47 +343,41 b' class SGEEngineSet(BatchEngineSet):' | |||
|
347 | 343 | job_id = m.group() |
|
348 | 344 | else: |
|
349 | 345 | raise Exception("job id couldn't be determined: %s" % output) |
|
350 |
self.job_id |
|
|
351 |
log.msg(' |
|
|
346 | self.job_id = job_id | |
|
347 | log.msg('job started with job id: %r' % job_id) | |
|
352 | 348 | return job_id |
|
353 | 349 | |
|
354 | def kill_job(self, output): | |
|
355 | log.msg(output) | |
|
356 | return output | |
|
357 | ||
|
358 | def write_batch_script(self, i): | |
|
359 | context = {'eid':i} | |
|
360 | template = open(self.template_file, 'r').read() | |
|
361 | log.msg('Using template for batch script: %s' % self.template_file) | |
|
362 | script_as_string = Itpl.itplns(template, context) | |
|
363 | log.msg('Writing instantiated batch script: %s' % self.batch_file+str(i)) | |
|
364 | f = open(self.batch_file+str(i),'w') | |
|
365 | f.write(script_as_string) | |
|
366 | f.close() | |
|
367 | ||
|
368 | 350 | def start(self, n): |
|
369 | dlist = [] | |
|
370 | self.num_engines = 0 | |
|
371 | self.job_id = [] | |
|
372 | for i in range(n): | |
|
373 |
log.msg(" |
|
|
374 | self.write_batch_script(i) | |
|
351 | log.msg("starting %d engines" % n) | |
|
352 | self._temp_file = tempfile.NamedTemporaryFile() | |
|
353 | regex = re.compile('#\$[ \t]+-t[ \t]+\d+') | |
|
354 | if self.template_file: | |
|
355 | log.msg("Using sge script %s" % self.template_file) | |
|
356 | contents = open(self.template_file, 'r').read() | |
|
357 | if not regex.search(contents): | |
|
358 | log.msg("adding job array settings to sge script") | |
|
359 | contents = ("#$ -t 1-%d\n" % n) + contents | |
|
360 | self._temp_file.write(contents) | |
|
361 | self.template_file = self._temp_file.name | |
|
362 | else: | |
|
363 | log.msg("using default ipengine sge script: \n%s" % | |
|
364 | (sge_template % n)) | |
|
365 | self._temp_file.file.write(sge_template % n) | |
|
366 | self.template_file = self._temp_file.name | |
|
367 | self._temp_file.file.flush() | |
|
375 | 368 |
|
|
376 |
|
|
|
369 | [self.template_file], | |
|
370 | env=os.environ) | |
|
377 | 371 |
|
|
378 | 372 |
|
|
379 | dlist.append(d) | |
|
380 | return gatherBoth(dlist, consumeErrors=True) | |
|
373 | return d | |
|
381 | 374 | |
|
382 | def kill(self): | |
|
383 | dlist = [] | |
|
384 | for i in range(self.num_engines): | |
|
385 | log.msg("killing job id: %d"%self.job_id[i]) | |
|
386 | d = getProcessOutput(self.delete_command, | |
|
387 | [self.job_id[i]],env=os.environ) | |
|
388 | d.addCallback(self.kill_job) | |
|
389 | dlist.append(d) | |
|
390 | return gatherBoth(dlist, consumeErrors=True) | |
|
375 | sge_template="""#$ -V | |
|
376 | #$ -t 1-%d | |
|
377 | #$ -N ipengine | |
|
378 | eid=$(($SGE_TASK_ID - 1)) | |
|
379 | ipengine --logfile=ipengine${eid}.log | |
|
380 | """ | |
|
391 | 381 | |
|
392 | 382 | sshx_template="""#!/bin/sh |
|
393 | 383 | "$@" &> /dev/null & |
@@ -697,6 +687,10 b' def main_sge(args):' | |||
|
697 | 687 | if not check_reuse(args, cont_args): |
|
698 | 688 | return |
|
699 | 689 | |
|
690 | if args.sgescript and not os.path.isfile(args.sgescript): | |
|
691 | log.err('SGE script does not exist: %s' % args.sgescript) | |
|
692 | return | |
|
693 | ||
|
700 | 694 | cl = ControllerLauncher(extra_args=cont_args) |
|
701 | 695 | dstart = cl.start() |
|
702 | 696 | def start_engines(r): |
@@ -877,7 +871,7 b' def get_args():' | |||
|
877 | 871 | type=str, |
|
878 | 872 | dest='sgescript', |
|
879 | 873 | help='SGE script template', |
|
880 | default='template.sge' | |
|
874 | default='' # SGEEngineSet will create one if not specified | |
|
881 | 875 | ) |
|
882 | 876 | parser_sge.set_defaults(func=main_sge) |
|
883 | 877 |
General Comments 0
You need to be logged in to leave comments.
Login now