Peano
Loading...
Searching...
No Matches
plot-comparison-of-implementation-variants.py
Go to the documentation of this file.
2# You might have to add . to the PYTHONPATH
3#
4import matplotlib.pyplot as plt
5import argparse
6import tarfile
7import os
8
9from noh import (
10 Choices,
11 ParallelisationVariants,
12 Parallelisation_DomainDecomposition,
13 StorageVariants,
14 SortingVariants,
15 AllKernelOptimisationVariants,
16 Storage_Scattered,
17 BasicKernelOptimisationVariants,
18 KernelOptimisation_NoOptimisation,
19)
20
21Symbols = ["-o", "-s", "-v", "-^"]
22
23
25 choices,
26 tar,
27 plt,
28):
29 data_files = tar.getnames()
30 data_points = []
31 for choice in choices:
32 print("study choice/variant {}".format(choice))
33 for file in data_files:
34 if choice + ".out" in file:
35 print("read file {}".format(file))
36 time_stepping_cost = 0
37 tar.extract(file)
38 input_file = open(file, "r")
39 for line in input_file:
40 if "time stepping:" in line:
41 time_stepping_cost = float(
42 line.split("time stepping:")[1].split("s")[0]
43 )
44 print("cost is {}s".format(time_stepping_cost))
45 data_points.append(time_stepping_cost)
46 os.remove(file)
47
48 thread_count = archive_file.split("-threads")[0].split("-")[-1]
49 plt.plot(
50 data_points,
51 Symbols[args.file.index(archive_file)],
52 label=thread_count + " threads",
53 )
54
55
57 sub_choices,
58):
59 """!
60
61 You can pass in the subchoices directly, or you can simply pass in some
62 strings. The routine takes the points in the identifier and replaces them
63 with linebreaks.
64
65 """
66 return [x.replace(".", "\n") for x in sub_choices]
67
68
70 plt,
71 labels_on_x_axis,
72):
73 """!
74
75 Add the labels of the choices as x-ticks and rotate them by 90 degrees.
76 After that, we have to extend the whitespace underneath the plot, as the
77 labels otherwise don't fit in.
78
79 """
80 plt.xticks(
81 range(0, len(labels_on_x_axis)),
82 labels_on_x_axis,
83 rotation="vertical",
84 fontsize=6,
85 )
86 plt.ylabel("time [t]=s")
87 plt.legend()
88 plt.subplots_adjust(bottom=0.3)
89
90
91if __name__ == "__main__":
92 parser = argparse.ArgumentParser(
93 description="SPH comparison of different implementation variants"
94 )
95 parser.add_argument(
96 "file",
97 nargs="+",
98 help="Filename of the file to parse. You can specify multiple files.",
99 )
100 parser.add_argument(
101 "-o", "--output", dest="output", required=True, help="Output file"
102 )
103 args = parser.parse_args()
104
105 # ===========================
106 # All variants
107 # ===========================
108 sub_choices = Choices
109 plt.clf()
110 for archive_file in args.file:
111 print("Study file {}".format(archive_file))
113 sub_choices, tarfile.open(archive_file, "r:gz"), plt
114 )
116 plt,
117 construct_labels(sub_choices),
118 )
119 print("Write to file {}.pdf and {}.png".format(args.output, args.output))
120 plt.savefig(args.output + ".pdf")
121 plt.savefig(args.output + ".png")
122 plt.yscale("log")
123 plt.savefig(args.output + "-log.pdf")
124 plt.savefig(args.output + "-log.png")
125
126 # ===========================
127 # Only domain decomposition
128 # ===========================
129 sub_choices = [
130 parallelisation_variant
131 + "."
132 + storage
133 + "."
134 + sorting
135 + "."
136 + kernel_optimisation
137 for parallelisation_variant in [Parallelisation_DomainDecomposition]
138 for storage in [Storage_Scattered]
139 for sorting in SortingVariants
140 for kernel_optimisation in BasicKernelOptimisationVariants
141 ] + [
142 parallelisation_variant
143 + "."
144 + storage
145 + "."
146 + sorting
147 + "."
148 + kernel_optimisation
149 for parallelisation_variant in [Parallelisation_DomainDecomposition]
150 for storage in StorageVariants
151 for sorting in SortingVariants
152 for kernel_optimisation in AllKernelOptimisationVariants
153 ]
154 plt.clf()
155 for archive_file in args.file:
156 print("Study file {}".format(archive_file))
158 sub_choices, tarfile.open(archive_file, "r:gz"), plt
159 )
161 plt,
163 [
164 x.replace(Parallelisation_DomainDecomposition + ".", "")
165 for x in sub_choices
166 ]
167 ),
168 )
169 print("Write to file {}.pdf and {}.png".format(args.output, args.output))
170 plt.savefig(args.output + "-domain-decomposition.pdf")
171 plt.savefig(args.output + "-domain-decomposition.png")
172 plt.yscale("log")
173 plt.savefig(args.output + "-domain-decomposition-log.pdf")
174 plt.savefig(args.output + "-domain-decomposition-log.png")
175
176 # ===========================
177 # Without any optimisation
178 # ===========================
179 sub_choices = [
180 parallelisation_variant
181 + "."
182 + storage
183 + "."
184 + sorting
185 + "."
186 + kernel_optimisation
187 for parallelisation_variant in [Parallelisation_DomainDecomposition]
188 for storage in [Storage_Scattered] + StorageVariants
189 for sorting in SortingVariants
190 for kernel_optimisation in [KernelOptimisation_NoOptimisation]
191 ]
192 plt.clf()
193 for archive_file in args.file:
194 print("Study file {}".format(archive_file))
196 sub_choices, tarfile.open(archive_file, "r:gz"), plt
197 )
199 plt,
201 [
202 x.replace(Parallelisation_DomainDecomposition + ".", "")
203 for x in sub_choices
204 ]
205 ),
206 )
207 print("Write to file {}.pdf and {}.png".format(args.output, args.output))
208 plt.savefig(args.output + "-compare-only-storage.pdf")
209 plt.savefig(args.output + "-compare-only-storage.png")
210 plt.yscale("log")
211 plt.savefig(args.output + "-compare-only-storage-log.pdf")
212 plt.savefig(args.output + "-compare-only-storage-log.png")
add_legend_and_labels(plt, labels_on_x_axis)
Add the labels of the choices as x-ticks and rotate them by 90 degrees.
construct_labels(sub_choices)
You can pass in the subchoices directly, or you can simply pass in some strings.