1 | #!/usr/bin/env python |
---|
2 | |
---|
3 | """Run job in parallel using PBS batch system with |
---|
4 | specified number of processors |
---|
5 | |
---|
6 | Syntax |
---|
7 | run_parallel_job.py 4 <prog> |
---|
8 | """ |
---|
9 | |
---|
10 | queue = 'normal' |
---|
11 | walltime = '00:10:00' |
---|
12 | vmem = '1Mb' |
---|
13 | |
---|
14 | import sys, string, time, os |
---|
15 | arg = sys.argv |
---|
16 | command = arg[0] |
---|
17 | ext = '.py' |
---|
18 | |
---|
19 | if len(arg)<3: |
---|
20 | print __doc__ |
---|
21 | print 'Usage:' |
---|
22 | print command + ' p <filename>' + ext |
---|
23 | sys.exit() |
---|
24 | |
---|
25 | numproc = int(arg[1]) |
---|
26 | progname = arg[2] |
---|
27 | |
---|
28 | |
---|
29 | #Create batchfile |
---|
30 | |
---|
31 | s = """ |
---|
32 | #!/bin/csh |
---|
33 | |
---|
34 | # This file is automatically generated - don't edit |
---|
35 | # |
---|
36 | |
---|
37 | #PBS -wd |
---|
38 | #PBS -q %s |
---|
39 | #PBS -l ncpus=%d |
---|
40 | #PBS -l walltime=%s,vmem=%s |
---|
41 | #PBS -l software=python |
---|
42 | |
---|
43 | prun %s""" %(queue, numproc, walltime, vmem, progname) |
---|
44 | |
---|
45 | |
---|
46 | scriptname = progname + '.run' |
---|
47 | fid = open(scriptname, 'w') |
---|
48 | fid.write(s) |
---|
49 | fid.close() |
---|
50 | |
---|
51 | #Cleanup |
---|
52 | os.system('/bin/rm *.o* *.e*') |
---|
53 | |
---|
54 | # Run |
---|
55 | os.system('qsub %s' %scriptname) |
---|
56 | os.system('/bin/rm %s' %scriptname) |
---|
57 | |
---|
58 | #Create check scripts |
---|
59 | fid = open('q', 'w') |
---|
60 | fid.write("""#!/bin/csh |
---|
61 | #This file is generated automatically. |
---|
62 | #Any modifications will be lost. |
---|
63 | #Edit runjob.py instead. |
---|
64 | echo '--------------------------------------------' |
---|
65 | nqstat %s\n""" %queue) |
---|
66 | fid.close() |
---|
67 | |
---|
68 | #fid = open('o', 'w') |
---|
69 | #fid.write("""#!/bin/csh |
---|
70 | ##This file is generated automatically. |
---|
71 | ##Any modifications will be lost. |
---|
72 | ##Edit runjob.py instead. |
---|
73 | #cat %s.e* %s.o*\n""" %((progname,)*2)) |
---|
74 | #fid.close() |
---|
75 | |
---|
76 | |
---|
77 | fid = open('o', 'w') |
---|
78 | fid.write("""#!/bin/csh |
---|
79 | #This file is generated automatically. |
---|
80 | #Any modifications will be lost. |
---|
81 | #Edit runjob.py instead. |
---|
82 | cat *.e* *.o*\n""") |
---|
83 | |
---|
84 | fid.close() |
---|
85 | |
---|
86 | os.system('chmod +x o q') |
---|
87 | |
---|
88 | |
---|
89 | |
---|
90 | |
---|
91 | |
---|
92 | |
---|
93 | |
---|
94 | |
---|
95 | |
---|