forked from kunyuan/FeynCalculator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
send.py
executable file
·112 lines (95 loc) · 3.95 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
104
105
106
107
108
109
110
111
112
#!/usr/bin/python
import random
import os, sys
##### Modify parameters here ###############
Cluster="local"
# Cluster="PBS"
# Cluster="condor"
compiler="ifort"
# compiler="gfortran"
execute="feyncalc"
############################################
sourcedir=os.getcwd()
filelist=os.listdir(sourcedir)
sourcename=[elem for elem in filelist if elem[0:len(execute)]==execute and elem[-3:]=="f90"]
print sourcename
sourcename.sort()
sourcename=sourcename[-1]
tothomedir=os.getcwd()
inlist=open(tothomedir+"/inlist","r")
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{1}_rs{2}_lambda{3}_{0}".format(title, para[0], para[1], para[2])
if(os.path.exists(homedir)!=True):
os.system("mkdir "+homedir)
os.system("cp DiagPolar*.txt "+homedir)
os.system(compiler+" "+sourcedir+"/"+sourcename+" -O3 -o "+homedir+"/"+execute)
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)
if(os.path.exists(homedir+"/Data")!=True):
os.system("mkdir "+homedir+"/Data")
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("pwd")
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)