-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_result.py
More file actions
69 lines (62 loc) · 1.95 KB
/
plot_result.py
File metadata and controls
69 lines (62 loc) · 1.95 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
import sys, getopt
import re
import os
import matplotlib.pyplot as plt
from pprint import pprint
def test_func(fun_name, r):
os.system('make ' + fun_name)
# The following data is for sequential performance
res = []
num_pars = []
for i in xrange(1000, r, 1000):
tmp = os.popen('./' + fun_name + ' -no -n '+str(i)).read()
p = re.compile('(\d+.\d+)')
outcome = p.findall(tmp)
num_pars.append(int(outcome[0]))
res.append(float(outcome[1]))
return (num_pars, res)
def main(argv):
output_file = ''
func_name = ''
plot = True
r = 10000
try:
opts, args = getopt.getopt(argv, "hf:o:p:r:")
except getopt.GetoptError:
print "Usage: plot_result -f <func_name> -o <output_file> -p <plot> -r <range>"
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
print "Usage: plot_result -f <func_name> -o <output_file> -p <plot> -r <range>"
sys.exit()
elif opt in ('-f'):
func_name = arg
elif opt in ('-o'):
output_file = arg
elif opt in ('-p'):
plot = arg
elif opt in ('-r'):
r = int(arg)
(num_pars, res) = test_func(func_name, r)
if plot:
plt.loglog(num_pars, res, basex=2, basey=2)
plt.show()
if output_file != '':
target = open(output_file, 'w')
target.write("Tested func: " + func_name + "\n")
target.write(str(num_pars) + "\n")
target.write(str(res))
if func_name == 'openmp':
# Plot speedup vs num_threads for openmp
p = re.compile('(\d+.\d+)')
serial = os.popen('./serial -n 10000 -no').read()
serial_time = float(p.findall(serial)[1])
speedup = []
for i in xrange(1, 2, 9):
tmp = os.popen('./openmp -n 10000 -t ' + str(i) + ' -no').read()
print tmp
speedup.append(serial_time / float(p.findall(tmp)[1]))
plt.bar(xrange(1, 2, 9), speedup, 0.35)
plt.show()
if __name__ == "__main__":
main(sys.argv[1:])