forked from kunyuan/DSEMC
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsend.py
executable file
·103 lines (88 loc) · 3.39 KB
/
send.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/python
import random
import os
import sys
##### Modify parameters here ###############
# Cluster="PBS"
Cluster = "local"
# Cluster="condor"
############################################
rootdir = os.getcwd()
inlist = open(rootdir+"/inlist", "r")
execute = "feyncalc.exe"
for index, eachline in enumerate(inlist):
para = eachline.split()
if len(para) == 0:
print "All submitted!"
break
# if int(para[-2])==0:
# title="freq"
# elif int(para[-2])==1:
# title="eqTime"
# else:
# print "Not yet implemented!"
# break
homedir = os.getcwd() + \
"/Beta{0}_rs{1}_lambda{2}".format(para[0], para[1], para[2])
if(os.path.exists(homedir) != True):
os.system("mkdir "+homedir)
os.system("cp -r groups "+homedir)
os.system("cp {0} {1}".format(execute, homedir))
infilepath = homedir+"/infile"
if(os.path.exists(infilepath) != True):
os.system("mkdir "+infilepath)
outfilepath = homedir+"/outfile"
if(os.path.exists(outfilepath) != True):
os.system("mkdir "+outfilepath)
jobfilepath = homedir+"/jobfile"
if(os.path.exists(jobfilepath) != True):
os.system("mkdir "+jobfilepath)
for pid in range(int(para[-1])):
########## Generate input files ################
infile = "_in"+str(pid)
f = open(infilepath+"/"+infile, "w")
item = para[0:-1]
item.append(str(-int(random.random()*1000000)))
item.append(str(pid))
stri = " ".join(item)
f.write(stri)
f.close()
### terminal output goes here #############
outfile = "_out"+str(pid)
### job file to submit to cluster ########
jobfile = "_job"+str(pid)+".sh"
if Cluster == "local":
os.chdir(homedir)
os.system("./"+execute+" < "+infilepath+"/" +
infile+" > "+outfilepath+"/"+outfile+" &")
os.chdir("..")
elif Cluster == "condor":
with open(jobfilepath+"/"+jobfile, "w") as fjob:
fjob.write("executable = {0}\n".format(execute))
fjob.write("input ={0}/{1}\n".format(infilepath, infile))
fjob.write("output ={0}/{1}\n".format(outfilepath, outfile))
fjob.write("initialdir ={0}\n".format(homedir))
fjob.write("queue")
os.chdir(homedir)
os.system("condor_submit {0}/{1}".format(jobfilepath, jobfile))
os.system("rm "+jobfilepath + "/"+jobfile)
os.chdir("..")
elif Cluster == "PBS":
with open(jobfilepath+"/"+jobfile, "w") as fjob:
fjob.write("#!/bin/sh\n"+"#PBS -N "+jobfile+"\n")
fjob.write("#PBS -o "+homedir+"/Output\n")
fjob.write("#PBS -e "+homedir+"/Error\n")
fjob.write("#PBS -l walltime=2000:00:00\n")
fjob.write("echo $PBS_JOBID >>"+homedir+"/id_job.log\n")
fjob.write("cd "+homedir+"\n")
fjob.write("./"+execute+" < "+infilepath+"/" +
infile+" > "+outfilepath+"/"+outfile)
os.chdir(homedir)
os.system("qsub "+jobfilepath + "/"+jobfile)
os.system("rm "+jobfilepath + "/"+jobfile)
os.chdir("..")
else:
print("I don't know what is {0}".format(Cluster))
break
print("Jobs manage daemon is ended")
sys.exit(0)