Peano
Loading...
Searching...
No Matches
kernel-benchmarks-fv-muscl-hancock-dsl.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 os
4import argparse
5
6import peano4.api
7import exahype2
8
9parser = argparse.ArgumentParser(
10 description="ExaHyPE 2 - Shallow Water Finite Volume MUSCL-Hancock Kernel Benchmarking Script"
11)
12parser.add_argument(
13 "-m",
14 "--build-mode",
15 choices=peano4.api.output.CompileModes,
16 default=peano4.api.output.CompileModes[0], # Release
17 help="|".join(peano4.api.output.CompileModes),
18)
19parser.add_argument(
20 "-t",
21 "--num-threads",
22 default=1,
23 type=int,
24 help="Number of launching threads",
25)
26parser.add_argument(
27 "-ps",
28 "--patch-size",
29 default=16,
30 type=int,
31 help="Number of finite volumes per axis (dimension) per patch.",
32)
33parser.add_argument(
34 "-p",
35 "--num-patches",
36 nargs="+",
37 default=[32, 64, 128, 256],
38 type=int,
39 help="Number of patches to study",
40)
41parser.add_argument(
42 "-samples",
43 "--samples",
44 default=10,
45 type=int,
46 help="Number of samples per measurement",
47)
48parser.add_argument(
49 "-a",
50 "--accuracy",
51 default=0.0,
52 type=float,
53 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).",
54)
55parser.add_argument(
56 "-e",
57 "--eval-eig",
58 action="store_true",
59 help="Evaluate max. eigenvalue",
60)
61parser.add_argument(
62 "-cpu",
63 "--cpu",
64 action="store_true",
65 help="Assess host kernels",
66)
67parser.add_argument(
68 "-gpu",
69 "--gpu",
70 action="store_true",
71 help="Assess device kernels",
72)
73parser.add_argument(
74 "-fpe",
75 "--fpe",
76 action="store_true",
77 help="Enable a floating-point exception handler.",
78)
79parser.add_argument(
80 "-d",
81 "--dimensions",
82 default=2,
83 choices = [2, 3],
84 type=int,
85 help="Number of dimensions to use: 2 or 3",
86)
87parser.add_argument(
88 "-j",
89 default=-1,
90 type=int,
91 help="Number of parallel builds to use",
92)
93
94args = parser.parse_args()
95
96fv_muscl_solver = exahype2.solvers.fv.musclhancock.GlobalAdaptiveTimeStep(
97 name="FVMUSCLHancock",
98 patch_size=args.patch_size,
99 unknowns={"rho": 1, "u": 1, "v": 1, "e": 1} if args.dimensions == 2 else {"rho": 1, "u": 1, "v": 1, "w": 1, "e": 1},
100 auxiliary_variables = {},
101 min_volume_h=0.001, # max_cell_size -> arbitrary value
102 max_volume_h=0.001, # min_cell_size -> arbitrary value
103 time_step_relaxation=0.5,
104 pde_terms_without_state=True,
105)
106
107fv_muscl_solver.set_implementation(
108 initial_conditions="",
109 boundary_conditions=exahype2.solvers.PDETerms.Empty_Implementation,
110 refinement_criterion=exahype2.solvers.PDETerms.Empty_Implementation,
111 flux="applications::exahype2::euler::flux(Q, faceCentre, volumeH, t, dt, normal, F);",
112 ncp="",
113 eigenvalues="applications::exahype2::euler::maxEigenvalue(Q, faceCentre, volumeH, t, dt, normal, maxEigenvalue);",
114 source_term="",
115)
116fv_muscl_solver.add_user_solver_includes(
117 """
118 #include "../../../../applications/exahype2/euler/Euler.h"
119 """
120)
121
122project = exahype2.Project(
123 namespace=["benchmarks", "exahype2", "kernelbenchmarks"],
124 project_name="KernelBenchmarksFVMUSCLHancockDSL",
125 directory=".",
126 executable=f"KernelBenchmarksFVMUSCLHancockDSL.{args.build_mode}",
127)
128project.add_solver(fv_muscl_solver)
129
130project.set_global_simulation_parameters(
131 dimensions=args.dimensions,
132 size=[1.0] * args.dimensions,
133 offset=[0.0] * args.dimensions,
134 min_end_time=0.1,
135 max_end_time=0.1,
136 first_plot_time_stamp=0.0,
137 time_in_between_plots=0.0,
138 periodic_BC=[False] * args.dimensions
139)
140
141project.set_Peano4_installation("../../../../", mode=peano4.api.output.string_to_mode(args.build_mode))
142project = project.generate_Peano4_project(verbose=True)
143
144accuracy = args.accuracy
145if accuracy < 0:
146 import numpy
147 accuracy = default = numpy.finfo(float).eps
148project.constants.export_constexpr_with_type("Accuracy", str(accuracy), "double")
149
150project.constants.export_constexpr_with_type("NumberOfSamples", str(args.samples), "int")
151
152formatted_num_patches = "{{{}}}".format(", ".join(str(val) for val in args.num_patches))
153project.constants.export_const_with_type("NumberOfPatchesToStudy", str(formatted_num_patches), "tarch::la::Vector<%s, int>" % len(args.num_patches))
154
155project.constants.export_constexpr_with_type("NumberOfLaunchingThreads", str(args.num_threads), "int")
156
157if args.fpe:
158 project.constants.export_boolean("EnableFPE", True)
159else:
160 project.constants.export_boolean("EnableFPE", False)
161
162if args.cpu == False and args.gpu == False:
163 project.constants.export_boolean("AssessHostKernels", True)
164 project.constants.export_boolean("AssessDeviceKernels", True)
165else:
166 project.constants.export_boolean("AssessHostKernels", True if args.cpu else False)
167 project.constants.export_boolean("AssessDeviceKernels", True if args.gpu else False)
168
169project.constants.export_boolean("EvaluateFlux", True)
170project.constants.export_boolean("EvaluateNonconservativeProduct", True)
171project.constants.export_boolean("EvaluateSource", False)
172project.constants.export_boolean("EvaluateMaximumEigenvalueAfterTimeStep", True if args.eval_eig else False) # Reduction
173
174project.constants.define_value("GAMMA", str(1.0))
175
176benchmark_main_file = "../../kernel-benchmarks/KernelBenchmarksFVMUSCLHancockDSL-main.cpp"
177os.system("cp {} KernelBenchmarksFVMUSCLHancockDSL-main.cpp".format(benchmark_main_file))
178
179project.output.makefile.add_CXX_flag("-DGRAV=9.81")
180
181project.build(make=True, make_clean_first=True, throw_away_data_after_build=True)
182
183print(project)
184print(fv_muscl_solver)