Peano
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
3 import sys, os, argparse
4 import peano4, exahype2
5 
6 sys.path.insert(0, os.path.abspath("../../../../tests/exahype2/aderdg"))
7 import scenarios
8 
9 available_scenarios = {
10  "AcousticPlanarWaves": scenarios.AcousticPlanarWaves(dimensions=2),
11  "AdvectionLinear": scenarios.AdvectionLinear(),
12  "ElasticPlanarWaves": scenarios.ElasticPlanarWaves(dimensions=2),
13  "EulerGaussianBell": scenarios.EulerGaussianBell(),
14  "EulerIsotropicVortex": scenarios.EulerIsotropicVortex(),
15  "SWERadialDamBreak": scenarios.SWERadialDamBreak(),
16  "SWERestingLake": scenarios.SWERestingLake(),
17 }
18 
19 parser = argparse.ArgumentParser(
20  description="ExaHyPE 2 - ADER-DG Kernel Benchmarking Script"
21 )
22 parser.add_argument(
23  "-m", "--build-mode",
24  choices=peano4.output.CompileModes,
25  default=peano4.output.CompileModes[0], # Release
26  help="|".join(peano4.output.CompileModes),
27 )
28 parser.add_argument(
29  "-t", "--num-threads",
30  type=int,
31  default=1,
32  help="Number of launching threads",
33 )
34 parser.add_argument(
35  "-o", "--order",
36  type=int,
37  default=5,
38  help="Order of the underlying ADER-DG solver.",
39 )
40 parser.add_argument(
41  "-c", "--num-cells",
42  type=int, nargs="+",
43  default=[32, 64, 128, 256, 512, 1024, 2048],
44  help="Number of patches to study",
45 )
46 parser.add_argument(
47  "-samples", "--samples",
48  type=int,
49  default=10,
50  help="Number of samples per measurement",
51 )
52 parser.add_argument(
53  "-a", "--accuracy",
54  type=float,
55  default=0.0,
56  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).",
57 )
58 parser.add_argument(
59  "-cpu", "--cpu",
60  action="store_true",
61  help="Assess host kernels",
62 )
63 parser.add_argument(
64  "-gpu", "--gpu",
65  action="store_true",
66  help="Assess device kernels",
67 )
68 parser.add_argument(
69  "-fpe", "--fpe",
70  action="store_true",
71  help="Enable a floating-point exception handler.",
72 )
73 parser.add_argument(
74  "-pr", "--precision",
75  choices=["double", "float", "fp16", "bf16"],
76  default="double",
77  help="Precision in which the solver should be computed.",
78 )
79 parser.add_argument(
80  "-s", "--scenario",
81  choices=available_scenarios.keys(),
82  default="ElasticPlanarWaves",
83  help="Scenario which should be used as a base for the benchmarking",
84 )
85 
86 args = parser.parse_args()
87 
88 scenario = available_scenarios[args.scenario]
89 
90 ader_solver = exahype2.solvers.aderdg.GlobalAdaptiveTimeStep(
91  name="AderSolver",
92  order=args.order,
93  unknowns=scenario._equation.num_unknowns,
94  auxiliary_variables=scenario._equation.num_auxiliary_variables,
95  min_cell_h=0.001, # max_cell_size -> arbitrary value
96  max_cell_h=0.001, # min_cell_size -> arbitrary value
97  time_step_relaxation=0.5
98 )
99 
100 ader_solver.add_kernel_optimisations(
101  polynomials=exahype2.solvers.aderdg.Polynomials.Gauss_Legendre,
102  is_linear=scenario._equation.is_linear,
103  precision = args.precision
104 )
105 
106 ader_solver.set_implementation(
107  initial_conditions=scenario.initial_conditions(),
108  boundary_conditions=scenario.boundary_conditions(),
109  max_eigenvalue=scenario._equation.eigenvalues(),
110  flux=scenario._equation.flux(),
111  ncp=scenario._equation.ncp(),
112  riemann_solver=scenario._equation.riemann_solver(),
113 )
114 
115 project = exahype2.Project(
116  namespace=["benchmarks", "exahype2", "kernelbenchmarks"],
117  project_name="KernelBenchmarks",
118  directory=".",
119  executable="KernelBenchmarks",
120 )
121 project.add_solver(ader_solver)
122 
123 project.set_global_simulation_parameters(
124  dimensions=2,
125  size=[1.0, 1.0],
126  offset=[0.0, 0.0],
127  min_end_time=0.1,
128  max_end_time=0.1,
129  first_plot_time_stamp=0.0,
130  time_in_between_plots=0.0,
131  periodic_BC=[False, False]
132 )
133 
134 project.set_Peano4_installation("../../../../", mode=peano4.output.string_to_mode(args.build_mode))
135 project = project.generate_Peano4_project(verbose=False)
136 
137 accuracy = args.accuracy
138 if accuracy < 0:
139  import numpy
140  accuracy = default = numpy.finfo(float).eps
141 project.constants.export_constexpr_with_type("Accuracy", str(accuracy), "double")
142 
143 project.constants.export_constexpr_with_type("NumberOfSamples", str(args.samples), "int")
144 
145 formatted_num_cells = "{{{}}}".format(", ".join(str(val) for val in args.num_cells))
146 project.constants.export_const_with_type("NumberOfCellsToStudy", str(formatted_num_cells), "tarch::la::Vector<%s, int>" % len(args.num_cells))
147 
148 project.constants.export_constexpr_with_type("NumberOfLaunchingThreads", str(args.num_threads), "int")
149 
150 if args.fpe:
151  project.constants.export_boolean("EnableFPE", True)
152 else:
153  project.constants.export_boolean("EnableFPE", False)
154 
155 if args.cpu == False and args.gpu == False:
156  project.constants.export_boolean("AssessHostKernels", True)
157  project.constants.export_boolean("AssessDeviceKernels", True)
158 else:
159  project.constants.export_boolean("AssessHostKernels", True if args.cpu else False)
160  project.constants.export_boolean("AssessDeviceKernels", True if args.gpu else False)
161 
162 project.output.makefile.add_cpp_file("KernelBenchmarks-main.cpp")
163 project.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.
str
Definition: ccz4.py:55