source: doc/theses/colby_parsons_MMAth/benchmarks/channels/plotData.py @ 8599415

ast-experimental
Last change on this file since 8599415 was 4912520, checked in by caparsons <caparson@…>, 14 months ago

updated plotting scripts with new plot style

  • Property mode set to 100644
File size: 4.1 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    Contend = 1
52    Zero = 2
53    Barrier = 3
54    Churn = 4
55    Daisy_Chain = 5
56    Hot_Potato = 6
57    Pub_Sub = 7
58
59nameSet = False
60currBench = Bench.Unset # default val
61count = 0
62procCount = 0
63currVariant = 0
64name = ""
65var_name = ""
66sendData = [0.0 for j in range(numVariants)]
67data = [[0.0 for i in range(len(procs))] for j in range(numVariants)]
68bars = [[[0.0 for i in range(len(procs))],[0.0 for k in range(len(procs))]] for j in range(numVariants)]
69tempData = [0.0 for i in range(numTimes)]
70for idx, line in enumerate(lines):
71    # print(line)
72   
73    if currBench == Bench.Unset:
74        if line == "contend:":
75            name = "Channel Contention"
76            currBench = Bench.Contend
77        elif line == "zero:":
78            name = "Zero"
79            currBench = Bench.Zero
80        elif line == "barrier:":
81            name = "Barrier"
82            currBench = Bench.Barrier
83        elif line == "churn:":
84            name = "Churn"
85            currBench = Bench.Churn
86        elif line == "daisy_chain:":
87            name = "Daisy_Chain"
88            currBench = Bench.Daisy_Chain
89        elif line == "hot_potato:":
90            name = "Hot_Potato"
91            currBench = Bench.Hot_Potato
92        elif line == "pub_sub:":
93            name = "Pub_Sub"
94            currBench = Bench.Pub_Sub
95        else:
96            print("Expected benchmark name")
97            print("Line: " + line)
98            sys.exit()
99        continue
100
101    if line[0:5] == "cores":
102        continue
103
104    if not nameSet:
105        nameSet = True
106        continue
107   
108    lineArr = line.split()
109    tempData[count] = float(lineArr[-1])
110    count += 1
111    if count == numTimes:
112        currMedian = median( tempData )
113        data[currVariant][procCount] = currMedian
114        lower, upper = st.t.interval(0.95, numTimes - 1, loc=np.mean(tempData), scale=st.sem(tempData))
115        bars[currVariant][0][procCount] = currMedian - lower
116        bars[currVariant][1][procCount] = upper - currMedian
117        count = 0
118        procCount += 1
119
120        if procCount == len(procs):
121            procCount = 0
122            nameSet = False
123            currVariant += 1
124
125            if currVariant == numVariants:
126                fig, ax = plt.subplots()
127                plt.title(name + " Benchmark")
128                plt.ylabel("Throughput (channel operations)")
129                plt.xlabel("Cores")
130                for idx, arr in enumerate(data):
131                    plt.errorbar( procs, arr, [bars[idx][0], bars[idx][1]], capsize=2, marker=next(marker) )
132               
133                plt.yscale("log")
134                # plt.ylim(1, None)
135                # ax.get_yaxis().set_major_formatter(ticks.ScalarFormatter())
136                # else:
137                #     plt.ylim(0, None)
138                plt.xticks(procs)
139                ax.legend(names)
140                # fig.savefig("plots/" + machineName + name + ".png")
141                plt.savefig("plots/" + machineName + name + ".pgf")
142                fig.clf()
143
144                # reset
145                currBench = Bench.Unset
146                currVariant = 0
Note: See TracBrowser for help on using the repository browser.