[ab81e3b] | 1 | import os |
---|
| 2 | import sys |
---|
| 3 | import time |
---|
[4912520] | 4 | import itertools |
---|
[ab81e3b] | 5 | import matplotlib.pyplot as plt |
---|
| 6 | import matplotlib.ticker as ticks |
---|
| 7 | import math |
---|
| 8 | from scipy import stats as st |
---|
| 9 | import numpy as np |
---|
| 10 | from enum import Enum |
---|
| 11 | from statistics import median |
---|
| 12 | |
---|
[625f3e2] | 13 | import matplotlib |
---|
| 14 | matplotlib.use("pgf") |
---|
| 15 | matplotlib.rcParams.update({ |
---|
| 16 | "pgf.texsystem": "pdflatex", |
---|
| 17 | 'font.family': 'serif', |
---|
| 18 | 'text.usetex': True, |
---|
| 19 | 'pgf.rcfonts': False, |
---|
[4912520] | 20 | 'font.size': 16 |
---|
[625f3e2] | 21 | }) |
---|
[4912520] | 22 | marker = itertools.cycle(('o', 's', 'D', 'x', 'p', '^', 'h', '*', 'v' )) |
---|
[625f3e2] | 23 | |
---|
[ab81e3b] | 24 | readfile = open(sys.argv[1], "r") |
---|
| 25 | |
---|
[625f3e2] | 26 | machineName = "" |
---|
| 27 | |
---|
| 28 | if len(sys.argv) > 2: |
---|
| 29 | machineName = sys.argv[2] |
---|
| 30 | |
---|
[ab81e3b] | 31 | # first line has num times per experiment |
---|
| 32 | line = readfile.readline() |
---|
| 33 | numTimes = int(line) |
---|
| 34 | |
---|
| 35 | # second line has processor args |
---|
| 36 | line = readfile.readline() |
---|
| 37 | procs = [] |
---|
| 38 | for val in line.split(): |
---|
| 39 | procs.append(int(val)) |
---|
| 40 | |
---|
| 41 | # 3rd line has number of variants |
---|
| 42 | line = readfile.readline() |
---|
| 43 | names = line.split() |
---|
| 44 | numVariants = len(names) |
---|
| 45 | |
---|
| 46 | lines = (line.rstrip() for line in readfile) # All lines including the blank ones |
---|
| 47 | lines = (line for line in lines if line) # Non-blank lines |
---|
| 48 | |
---|
| 49 | class 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 |
---|
[c74372f] | 58 | Mem = 9 |
---|
[ab81e3b] | 59 | |
---|
| 60 | nameSet = False |
---|
| 61 | currBench = Bench.Unset # default val |
---|
| 62 | count = 0 |
---|
| 63 | procCount = 0 |
---|
| 64 | currVariant = 0 |
---|
| 65 | name = "" |
---|
| 66 | var_name = "" |
---|
[625f3e2] | 67 | sendData = [0.0 for j in range(numVariants)] |
---|
[ab81e3b] | 68 | data = [[0.0 for i in range(len(procs))] for j in range(numVariants)] |
---|
| 69 | bars = [[[0.0 for i in range(len(procs))],[0.0 for k in range(len(procs))]] for j in range(numVariants)] |
---|
| 70 | tempData = [0.0 for i in range(numTimes)] |
---|
| 71 | for 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": |
---|
[625f3e2] | 85 | name = "Balance-One" |
---|
[ab81e3b] | 86 | currBench = Bench.Balance_One |
---|
| 87 | elif line == "balance_multi": |
---|
[625f3e2] | 88 | name = "Balance-Multi" |
---|
[ab81e3b] | 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 |
---|
[c74372f] | 96 | elif line == "mem": |
---|
| 97 | name = "ExecutorMemory" |
---|
| 98 | currBench = Bench.Mem |
---|
[ab81e3b] | 99 | else: |
---|
| 100 | print("Expected benchmark name") |
---|
| 101 | sys.exit() |
---|
| 102 | continue |
---|
| 103 | |
---|
| 104 | if line[0:4] == "proc": |
---|
| 105 | continue |
---|
| 106 | |
---|
[c74372f] | 107 | if currBench == Bench.Static or currBench == Bench.Dynamic or currBench == Bench.Mem: |
---|
[625f3e2] | 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" |
---|
[c74372f] | 125 | elif currBench == Bench.Dynamic: |
---|
[625f3e2] | 126 | fileName += "SendDynamic" |
---|
[c74372f] | 127 | else: |
---|
| 128 | fileName += "ExecutorMem" |
---|
[625f3e2] | 129 | f = open(fileName, 'w') |
---|
[c74372f] | 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))) |
---|
[625f3e2] | 134 | |
---|
| 135 | # reset |
---|
| 136 | currBench = Bench.Unset |
---|
| 137 | currVariant = 0 |
---|
| 138 | |
---|
[ab81e3b] | 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: |
---|
[5eb9327] | 162 | fig, ax = plt.subplots(layout='constrained') |
---|
[ab81e3b] | 163 | plt.title(name + " Benchmark") |
---|
| 164 | plt.ylabel("Runtime (seconds)") |
---|
| 165 | plt.xlabel("Cores") |
---|
| 166 | for idx, arr in enumerate(data): |
---|
[4912520] | 167 | plt.errorbar( procs, arr, [bars[idx][0], bars[idx][1]], capsize=2, marker=next(marker) ) |
---|
[ab81e3b] | 168 | if currBench == Bench.Executor or currBench == Bench.Matrix or currBench == Bench.Balance_One or currBench == Bench.Repeat: |
---|
| 169 | plt.yscale("log") |
---|
| 170 | plt.ylim(1, None) |
---|
| 171 | ax.get_yaxis().set_major_formatter(ticks.ScalarFormatter()) |
---|
| 172 | else: |
---|
| 173 | plt.ylim(0, None) |
---|
[5217569] | 174 | plt.xticks(procs) |
---|
[ab81e3b] | 175 | ax.legend(names) |
---|
[c74372f] | 176 | # fig.savefig("plots/" + machineName + name + ".png") |
---|
[625f3e2] | 177 | plt.savefig("plots/" + machineName + name + ".pgf") |
---|
[ab81e3b] | 178 | fig.clf() |
---|
| 179 | |
---|
| 180 | # reset |
---|
| 181 | currBench = Bench.Unset |
---|
| 182 | currVariant = 0 |
---|