-
Notifications
You must be signed in to change notification settings - Fork 6
/
run-benchmark.py
executable file
·200 lines (154 loc) · 7.41 KB
/
run-benchmark.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
#! /usr/bin/env python
from optparse import OptionParser
import subprocess
#####################################
# mpirun command spawning functions
#####################################
# log file name generator
def generateLogFileName(options):
outFilePattern = "lP1"
outFilePattern += "T" + str(options.numThreads)
outFilePattern += "S" + str(options.numScale)
outFilePattern += "VR" + str(options.vertexReordering)
outFilePattern += "B" + str(options.bindMode)
return outFilePattern
# for OpenMPI
def spawnOpenMPI(options):
benchArgs = ["mpirun", "-np", "1", "-bind-to", "none"]
outFilePattern = generateLogFileName(options)
benchArgs.extend(["-output-filename", options.logfileDestination + "/" + outFilePattern])
benchArgs.extend(["-x", "OMP_NUM_THREADS=" + str(options.numThreads)])
if options.bindMode != "NONE":
benchArgs.extend(["-x", "OMP_PROC_BIND=" + options.bindMode])
if options.hostfile != "":
benchArgs.extend(["-hostfile", options.hostfile])
benchArgs.extend(["./mpi/runnable", str(options.numScale)])
returnCode = 0
if options.printCommandMode:
print(" ".join(benchArgs))
else:
benchProc = subprocess.Popen(benchArgs)
benchProc.communicate()
returnCode = benchProc.returncode
del benchProc
return returnCode
# for OpenMPI (<= version 1.6.5)
def spawnOpenMPIOld(options):
benchArgs = ["mpirun", "-np", "1", "-bind-to-none"]
outFilePattern = generateLogFileName(options)
benchArgs.extend(["-output-filename", options.logfileDestination + "/" + outFilePattern])
benchArgs.extend(["-x", "OMP_NUM_THREADS=" + str(options.numThreads)])
if options.bindMode != "NONE":
benchArgs.extend(["-x", "OMP_PROC_BIND=" + options.bindMode])
if options.hostfile != "":
benchArgs.extend(["-hostfile", options.hostfile])
benchArgs.extend(["./mpi/runnable", str(options.numScale)])
returnCode = 0
if options.printCommandMode:
print(" ".join(benchArgs))
else:
benchProc = subprocess.Popen(benchArgs)
benchProc.communicate()
returnCode = benchProc.returncode
del benchProc
return returnCode
# for MPICH/MVAPICH
def spawnMPICH(options):
benchArgs = ["mpirun", "-n", "1"]
outFilePattern = generateLogFileName(options)
benchArgs.extend(["-outfile-pattern", options.logfileDestination + "/" + outFilePattern])
benchArgs.extend(["-genv", "OMP_NUM_THREADS", str(options.numThreads)])
if options.bindMode != "NONE":
benchArgs.extend(["-genv", "OMP_PROC_BIND", options.bindMode])
if options.hostfile != "":
benchArgs.extend(["-hostfile", options.hostfile])
benchArgs.extend(["./mpi/runnable", str(options.numScale)])
returnCode = 0
if options.printCommandMode:
print(" ".join(benchArgs))
else:
benchProc = subprocess.Popen(benchArgs)
benchProc.communicate()
returnCode = benchProc.returncode
del benchProc
return returnCode
# parse command line arguments
parser = OptionParser()
parser.add_option("-t","--threads", action="store", dest="numThreads", default=4, type="int", help="number of threads")
parser.add_option("-s","--scale", action="store", dest="numScale", default=16, type="int", help="number of scale (when you specified --increasing-scale, this is treated as initial scale)")
parser.add_option("-v","--verbose", action="store_true", dest="verboseMode", default=False, help="enable verbose output in log")
parser.add_option("--vertex-reordering", action="store", dest="vertexReordering", type="int", default=0, help="vertex reordering mode : 0 = none, 1 = remove isolated vertices, 2 = 1 + reorder vertices by degree")
parser.add_option("-b", "--bind-mode", action="store", dest="bindMode", type="choice", choices=["NONE", "TRUE", "SPREAD", "CLOSE"], default="NONE", help="OpenMP process binding mode : NONE, TRUE, SPREAD, CLOSE (please search OMP_PROC_BIND for detail)")
parser.add_option("--test", action="store_true", dest="testMode", default=False, help="enable test mode (set the number of BFS execution times to 16)")
parser.add_option("--increasing-scale", action="store_true", dest="increasingScale", default=False, help="iterate benchmarking with increasing scale unless benchmarking process returns non-zero code")
parser.add_option("--logfile-dest", action="store", dest="logfileDestination", default="./log", type="string", help="set destination directory to store log files")
parser.add_option("--print-command", action="store_true", dest="printCommandMode", default=False, help="only print commands for benchmarking (don't execute benchmarking)")
parser.add_option("-m", "--mpi-runtime", action="store", dest="mpiRuntime", type="choice", choices=["OpenMPI", "OpenMPIOld", "MPICH", "MVAPICH"], default="MPICH", help="select MPI runtime : OpenMPI, OpenMPIOld (for version less than 1.6.5), MPICH, MVAPICH")
parser.add_option("--hostfile", action="store", dest="hostfile", default="", type="string", help="hostfile provided to mpirun")
(options, args) = parser.parse_args()
# confirmation
if not options.printCommandMode:
print("Number of Scale : " + str(options.numScale))
print("Number of Threads : " + str(options.numThreads))
print("Verbose Mode : " + str(options.verboseMode))
print("Vertex Reordering Mode : " + str(options.vertexReordering))
print("Thread Binding Mode : " + str(options.bindMode))
print("Test Mode : " + str(options.testMode))
# rebuild benchmark program
buildArgs = ["make"]
## set verbose option
if options.verboseMode:
buildArgs.append("VERBOSE=true")
## set vertex reordering options
buildArgs.append(" VERTEX_REORDERING=" + str(options.vertexReordering))
## set state whether benchmarking or testing
if not options.testMode:
buildArgs.append("REAL_BENCHMARK=true")
## append build target
buildArgs.append("cpu")
## compare previous build options and this time's
sameBuildOptions = False
try:
prevBuildOptFile = open("prev_build_options", "r")
prevBuildOptStr = prevBuildOptFile.readline()
if prevBuildOptStr == str(buildArgs):
sameBuildOptions = True
else:
sameBuildOptions = False
prevBuildOptFile.close()
prevBuildOptFile = open("prev_build_options", "w")
prevBuildOptFile.write(str(buildArgs))
prevBuildOptFile.close()
except IOError:
sameBuildOptions = False
prevBuildOptFile = open("prev_build_options", "w")
prevBuildOptFile.write(str(buildArgs))
#print(str(sameBuildOptions))
## rebuild if nesessary
if not sameBuildOptions:
if options.printCommandMode:
print("cd mpi")
print("make clean")
print(" ".join(buildArgs))
print("cd ..")
else:
buildProc = subprocess.Popen(["make", "clean"], cwd="mpi")
buildProc.communicate()
buildProc = subprocess.Popen(buildArgs, cwd="mpi")
buildProc.communicate()
# run benchmark
commandFunction = None
if options.mpiRuntime == "OpenMPI":
commandFunction = spawnOpenMPI
elif options.mpiRuntime == "OpenMPIOld":
commandFunction = spawnOpenMPIOld
elif options.mpiRuntime == "MPICH" or options.mpiRuntime == "MVAPICH":
commandFunction = spawnMPICH
while True:
returnCode = commandFunction(options)
if options.increasingScale and returnCode == 0 and not options.printCommandMode:
options.numScale += 1
print("continueing... scale : " + str(options.numScale))
else:
print("return code: " + str(returnCode))
break