Peano
Loading...
Searching...
No Matches
35_offline-load-balancing-quantised.py
Go to the documentation of this file.
1# This file is part of the Peano project. For conditions of distribution and
2# use, please see the copyright notice at www.peano-framework.org
3"""!
4
5Create the quantised-decomposition PNG of the tutorial 35_offline-load-balancing.ipynb
6
7The script computes two offline decompositions of the tutorial's regular
8mesh along Peano's space-filling curve, the equidistant one and the quantised
9one, keeps the cells along the periodic boundary on tree 0, and draws them next
10to each other. It does not build or run anything. Call it from anywhere:
11
12 python3 tutorials/exahype2/illustrations/35_offline-load-balancing-quantised.py
13
14The script needs matplotlib, but no ParaView.
15
16"""
17import importlib.util
18import os
19
20import numpy as np
21import matplotlib
22
23matplotlib.use("Agg")
24import matplotlib.pyplot as plt
25
26Here = os.path.dirname(os.path.abspath(__file__))
27
28# The file names of the scripts start with a digit, i.e. we cannot import them
29_specification = importlib.util.spec_from_file_location(
30 "plan_vs_run_illustrations",
31 os.path.join(Here, "35_offline-load-balancing-plan-vs-run.py"),
32)
33plan_vs_run = importlib.util.module_from_spec(_specification)
34_specification.loader.exec_module(plan_vs_run)
35
37import toolbox.loadbalancing.api.strategies.Decomposition as Decomposition
38import toolbox.loadbalancing.api.strategies.SplitTrees as SplitTrees
39
40QuantisedPicture = os.path.join(Here, "35_offline-load-balancing-quantised.png")
41NumberOfSubtrees = plan_vs_run.domain_decomposition.NumberOfThreads
42CellsPerAxis = plan_vs_run.CellsPerAxis
43
44
45def owner_of_cells(quantised):
46 """!
47 Owner of each fine grid cell after the offline decomposition
48
49 @param quantised: Bool
50 Quantised instead of equidistant chunk sizes
51 """
52 tree = RegularGridGenerator.RegularGridGenerator(max_level=3, dimensions=2)
53 if quantised:
55 peano_tree=tree, number_of_subtrees=NumberOfSubtrees, dimension=2
56 )
57 else:
59 peano_tree=tree, number_of_subtrees=NumberOfSubtrees
60 )
61 SplitTrees.split_tree(tree, decomposition=decomposition, periodic_BC=[True, True])
62 owner = np.zeros((CellsPerAxis, CellsPerAxis), dtype=int)
63 for x in range(CellsPerAxis):
64 for y in range(CellsPerAxis):
65 owner[y, x] = tree._tree_arrays[2][x][y][1]
66 return owner
67
68
69if __name__ == "__main__":
70 figure, axes = plt.subplots(1, 2, figsize=(9.0, 5.2))
71 plan_vs_run.draw(axes[0], owner_of_cells(False), "Equidistant decomposition")
72 plan_vs_run.draw(axes[1], owner_of_cells(True), "Quantised decomposition")
73 plt.tight_layout()
74 plt.savefig(QuantisedPicture, dpi=130, bbox_inches="tight")
75 print("wrote {}".format(QuantisedPicture))
owner_of_cells(quantised)
Owner of each fine grid cell after the offline decomposition.
quantised_splitting(Tree peano_tree, int number_of_subtrees, int dimension, verbose=False)
Quantised splitting.
equidistant_splitting(Tree peano_tree, int number_of_subtrees, verbose=False)
RegularGridGenerator(name=None, max_level=None, dimensions=None)
Generate an artificial regular grid with uniform refinement for testing purposes.
tuple[str, str] split_tree(Tree peano_tree, decomposition, str traversal="bfs_finest_first", bool enable_propagate_bottom_up=False, bool enable_optimize_hierarchy=False, bool require_all_children_for_hierarchy_optimization=True, list[bool]|None periodic_BC=None, bool verbose=False)
Split a tree using a staged load-balancing workflow.
Definition SplitTrees.py:23