Created
April 11, 2014 17:32
-
-
Save lebedov/10486422 to your computer and use it in GitHub Desktop.
Automatically create and submit Torque job script with specified commands to qsub.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
""" | |
Automatically create and submit Torque job script with specified commands to qsub. | |
""" | |
import argparse | |
import os | |
import pwd | |
import tempfile | |
parser = argparse.ArgumentParser() | |
parser.add_argument('-l', nargs=1, default='nodes=1:gpus=4:ppn=4', help='qsub resources') | |
parser.add_argument('-n', nargs=1, default=None, | |
help='string to use as job basename (default is username-[unique suffix])') | |
parser.add_argument('-c', required=True, nargs=argparse.REMAINDER, help='commands to submit') | |
args = parser.parse_args() | |
if type(args.l) is list: | |
args.l = args.l[0] | |
username = pwd.getpwuid(os.getuid()).pw_name | |
if args.n is None: | |
fd, name = tempfile.mkstemp(dir=os.path.expanduser('~'), prefix=username+'-') | |
else: | |
name = args.n[0] | |
with open(name, 'w') as f: | |
f.write('#!/bin/sh\n') | |
f.write('#PBS -l '+args.l+'\n') | |
f.write('cd '+os.getcwd()+'\n') | |
f.write(' '.join(args.c)+'\n') | |
os.system('/usr/bin/qsub %s' % name) | |
os.remove(name) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment