Peano
Loading...
Searching...
No Matches
aderdg.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 sys, os, argparse
4import peano4, exahype2
5
6sys.path.insert(0, os.path.abspath("../../../tests/aderdg"))
7import scenarios
8
9available_scenarios = {
10 "AcousticPlanarWaves": scenarios.AcousticPlanarWaves(dimensions=2),
11 "AdvectionLinear": scenarios.AdvectionLinear(),
12 "ElasticPlanarWaves": scenarios.ElasticPlanarWaves(dimensions=2),
13 "EulerGaussianBell": scenarios.EulerGaussianBell(),
14 "EulerIsentropicVortex": scenarios.EulerIsentropicVortex(),
15 "SWERadialDamBreak": scenarios.SWERadialDamBreak(),
16 "SWERestingLake": scenarios.SWERestingLake(),
17}
18
19parser = argparse.ArgumentParser(
20 description="ExaHyPE 2 - ADER-DG Kernel Benchmarking Script"
21)
22parser.add_argument(
23 "-m",
24 "--build-mode",
25 choices=peano4.output.CompileModes,
26 default=peano4.output.CompileModes[0], # Release
27 help="|".join(peano4.output.CompileModes),
28)
29parser.add_argument(
30 "-t",
31 "--num-threads",
32 type=int,
33 default=1,
34 help="Number of launching threads",
35)
36parser.add_argument(
37 "-o",
38 "--order",
39 type=int,
40 default=5,
41 help="Order of the underlying ADER-DG solver.",
42)
43parser.add_argument(
44 "-c",
45 "--num-cells",
46 type=int,
47 nargs="+",
48 default=[32, 64, 128, 256, 512, 1024, 2048],
49 help="Number of patches to study",
50)
51parser.add_argument(
52 "-samples",
53 "--samples",
54 type=int,
55 default=10,
56 help="Number of samples per measurement",
57)
58parser.add_argument(
59 "-a",
60 "--accuracy",
61 type=float,
62 default=0.0,
63 help="Floating point accuracy to which the different kernel variants have to match (absolute). Pass in 0 to disable correctness check. Pass in values < 0 to use machine epsilon (default).",
64)
65parser.add_argument(
66 "-cpu",
67 "--cpu",
68 action="store_true",
69 help="Assess host kernels",
70)
71parser.add_argument(
72 "-gpu",
73 "--gpu",
74 action="store_true",
75 help="Assess device kernels",
76)
77parser.add_argument(
78 "-pr", "--precision",
79 choices=["double", "float", "fp16", "bf16"],
80 default="double",
81 help="Precision in which the solver should be computed.",
82)
83parser.add_argument(
84 "-s",
85 "--scenario",
86 choices=available_scenarios.keys(),
87 default="ElasticPlanarWaves",
88 help="Scenario which should be used as a base for the benchmarking",
89)
90parser.add_argument(
91 "-md",
92 "--min-depth",
93 type=int,
94 default=6,
95 help="Determines maximum size of a single cell on each axis.",
96)
97
98args = parser.parse_args()
99
100scenario = available_scenarios[args.scenario]
101
102ader_solver = exahype2.solvers.aderdg.GlobalAdaptiveTimeStep(
103 name="AderSolver",
104 order=args.order,
105 unknowns=scenario._equation.num_unknowns,
106 auxiliary_variables=scenario._equation.num_auxiliary_variables,
107 min_cell_h=0.001, # max_cell_size -> arbitrary value
108 max_cell_h=0.001, # min_cell_size -> arbitrary value
109 time_step_relaxation=0.5,
110)
111
112ader_solver.add_kernel_optimisations(
113 polynomials=exahype2.solvers.aderdg.Polynomials.Gauss_Legendre,
114 is_linear=scenario._equation.is_linear,
115 precision=args.precision,
116)
117
118ader_solver.set_implementation(
119 initial_conditions=scenario.initial_conditions(),
120 boundary_conditions=scenario.boundary_conditions(),
121 max_eigenvalue=scenario._equation.eigenvalues(),
122 flux=scenario._equation.flux(),
123 ncp=scenario._equation.ncp(),
124 riemann_solver=scenario._equation.riemann_solver(),
125)
126
127project = exahype2.Project(
128 namespace=["benchmarks", "exahype2", "kernelbenchmarks"],
129 project_name="KernelBenchmarks",
130 directory=".",
131 executable="KernelBenchmarks",
132)
133project.add_solver(ader_solver)
134
135project.set_global_simulation_parameters(
136 dimensions=2,
137 size=[1.0, 1.0],
138 offset=[0.0, 0.0],
139 min_end_time=0.1,
140 max_end_time=0.1,
141 first_plot_time_stamp=0.0,
142 time_in_between_plots=0.0,
143 periodic_BC=[False, False],
144)
145
146project.set_build_mode(mode=peano4.output.string_to_mode(args.build_mode))
147project = project.generate_Peano4_project(verbose=False)
148
149accuracy = args.accuracy
150if accuracy < 0:
151 import numpy
152
153 accuracy = default = numpy.finfo(float).eps
154project.constants.export_constexpr_with_type("Accuracy", str(accuracy), "double")
155
156project.constants.export_constexpr_with_type(
157 "NumberOfSamples", str(args.samples), "int"
158)
159
160formatted_num_cells = "{{{}}}".format(", ".join(str(val) for val in args.num_cells))
161project.constants.export_const_with_type(
162 "NumberOfCellsToStudy",
163 str(formatted_num_cells),
164 "tarch::la::Vector<%s, int>" % len(args.num_cells),
165)
166
167project.constants.export_constexpr_with_type(
168 "NumberOfLaunchingThreads", str(args.num_threads), "int"
169)
170
171if args.cpu == False and args.gpu == False:
172 project.constants.export_boolean("AssessHostKernels", True)
173 project.constants.export_boolean("AssessDeviceKernels", True)
174else:
175 project.constants.export_boolean("AssessHostKernels", True if args.cpu else False)
176 project.constants.export_boolean("AssessDeviceKernels", True if args.gpu else False)
177
178project.output.makefile.add_cpp_file("KernelBenchmarks-main.cpp")
179project.build(make=True, make_clean_first=True, throw_away_data_after_build=True)
Scenario reproduced from Dumbser & Käser, https://doi.org/10.1111/j.1365-246X.2006....
Very simple scenario in which the initial value of x is shifted in each spatial dimension.
Scenario reproduced from Dumbser & Käser, https://doi.org/10.1111/j.1365-246X.2006....
Scenario reproduced from Ioratti, Dumbser & Loubère, https://doi.org/10.1007/s10915-020-01209-w (p.
Scenario reproduced from Ioratti, Dumbser & Loubère, https://doi.org/10.1007/s10915-020-01209-w (p.
Classic radial dam break SWE equations, with constant initial water height but a bump in the bathymet...
Resting lake scenario for the shallow water equations.