forked from taskflow/taskflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbenchmarks.py
executable file
·171 lines (138 loc) · 3.71 KB
/
benchmarks.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
#!/usr/bin/env python3
import os
import subprocess
import sys
import math
import argparse
import matplotlib.pyplot as plot
import statistics as stat
tmp_file="/tmp/tmp.txt"
def analyze(Y):
print(
" -> [min, max, avg] = [%f, %f, %f]" %
(min(Y), max(Y), stat.mean(Y))
)
###########################################################
# regression: run
###########################################################
def run(target, method, thread, round):
exe = target + '/' + target
print(exe, '-m', method, '-t', thread, '-r', round)
with open(tmp_file, "w") as ofs:
subprocess.call(
[exe, '-m', method, '-t', str(thread), '-r', str(round)],
stdout=ofs
)
X = []
Y = []
with open(tmp_file, "r") as ifs:
ifs.readline()
ifs.readline()
for line in ifs:
token = line.split()
assert len(token) == 2, "output line must have exactly two numbers"
X.append(int(token[0]))
Y.append(float(token[1]))
#analyze(Y)
return X, Y
###########################################################
# main function
###########################################################
def main():
# example usage
# -b wavefront graph_traversal -t 1 2 3 -m tbb omp tf
parser = argparse.ArgumentParser(description='regression')
parser.add_argument(
'-b', '--benchmarks',
nargs='+',
help='list of benchmark names',
choices=['wavefront',
'graph_traversal',
'binary_tree',
'linear_chain',
'matrix_multiplication',
'mnist'],
required=True
)
parser.add_argument(
'-m','--methods',
nargs='+',
help='list of tasking methods',
default=['tf', 'tbb', 'omp'],
choices=['tf', 'tbb', 'omp']
)
parser.add_argument(
'-t', '--threads',
type=int,
nargs='+',
help='list of the number of threads',
required=True
)
parser.add_argument(
'-r', '--num_rounds',
type=int,
help='number of rounds to average',
default=1
)
parser.add_argument(
'-p', '--plot',
type=bool,
help='show the plot or not',
default=False
)
parser.add_argument(
'-o', '--output',
type=str,
help='file name to save the plot result',
default="result.png"
)
# parse the arguments
args = parser.parse_args()
print('benchmarks: ', args.benchmarks)
print('threads:', args.threads)
print('methods:', args.methods)
print('num_rounds:', args.num_rounds)
print('plot:', args.plot)
rows = len(args.benchmarks)
cols = len(args.threads)
figc = plot.rcParams["figure.figsize"][0]
figr = plot.rcParams["figure.figsize"][1]
plot.rcParams["figure.figsize"] = [figc*cols*0.5, figr*rows*0.5]
fig, axes = plot.subplots(rows, cols)
plot_index = 1
for benchmark in args.benchmarks:
for thread in args.threads:
ax = plot.subplot(rows, cols, plot_index)
for method in args.methods:
ax = plot.title(benchmark + ' (' + str(thread) + ' threads)')
X, Y = run(
benchmark, method, thread, args.num_rounds
)
#ax.text(
# .5, .9,
# benchmark + ' (' + str(thread) + ' threads)',
# horizontalalignment='center',
# transform=ax.transAxes
#)
if method == 'tf':
marker = ''
color = 'b'
elif method == 'omp':
marker = '+'
color = 'g'
else:
marker = '.'
color = 'r'
plot.plot(X, Y, label=method, marker=marker, color=color)
plot.legend()
print(X)
print(Y)
plot_index = plot_index + 1
plot.tight_layout()
plot.savefig(args.output)
if args.plot:
plot.show()
plot.close(fig)
# run the main entry
if __name__ == "__main__":
main()