Peano
Loading...
Searching...
No Matches
kernel-benchmarks-fv-rusanov.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 Rusanov 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, 512, 1024, 2048],
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)
79
80args = parser.parse_args()
81
82fv_rusanov_solver = exahype2.solvers.fv.rusanov.GlobalAdaptiveTimeStepWithEnclaveTasking(
83 name="FVRusanov",
84 patch_size=args.patch_size,
85 unknowns={"h": 1, "hu": 1, "hv": 1},
86 auxiliary_variables={"b": 1},
87 min_volume_h=0.001, # max_cell_size -> arbitrary value
88 max_volume_h=0.001, # min_cell_size -> arbitrary value
89 time_step_relaxation=0.5,
90 pde_terms_without_state=True,
91)
92
93fv_rusanov_solver.set_implementation(
94 initial_conditions="",
95 boundary_conditions=exahype2.solvers.PDETerms.Empty_Implementation,
96 refinement_criterion=exahype2.solvers.PDETerms.Empty_Implementation,
97 flux="applications::exahype2::swe::flux(Q, faceCentre, volumeH, t, dt, normal, F);",
98 ncp="applications::exahype2::swe::nonconservativeProduct(Q, deltaQ, faceCentre, volumeH, t, dt, normal, BTimesDeltaQ);",
99 eigenvalues="return applications::exahype2::swe::maxEigenvalue(Q, faceCentre, volumeH, t, dt, normal);",
100 source_term="",
101)
102fv_rusanov_solver.add_user_solver_includes(
103 """
104#include "../../../../applications/exahype2/shallow-water/SWE.h"
105"""
106)
107
108project = exahype2.Project(
109 namespace=["benchmarks", "exahype2", "kernelbenchmarks"],
110 project_name="KernelBenchmarksFVRusanov",
111 directory=".",
112 executable=f"KernelBenchmarksFVRusanov.{args.build_mode}",
113)
114project.add_solver(fv_rusanov_solver)
115
116project.set_global_simulation_parameters(
117 dimensions=2,
118 size=[1.0, 1.0],
119 offset=[0.0, 0.0],
120 min_end_time=0.1,
121 max_end_time=0.1,
122 first_plot_time_stamp=0.0,
123 time_in_between_plots=0.0,
124 periodic_BC=[False, False]
125)
126
127project.set_Peano4_installation("../../../../", mode=peano4.api.output.string_to_mode(args.build_mode))
128project = project.generate_Peano4_project(verbose=True)
129
130accuracy = args.accuracy
131if accuracy < 0:
132 import numpy
133 accuracy = default = numpy.finfo(float).eps
134project.constants.export_constexpr_with_type("Accuracy", str(accuracy), "double")
135
136project.constants.export_constexpr_with_type("NumberOfSamples", str(args.samples), "int")
137
138formatted_num_patches = "{{{}}}".format(", ".join(str(val) for val in args.num_patches))
139project.constants.export_const_with_type("NumberOfPatchesToStudy", str(formatted_num_patches), "tarch::la::Vector<%s, int>" % len(args.num_patches))
140
141project.constants.export_constexpr_with_type("NumberOfLaunchingThreads", str(args.num_threads), "int")
142
143if args.fpe:
144 project.constants.export_boolean("EnableFPE", True)
145else:
146 project.constants.export_boolean("EnableFPE", False)
147
148if args.cpu == False and args.gpu == False:
149 project.constants.export_boolean("AssessHostKernels", True)
150 project.constants.export_boolean("AssessDeviceKernels", True)
151else:
152 project.constants.export_boolean("AssessHostKernels", True if args.cpu else False)
153 project.constants.export_boolean("AssessDeviceKernels", True if args.gpu else False)
154
155project.constants.export_boolean("EvaluateFlux", True)
156project.constants.export_boolean("EvaluateNonconservativeProduct", True)
157project.constants.export_boolean("EvaluateSource", False)
158project.constants.export_boolean("EvaluateMaximumEigenvalueAfterTimeStep", True if args.eval_eig else False) # Reduction
159
160benchmark_main_file = "../../kernel-benchmarks/KernelBenchmarksFVRusanov-main.cpp"
161os.system("cp {} KernelBenchmarksFVRusanov-main.cpp".format(benchmark_main_file))
162
163project.output.makefile.add_CXX_flag("-DGRAV=9.81")
164project.build(make=True, make_clean_first=True, throw_away_data_after_build=True)
165
166print(project)
167print(fv_rusanov_solver)