forked from taskflow/taskflow
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathregression.py
More file actions
140 lines (113 loc) · 3.14 KB
/
regression.py
File metadata and controls
140 lines (113 loc) · 3.14 KB
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
#!/usr/bin/env python
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():
parser = argparse.ArgumentParser(description='regression')
parser.add_argument(
'-b', '--benchmarks',
nargs='+',
help='valid benchmarks: wavefront, graph_traversal',
choices=['wavefront',
'graph_traversal',
'binary_tree',
'linear_chain',
'matrix_multiplication',
'mnist'],
required=True
)
parser.add_argument(
'-m','--methods',
nargs='+',
help='valid methods: omp, tbb, tf',
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
)
# 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)
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
#)
plot.plot(X, Y, label=method)
plot.legend()
print(X)
print(Y)
plot_index = plot_index + 1
plot.tight_layout()
plot.savefig('result.png')
plot.show()
plot.close(fig)
# run the main entry
if __name__ == "__main__":
main()