-
Notifications
You must be signed in to change notification settings - Fork 1
QsubPyBsc
Adrian Quintana edited this page Dec 11, 2017
·
1 revision
#!/usr/bin/env python
"""This is a script to isolate each qsub implementation from
the user. It needs to be modified for each cluster:
std_file is a template pbs file
The command line options and replace are machine dependent
"""
import os, string
import sys
import optparse
#check command line
def main():
std_file="""
#!/bin/bash
# @ job_name = XXXjobIDXXX
# @ initialdir = XXXiniDIRXXX
# @ output = OUTPUT/XXXjobIDXXX_%j.out
# @ error = OUTPUT/XXXjobIDXXX_%j.err
# @ total_tasks = XXXtasksXXX
# @ cpus_per_task = XXXppnXXX
# @ wall_clock_limit = XXXhoursXXX:00:00
# Environment
export OBJECT_MODE=64
export MP_RSH=ssh
mkdir -p OUTPUT
python XXXscriptXXX
""".strip()#note strip removes first newline
#check command line
####Crunchy####
parser = optparse.OptionParser("usage: %prog [options] protocols_file.py")
parser.add_option("-t", "--time", dest="wallClockTime",
default="72", type="int",
help="Maximum execution time in wallclock hours (default=24)")
parser.add_option("-i", "--id", dest="jobID", default='-1',
type="string", help="Job ID (default=-1)")
#options are the options ;-)
#arg the values that do not requiere '-flags', that is, the python script
(options, args) = parser.parse_args()
if len(args) < 1:
parser.print_help()
return
wallClockTime = options.wallClockTime
jobID = options.jobID
inFileName = args[1]
#get NumberOfMpiProcesses and NumberOfThreads from protocol script itself
pyFile = open(inFileName,"r")
doParallel = False
numberOfThreads = 1
numberOfNodes = 1
while 1:
line = (pyFile.readline()).replace('\n','')
if (line.find("WorkingDir") == 0):
myline=line.split("=")
workingDir=myline[1].replace('/','_')
elif (line.find("NumberOfThreads") == 0):
myline=line.split("=")
numberOfThreads = int(myline[1])
elif (line.find("DoParallel=True") == 0):
doParallel = True
elif (line.find("NumberOfMpiProcesses") == 0):
myline=line.split("=")
numberOfNodes = int(myline[1])
elif (line.find("end-of-header") > 0):
break
if (not doParallel):
numberOfNodes = 1
if (jobID == '-1'):
jobID=workingDir.replace("'","")
jobID=jobID.replace('"','')
numberOfTasks = numberOfNodes * numberOfThreads
iniDIR = str(os.getcwd())
#Replace old words with new ones
outFileName=inFileName.replace(".py",".job");
o = open(outFileName,"w")
std_file = std_file.replace("XXXjobIDXXX",jobID)
std_file = std_file.replace("XXXiniDIRXXX",iniDIR)
std_file = std_file.replace("XXXtasksXXX",str(numberOfTasks))
std_file = std_file.replace("XXXppnXXX",str(numberOfThreads))
std_file = std_file.replace("XXXhoursXXX",str(wallClockTime))
std_file = std_file.replace("XXXscriptXXX",inFileName)
#create command and add it (as a comment) to the job file
command = "mnsubmit "
command += outFileName
o.write(std_file)
o.close()
# Give the user some feedback
print "---------------------------------------"
print "qsub.py made job with:"
print "# @ job_name = " + jobID
print "# @ initialdir = " + iniDIR
print "# @ output = OUTPUT/" + jobID + "_%j.out"
print "# @ error = OUTPUT/" + jobID + "_%j.err"
print "# @ total_tasks = " + str(numberOfTasks)
print "# @ cpus_per_task = " + str(numberOfThreads)
print "# @ wall_clock_limit = " + str(wallClockTime) + ":00:00"
print " "
print "and submitted this script using command:"
print command
print "---------------------------------------"
# Really submit the job to the queue
os.system(command)
if __name__ == '__main__':
main()