Peano
Loading...
Searching...
No Matches
plot-throughput-fv-riemann.py
Go to the documentation of this file.
1# This file is part of the ExaHyPE2 project. For conditions of distribution and
2# use, please see the copyright notice at www.peano-framework.org
3import argparse
4import numpy as np
5import matplotlib.pyplot as plt
6from matplotlib.ticker import ScalarFormatter, FuncFormatter
7from matplotlib.backends.backend_pgf import FigureCanvasPgf
8
9# Define the LaTeX preamble for the output file
10preamble = r"\usepackage{amsmath,amssymb}"
11
12# Set the rcParams dictionary to use the pgf backend and include the LaTeX preamble
13plt.rcParams.update(
14 {
15 "font.family": "sans-serif",
16 "pgf.texsystem": "pdflatex",
17 "pgf.preamble": preamble,
18 }
19)
20
21def main():
22 parser = argparse.ArgumentParser(
23 description="ExaHyPE 2 - Finite Volume Riemann Kernel Benchmark Throughput Plotting Script"
24 )
25 parser.add_argument(dest="file", help="File to parse")
26 args = parser.parse_args()
27 lines = parse_file(args)
28
29 print("Create throughput plot for {}".format(args.file))
30
31 kernel_labels = []
32 kernel_throughputs = []
33
34 for line in lines:
35 for device in ["host", "device"]:
36 if device in line:
37 label = device + line.split(device)[-1].split(":")[0]
38 throughput = 1.0 / float(line.split(device)[-1].split(":")[1].split("|")[1])
39 kernel_labels.append(label)
40 kernel_throughputs.append(throughput)
41 print("data found for {}".format(label))
42
43 plt.clf()
44 fig, ax = plt.subplots(figsize=(20, 6))
45
46 colors = plt.cm.viridis(np.linspace(0, 1, len(kernel_throughputs)))
47
48 bars = plt.bar(
49 kernel_labels,
50 kernel_throughputs,
51 color=colors,
52 edgecolor="black",
53 linewidth=1.2,
54 zorder=2,
55 )
56
57 for bar in bars:
58 bar.set_edgecolor('black')
59 bar.set_linewidth(1.2)
60 bar.set_alpha(0.9)
61 bar.set_hatch('//')
62
63 plt.grid(axis="y", linestyle="--", alpha=0.7, linewidth=0.7, zorder=1)
64
65 plt.ylabel("Volume updates per second", fontsize=15)
66
67 ax.set_facecolor('#d3d3d3')
68
69 ax.yaxis.set_major_formatter(ScalarFormatter(useMathText=True))
70 ax.ticklabel_format(axis="y", style="sci", scilimits=(0, 0))
71 ax.yaxis.get_offset_text().set_fontsize(15)
72
73 ax.tick_params(axis='both', which='major', labelsize=15)
74
75 ax.set_xticks(range(len(kernel_labels)))
76 ax.set_xticklabels(kernel_labels, fontsize=15)
77
78 plt.xticks(fontsize=15)
79 plt.yticks(fontsize=15)
80
81 plt.savefig(args.file + ".png", bbox_inches="tight", transparent=False)
82 plt.savefig(args.file + ".pdf", bbox_inches="tight", transparent=False)
83 fig = plt.gcf()
84 fig.patch.set_alpha(0)
85 canvas = FigureCanvasPgf(fig)
86 canvas.print_figure(args.file + ".pgf", bbox_inches="tight",)
87
88
89def parse_file(args):
90 # Initialize an empty list to store the lines
91 data_lines = []
92
93 with open(args.file, "r") as file:
94 current_line = ""
95 for line in file:
96 line = line.strip()
97 if line and line[:8].replace(":", "").isdigit():
98 # Start a new line with the timestamp
99 if current_line:
100 data_lines.append(current_line)
101 current_line = line
102 else:
103 # Append subsequent lines to the current line
104 current_line += " " + line
105 # Add the last line to the list
106 if current_line:
107 data_lines.append(current_line)
108
109 return data_lines
110
111if __name__ == "__main__":
112 main()