source: doc/theses/colby_parsons_MMAth/benchmarks/actors/plotData.py@ d2e6f84

Last change on this file since d2e6f84 was a3c7bac, checked in by caparsons <caparson@…>, 2 years ago

reworked part of actor perf section

  • Property mode set to 100644
File size: 5.8 KB
Line 
1import os
2import sys
3import time
4import itertools
5import matplotlib.pyplot as plt
6import matplotlib.ticker as ticks
7import math
8from scipy import stats as st
9import numpy as np
10from enum import Enum
11from statistics import median
12
13import matplotlib
14matplotlib.use("pgf")
15matplotlib.rcParams.update({
16 "pgf.texsystem": "pdflatex",
17 'font.family': 'serif',
18 'text.usetex': True,
19 'pgf.rcfonts': False,
20 'font.size': 16
21})
22marker = itertools.cycle(('o', 's', 'D', 'x', 'p', '^', 'h', '*', 'v' ))
23
24readfile = open(sys.argv[1], "r")
25
26machineName = ""
27
28if len(sys.argv) > 2:
29 machineName = sys.argv[2]
30
31# first line has num times per experiment
32line = readfile.readline()
33numTimes = int(line)
34
35# second line has processor args
36line = readfile.readline()
37procs = []
38for val in line.split():
39 procs.append(int(val))
40
41# 3rd line has number of variants
42line = readfile.readline()
43names = line.split()
44numVariants = len(names)
45
46lines = (line.rstrip() for line in readfile) # All lines including the blank ones
47lines = (line for line in lines if line) # Non-blank lines
48
49class Bench(Enum):
50 Unset = 0
51 Executor = 1
52 Matrix = 2
53 Repeat = 3
54 Balance_One = 4
55 Balance_Multi = 5
56 Static = 7
57 Dynamic = 8
58 Mem = 9
59
60nameSet = False
61currBench = Bench.Unset # default val
62count = 0
63procCount = 0
64currVariant = 0
65name = ""
66var_name = ""
67sendData = [0.0 for j in range(numVariants)]
68data = [[0.0 for i in range(len(procs))] for j in range(numVariants)]
69bars = [[[0.0 for i in range(len(procs))],[0.0 for k in range(len(procs))]] for j in range(numVariants)]
70tempData = [0.0 for i in range(numTimes)]
71for idx, line in enumerate(lines):
72 # print(line)
73
74 if currBench == Bench.Unset:
75 if line == "executor":
76 name = "Executor"
77 currBench = Bench.Executor
78 elif line == "matrix":
79 name = "Matrix"
80 currBench = Bench.Matrix
81 elif line == "repeat":
82 name = "Repeat"
83 currBench = Bench.Repeat
84 elif line == "balance_one":
85 name = "Balance-One"
86 currBench = Bench.Balance_One
87 elif line == "balance_multi":
88 name = "Balance-Multi"
89 currBench = Bench.Balance_Multi
90 elif line == "static":
91 name = "Static"
92 currBench = Bench.Static
93 elif line == "dynamic":
94 name = "Dynamic"
95 currBench = Bench.Dynamic
96 elif line == "mem":
97 name = "ExecutorMemory"
98 currBench = Bench.Mem
99 else:
100 print("Expected benchmark name")
101 sys.exit()
102 continue
103
104 if line[0:4] == "proc":
105 continue
106
107 if currBench == Bench.Static or currBench == Bench.Dynamic or currBench == Bench.Mem:
108 if not nameSet:
109 nameSet = True
110 continue
111 lineArr = line.split()
112 tempData[count] = float(lineArr[-1])
113 count += 1
114 if count == numTimes:
115 currMedian = median( tempData )
116 sendData[currVariant] = currMedian
117 count = 0
118 nameSet = False
119 currVariant += 1
120
121 if currVariant == numVariants:
122 fileName = "data/" + machineName
123 if currBench == Bench.Static:
124 fileName += "SendStatic"
125 elif currBench == Bench.Dynamic:
126 fileName += "SendDynamic"
127 else:
128 fileName += "ExecutorMem"
129 f = open(fileName, 'w')
130 if currBench == Bench.Mem:
131 f.write(" & ".join(map(lambda a: str(int(a/1000)) + 'MB', sendData)))
132 else:
133 f.write(" & ".join(map(lambda a: str(int(a)) + 'ns', sendData)))
134
135 # reset
136 currBench = Bench.Unset
137 currVariant = 0
138
139 else:
140 if not nameSet:
141 nameSet = True
142 continue
143
144 lineArr = line.split()
145 tempData[count] = float(lineArr[-1])
146 count += 1
147 if count == numTimes:
148 currMedian = median( tempData )
149 data[currVariant][procCount] = currMedian
150 lower, upper = st.t.interval(0.95, numTimes - 1, loc=np.mean(tempData), scale=st.sem(tempData))
151 bars[currVariant][0][procCount] = currMedian - lower
152 bars[currVariant][1][procCount] = upper - currMedian
153 count = 0
154 procCount += 1
155
156 if procCount == len(procs):
157 procCount = 0
158 nameSet = False
159 currVariant += 1
160
161 if currVariant == numVariants:
162 fig, ax = plt.subplots(layout='constrained')
163 plt.title(name + " Benchmark")
164 plt.ylabel("Runtime (seconds)")
165 plt.xlabel("Cores")
166 for idx, arr in enumerate(data):
167 plt.errorbar( procs, arr, [bars[idx][0], bars[idx][1]], capsize=2, marker=next(marker) )
168 marker = itertools.cycle(('o', 's', 'D', 'x', 'p', '^', 'h', '*', 'v' ))
169 if currBench == Bench.Executor or currBench == Bench.Matrix or currBench == Bench.Balance_One:
170 plt.yscale("log")
171 plt.ylim(1, None)
172 ax.get_yaxis().set_major_formatter(ticks.ScalarFormatter())
173 elif currBench == Bench.Repeat:
174 plt.ylim(1, 100)
175 else:
176 plt.ylim(0, None)
177 plt.xticks(procs)
178 ax.legend(names)
179 # fig.savefig("plots/" + machineName + name + ".png")
180 plt.savefig("plots/" + machineName + name + ".pgf")
181 fig.clf()
182
183 # reset
184 currBench = Bench.Unset
185 currVariant = 0
Note: See TracBrowser for help on using the repository browser.