Skip to content

Commit

Permalink
Modified to load each module separately, work around bug in PBS qsub
Browse files Browse the repository at this point in the history
  • Loading branch information
bjpop committed Aug 26, 2011
1 parent e1523f8 commit a4ac685
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions cluster_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ def waitForJobCompletion(jobID):
sleep(10)

def runJobAndWait(script):
#print jobScript
print(script)
jobID = script.launch()
#print jobID
waitForJobCompletion(jobID)

class PBS_Script(object):
def __init__(self, command, walltime=None, name=None, memInGB=None, queue='batch', moduleList=None):
def __init__(self, command, walltime=None, name=None, memInGB=None, queue='batch', moduleList=None, logDir=None):
self.command = command
if queue in ['batch', 'smp']:
self.queue = queue
Expand All @@ -37,13 +37,17 @@ def __init__(self, command, walltime=None, name=None, memInGB=None, queue='batch
self.memInGB = memInGB
self.walltime = walltime
self.moduleList = moduleList
self.logDir = logDir

def __str__(self):
script = ['#!/bin/bash']
# XXX hack
script.append('#PBS -o log/%s' % self.name)
script.append('#PBS -e log/%s' % self.name)
# XXX fixme
# should include job id in the output name.
# should use the proper log directory.
script.append('#PBS -q %s' % self.queue)
if self.logDir:
script.append('#PBS -o %s' % self.logDir)
script.append('#PBS -e %s' % self.logDir)
if self.name:
script.append('#PBS -N %s' % self.name)
if self.memInGB:
Expand All @@ -54,7 +58,8 @@ def __str__(self):
if self.walltime:
script.append('#PBS -l walltime=%s' % self.walltime)
if type(self.moduleList) == list and len(self.moduleList) > 0:
script.append('module load %s' % ' '.join(self.moduleList))
for item in self.moduleList:
script.append('module load %s' % item)
script.append('cd $PBS_O_WORKDIR')
script.append(self.command)
return '\n'.join(script) + '\n'
Expand All @@ -70,7 +75,3 @@ def launch(self):
return stdout
else:
raise(Exception('qsub command failed with exit status: ' + str(returnCode)))

#waitForJobCompletion(jobID)
#jobScript = PBS_Script("sleep 50", "00:00:50", "sleepy", "1")
#runJobAndWait(jobScript)

0 comments on commit a4ac685

Please sign in to comment.