1 | import os |
---|
2 | import sys |
---|
3 | import time |
---|
4 | import matplotlib.pyplot as plt |
---|
5 | import matplotlib.ticker as ticks |
---|
6 | import math |
---|
7 | from scipy import stats as st |
---|
8 | import numpy as np |
---|
9 | from enum import Enum |
---|
10 | from statistics import median |
---|
11 | |
---|
12 | readfile = open(sys.argv[1], "r") |
---|
13 | |
---|
14 | # first line has num times per experiment |
---|
15 | line = readfile.readline() |
---|
16 | numTimes = int(line) |
---|
17 | |
---|
18 | # second line has processor args |
---|
19 | line = readfile.readline() |
---|
20 | procs = [] |
---|
21 | for val in line.split(): |
---|
22 | procs.append(int(val)) |
---|
23 | |
---|
24 | # 3rd line has number of variants |
---|
25 | line = readfile.readline() |
---|
26 | names = line.split() |
---|
27 | numVariants = len(names) |
---|
28 | |
---|
29 | lines = (line.rstrip() for line in readfile) # All lines including the blank ones |
---|
30 | lines = (line for line in lines if line) # Non-blank lines |
---|
31 | |
---|
32 | class Bench(Enum): |
---|
33 | Unset = 0 |
---|
34 | Executor = 1 |
---|
35 | Matrix = 2 |
---|
36 | Repeat = 3 |
---|
37 | Balance_One = 4 |
---|
38 | Balance_Multi = 5 |
---|
39 | Static = 7 |
---|
40 | Dynamic = 8 |
---|
41 | |
---|
42 | nameSet = False |
---|
43 | currBench = Bench.Unset # default val |
---|
44 | count = 0 |
---|
45 | procCount = 0 |
---|
46 | currVariant = 0 |
---|
47 | name = "" |
---|
48 | var_name = "" |
---|
49 | data = [[0.0 for i in range(len(procs))] for j in range(numVariants)] |
---|
50 | bars = [[[0.0 for i in range(len(procs))],[0.0 for k in range(len(procs))]] for j in range(numVariants)] |
---|
51 | tempData = [0.0 for i in range(numTimes)] |
---|
52 | for idx, line in enumerate(lines): |
---|
53 | # print(line) |
---|
54 | |
---|
55 | if currBench == Bench.Unset: |
---|
56 | if line == "executor": |
---|
57 | name = "Executor" |
---|
58 | currBench = Bench.Executor |
---|
59 | elif line == "matrix": |
---|
60 | name = "Matrix" |
---|
61 | currBench = Bench.Matrix |
---|
62 | elif line == "repeat": |
---|
63 | name = "Repeat" |
---|
64 | currBench = Bench.Repeat |
---|
65 | elif line == "balance_one": |
---|
66 | name = "Balance_One" |
---|
67 | currBench = Bench.Balance_One |
---|
68 | elif line == "balance_multi": |
---|
69 | name = "Balance_Multi" |
---|
70 | currBench = Bench.Balance_Multi |
---|
71 | elif line == "static": |
---|
72 | name = "Static" |
---|
73 | currBench = Bench.Static |
---|
74 | elif line == "dynamic": |
---|
75 | name = "Dynamic" |
---|
76 | currBench = Bench.Dynamic |
---|
77 | else: |
---|
78 | print("Expected benchmark name") |
---|
79 | sys.exit() |
---|
80 | continue |
---|
81 | |
---|
82 | if line[0:4] == "proc": |
---|
83 | continue |
---|
84 | |
---|
85 | if currBench == Bench.Static or currBench == Bench.Dynamic: |
---|
86 | print("NOT YET IMPLEMENTED") |
---|
87 | sys.exit() |
---|
88 | else: |
---|
89 | if not nameSet: |
---|
90 | nameSet = True |
---|
91 | continue |
---|
92 | |
---|
93 | lineArr = line.split() |
---|
94 | tempData[count] = float(lineArr[-1]) |
---|
95 | count += 1 |
---|
96 | if count == numTimes: |
---|
97 | currMedian = median( tempData ) |
---|
98 | data[currVariant][procCount] = currMedian |
---|
99 | lower, upper = st.t.interval(0.95, numTimes - 1, loc=np.mean(tempData), scale=st.sem(tempData)) |
---|
100 | bars[currVariant][0][procCount] = currMedian - lower |
---|
101 | bars[currVariant][1][procCount] = upper - currMedian |
---|
102 | count = 0 |
---|
103 | procCount += 1 |
---|
104 | |
---|
105 | if procCount == len(procs): |
---|
106 | procCount = 0 |
---|
107 | nameSet = False |
---|
108 | currVariant += 1 |
---|
109 | |
---|
110 | if currVariant == numVariants: |
---|
111 | fig, ax = plt.subplots() |
---|
112 | plt.title(name + " Benchmark") |
---|
113 | plt.ylabel("Runtime (seconds)") |
---|
114 | plt.xlabel("Cores") |
---|
115 | for idx, arr in enumerate(data): |
---|
116 | plt.errorbar( procs, arr, [bars[idx][0], bars[idx][1]], capsize=2, marker='o' ) |
---|
117 | if currBench == Bench.Executor or currBench == Bench.Matrix or currBench == Bench.Balance_One or currBench == Bench.Repeat: |
---|
118 | plt.yscale("log") |
---|
119 | plt.ylim(1, None) |
---|
120 | ax.get_yaxis().set_major_formatter(ticks.ScalarFormatter()) |
---|
121 | else: |
---|
122 | plt.ylim(0, None) |
---|
123 | ax.legend(names) |
---|
124 | fig.savefig("plots/" + name + ".png") |
---|
125 | fig.clf() |
---|
126 | |
---|
127 | # reset |
---|
128 | currBench = Bench.Unset |
---|
129 | currVariant = 0 |
---|