This repository has been archived by the owner on Jan 29, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
runJobs.py
executable file
·218 lines (164 loc) · 5.56 KB
/
runJobs.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
#!/usr/bin/env python
##
## o-------------------------o
## | runJobs.py |
## | ~~~~~~~~~~~~~~~~~~~~~~~ |
## | Part of libTardis |
## o-------------------------o
##
import subprocess
from platform import node
from time import time
from datetime import datetime
from math import floor
from os import listdir, path, rename
from sys import exit, argv
from incFunctions import *
# General Settings
#------------------
sExec = "CISD" # Name of executable
sResultFile = "tempQueue/output.txt" # Exec result file
# Automatic Settings
#--------------------
sNode = node().strip()
if len(argv) > 1:
sComment = argv[1]
else:
sComment = "No comment"
# Initialisation
#----------------
print ""
print "Running on node: "+sNode
# Creating Directories
sMainLog = "jobLogs/"+sNode+"_"+datetime.today().strftime("%Y-%m-%d")+".log"
sLogSep = chr(9)+"| "
if not fDirX("jobFiles"): exit()
if not fDirX("jobQueue"): exit()
if not fDirX("jobQueue/Done"): exit()
if not fDirX("jobLogs"): exit()
if not fDirX("tempCompile"): exit()
if not fDirX("tempQueue"): exit()
iJobs = 0
aJobs = list()
for sObject in listdir("jobQueue"):
if not path.isdir("jobQueue/"+sObject):
aJobs.append(sObject)
iJobs += 1
aJobs.sort()
print "Job Queue has "+str(iJobs)+" jobs"
print ""
oFile = open(sMainLog, 'a')
oFile.write("\n")
oFile.write(" Jobs started at "+datetime.today().strftime("%Y-%m-%d %H:%M:%S")+"\n")
oFile.write(("*"*37)+"\n")
oFile.write(" Comment: "+sComment+"\n")
oFile.write("\n")
oFile.close()
iJob = 0
for sFile in aJobs:
dNow = datetime.today()
sLogDir = "jobLogs/"+dNow.strftime("%Y/%m/%d")
if not fDirX(sLogDir): exit()
sOutFile = sLogDir+"/"+sNode+"-"+dNow.strftime("%H%M%S")+".out"
sLogEntry = dNow.strftime("%Y-%m-%d %H:%M:%S")+sLogSep
sLogEntry += "Node: "+sNode+sLogSep
iJob += 1
sPrint = "Running Job "+str(iJob)+" of "+str(iJobs)+" : "+sFile
fEcho("o"+("-"*(len(sPrint)+2))+"o",sOutFile)
fEcho("| "+sPrint+" |",sOutFile)
fEcho("o"+("-"*(len(sPrint)+2))+"o",sOutFile)
fEcho("",sOutFile)
fEcho("TimeStamp: "+datetime.today().strftime("%Y-%m-%d %H:%M:%S"),sOutFile)
fEcho("",sOutFile)
# Reading Options
#-----------------
fEcho("Reading Settings ...",sOutFile)
aOptions = fReadJobFile("jobQueue/"+sFile)
fEcho("",sOutFile)
sNSlater = fGetOption("Slater", aOptions, "64")
oFile = open("libTardis/slaterword.hpp", 'r')
sPSlater = oFile.read()
oFile.close()
if sPSlater[19:].strip() != sNSlater:
oFile = open("libTardis/slaterword.hpp", 'w')
oFile.write("#define SLATER_WORD "+sNSlater+"\n")
oFile.close()
# Compiler
#----------
sOldMain = "tempCompile/"+sNode+"/main.o"
if os.path.exists(sOldMain):
os.remove(sOldMain)
sExecName = sExec+"-"+sNode
iNodes = fGetOption("Nodes", aOptions, "1")
if int(iNodes) > 1:
sCompileString = "make CC=mpic++ LIBADD='-lmpi' NODE="+sNode+" MAIN=jobQueue/"+sFile
else:
sCompileString = "make NODE="+sNode+" MAIN=jobQueue/"+sFile
fEcho(" Calling: "+sCompileString,sOutFile)
fEcho("*"*(len(sCompileString)+11),sOutFile)
subprocess.call(sCompileString+" 2>&1 | tee -a "+sOutFile, shell=True)
sLastLine = open(sOutFile, 'r').readlines()[-1].strip()
if sLastLine[-7:] == "Error 1" or sLastLine[-5:] == "Stop.":
fEcho("",sOutFile)
fEcho("!!! Compiler error !!!",sOutFile)
fEcho("!!! Aborting !!!",sOutFile)
fEcho("",sOutFile)
continue
fEcho("",sOutFile)
fEcho("TimeStamp: "+datetime.today().strftime("%Y-%m-%d %H:%M:%S"),sOutFile)
fEcho("",sOutFile)
# Execution
#-----------
fEcho(" Running Program: "+sExecName,sOutFile)
fEcho("*"*(len(sExecName)+19),sOutFile)
if os.path.exists(sResultFile):
os.remove(sResultFile)
tExecStart = time()
if int(iNodes) > 1:
subprocess.call("mpirun -np "+iNodes+" ./"+sExecName+" "+chr(34)+sOutFile+chr(34), shell=True)
else:
subprocess.call("./"+sExecName+" "+chr(34)+sOutFile+chr(34), shell=True)
tExecStop = time()
tExecTime = tExecStop-tExecStart
fEcho("",sOutFile)
if os.path.exists(sResultFile):
oFile = open(sResultFile, 'r')
sResult = oFile.readline().strip()
oFile.close()
fEcho(" Result:",sOutFile)
fEcho("*********",sOutFile)
fEcho(sResult,sOutFile)
sResult.replace("\n", " :: ")
sResult.replace("\r", "")
sLogEntry += sResult+sLogSep
#~ os.rename("jobQueue/"+sFile, "jobQueue/Done/"+sFile)
# Timer Output
#--------------
sExecTime = ""
if tExecTime > 86400:
sExecTime += str(int(floor(tExecTime/86400)))+"d "
tExecTime %= 86400
if tExecTime > 3600:
sExecTime += str(int(floor(tExecTime/3600)))+"h "
tExecTime %= 3600
if tExecTime > 60:
sExecTime += str(int(floor(tExecTime/60)))+"m "
tExecTime %= 60
if tExecTime > 1:
sExecTime += str(int(floor(tExecTime)))+"s "
tExecTime %= 1
sExecTime += str(int(floor(tExecTime*1000)))+"ms"
sLogEntry += "Exec: "+sExecTime
fEcho("",sOutFile)
fEcho("TimeStamp: "+datetime.today().strftime("%Y-%m-%d %H:%M:%S"),sOutFile)
fEcho("",sOutFile)
fEcho("Execution time: "+sExecTime,sOutFile)
fEcho("",sOutFile)
# Job Log
#---------
oFile = open(sMainLog, 'a')
oFile.write(sLogEntry+"\n")
oFile.close()
if iJob < iJobs:
print "*"*95
print ""