Peano
Loading...
Searching...
No Matches
benchmarks.py
Go to the documentation of this file.
1import os, sys
2import argparse
3import peano4.api
4import mghype
5import numpy as np
6
7import toolbox.loadbalancing.api
8
9
10print( """
11
12Peano 4 multigrid solver using Discontinuous Galerkin
13
14""")
15
16parser = argparse.ArgumentParser(description='Multigrid - Poisson solver')
17parser.add_argument("-j", "--parallel-builds", dest="j", type=int, default=-1, help="Parallel builds" )
18parser.add_argument("-pd", "--peano-dir", dest="peanodir", default="../../..", help="Peano4 directory" )
19parser.add_argument("-v", "--verbose", dest="verbose", action="store_true", default=False, help="Verbose")
20parser.add_argument("-asserts", "--asserts", dest="asserts", action="store_true", default=False, help="Verbose")
21parser.add_argument("-ib", "--ill-balance", dest="ill_balance", action="store_true", default=False, help="Verbose")
22parser.add_argument("-d", "--dimensions", dest="dimensions", type=int, default=2, help="Dimensions")
23parser.add_argument("-p", "--poly_degree", dest="poly_degree", type=int, required=True, help="Polynomial Degree")
24parser.add_argument("-m", "--meshsize", dest="meshsize", required=True, help="Mesh size")
25parser.add_argument("-rea", "--realisation", dest="realisation", choices=["dg-sweeps", "dg-shifted-and-fused", "dg-tasks"], required=True, help="Pick variant" )
26parser.add_argument("-var", "--variant", dest="variant", choices=["rediscretise", "precompute"], required=True, help="Pick variant" )
27parser.add_argument("-o", "--output", dest="output", required=True, help="Name of executable")
28parser.add_argument("-t", "--max-trees", dest="max_trees", type=int, default=0, help="Number of trees")
29args = parser.parse_args()
30
31project = mghype.matrixfree.api.Project( project_name = "DGPointwise",
32 namespace = [ "benchmarks", "mghype", "poisson" ],
33 executable = args.output
34 )
35
37 args.dimensions,
38 args.poly_degree,
39 1, # Unknowns per cell dof. Scalar PDE here
40 2, # We use the penalty formulation (see docu in tutorials)
41 2,
42)
43
44assembly_matrix, assembly_matrix_scaling = matrices.get_cell_system_matrix_for_laplacian()
45mass_matrix, mass_matrix_scaling = matrices.get_cell_mass_matrix()
46face_from_cell_projection, \
47face_from_cell_projection_scaling = matrices.get_face_from_cell_matrix()
48cell_from_face_projection, \
49cell_from_face_projection_scaling = matrices.get_cell_from_face_matrix()
50approximate_system_matrix, \
51approximate_system_matrix_scaling = matrices.get_A_tilde()
52
53
54Solver_Type = None
55if args.realisation == "dg-sweeps":
56 Solver_Type = mghype.matrixfree.solvers.api.DiscontinuousGalerkinDiscretisationPointWiseRiemannSolver_Unshifted
57elif args.realisation == "dg-shifted-and-fused":
58 Solver_Type = mghype.matrixfree.solvers.api.DiscontinuousGalerkinDiscretisationPointWiseRiemannSolver
59elif args.realisation == "dg-tasks":
60 Solver_Type = mghype.matrixfree.solvers.api.DiscontinuousGalerkinDiscretisationPointWiseRiemannSolver_Tasks
61
62name = "DGPoisson"
63if args.variant == "rediscretise":
64 name = "DGPoissonRediscretise"
65if args.variant == "precompute":
66 name = "DGPoissonPrecompute"
67
68name = "DGPoisson"
69if args.variant == "rediscretise":
70 name = "DGPoissonRediscretise"
71if args.variant == "precompute":
72 name = "DGPoissonPrecompute"
73
74solver = Solver_Type(
75 name = name,
76 dimensions = args.dimensions,
77 poly_degree = args.poly_degree,
78 unknowns_per_cell_node = 1,
79 solutions_per_face_node = 2,
80 projections_per_face_node = 2,
81 min_h = args.meshsize,
82 max_h = args.meshsize,
83 assembly_matrix= assembly_matrix,
84 assembly_matrix_scaling = assembly_matrix_scaling,
85 mass_matrix = mass_matrix,
86 mass_matrix_scaling = mass_matrix_scaling,
87 face_from_cell_projection = face_from_cell_projection,
88 face_from_cell_projection_scaling = face_from_cell_projection_scaling,
89 cell_from_face_projection = cell_from_face_projection,
90 cell_from_face_projection_scaling = cell_from_face_projection_scaling,
91 riemann_matrix = matrices.get_face_face_riemann_problem_matrix(),
92 boundary_matrix = matrices.get_boundary_matrix(),
93 cell_relaxation = 0.5,
94 face_relaxation = 1.0,
95 approximate_system_matrix = approximate_system_matrix,
96 approximate_system_matrix_scaling = approximate_system_matrix_scaling,
97 solver_tolerance = 0.01,
98 integration_points = 0.5*(matrices.get_nodal_points_1d() + 1.0), # Should be specified in [0,1] interval
99 enable_plotting = False,
100)
101
102project.add_solver(solver)
103
104#t
105# Configure build
106#
107if args.asserts:
108 build_mode = peano4.api.output.CompileMode.ASSERTS
109else:
110 build_mode = peano4.api.output.CompileMode.RELEASE
111#build_mode = peano4.api.output.CompileMode.STATS
112#build_mode = peano4.api.output.CompileMode.ASSERTS
113
114
115cube_size = 1.0
116max_iterations = 10
117if args.realisation == "dg-sweeps":
118 max_iterations = max_iterations * 3
119project.set_global_simulation_parameters(
120 dimensions = args.dimensions,
121 offset = [ 0.0 for _ in range(args.dimensions) ],
122 domain_size = [ cube_size for _ in range(args.dimensions) ],
123 plot_after_each_mesh_sweep = False,
124 max_iterations = max_iterations
125)
126
127if args.max_trees>0:
128 max_trees = args.max_trees
129else:
130 max_trees = "::exahype2::LoadBalancingConfiguration::UseNumberOfThreads"
131
132project.set_multicore_orchestration( """new ::tarch::multicore::orchestration::Hardcoded(
133// 4,128, viel schlechter
134// 8,256,
135 32,256,
136 tarch::multicore::Task::Host,
137 ::tarch::multicore::orchestration::Hardcoded::NoNestedParallelism,
138// ::tarch::multicore::orchestration::FusionImplementation::DisableFusionAndMapOntoNativeTask
139// ::tarch::multicore::orchestration::FusionImplementation::LazyEvaluation
140// ::tarch::multicore::orchestration::FusionImplementation::ProducerConsumerTaskSequence
141 ::tarch::multicore::orchestration::FusionImplementation::EagerConsumerTasks
142)""" )
143
144
145if args.ill_balance:
146 tree_levels = toolbox.loadbalancing.api.real_mesh_size_and_level(float(args.meshsize),1.0)[1]
147 split_iteration = toolbox.loadbalancing.api.compute_regular_mesh_construction_grid_construction_sweeps(tree_levels)
148 assert args.max_trees>0
149
150 dimensions=2
151 new_partitions = [ int(3**(dimensions*tree_levels)/2) ]
152
153 for i in range(0,args.max_trees-2):
154 new_partitions.append( int(new_partitions[-1] / 2) )
155
156 if new_partitions[-1]==0:
157 new_partitions = [ x+1 for x in new_partitions ]
158
159 target_ranks = [0 for x in new_partitions]
160
161 project.set_load_balancing(
162 "toolbox::loadbalancing::strategies::Hardcoded",
163 toolbox.loadbalancing.api.output.create_constructor_initialisation_string(split_iteration,
164 0,
165 new_partitions,
166 target_ranks)
167 )
168else:
169 project.set_load_balancing( "toolbox::loadbalancing::strategies::SpreadOutOnceGridStagnates", "new ::exahype2::LoadBalancingConfiguration(0.9, 0, false, {}, {})".format(max_trees, max_trees) )
170
171
172project.set_Peano4_installation( args.peanodir, build_mode )
173
174peano4_project = project.generate_Peano4_project(args.verbose)
175peano4_project.output.makefile.add_cpp_file( args.peanodir + "/tests/multigrid/matrixfree/poisson/Scenario.cpp" )
176peano4_project.generate()
177
178os.system( "make clean" )
179if args.j>0:
180 os.system( "make -j{}".format(args.j) )
181else:
182 os.system( "make -j$(nproc --all)" )
183