Peano
Loading...
Searching...
No Matches
35_offline-load-balancing.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 PNG illustration of the tutorial 35_offline-load-balancing.ipynb
6
7The script computes the offline decomposition of the tutorial's regular
8mesh, builds the tutorial's Euler setup with this hardcoded load balancing,
9runs it with four threads, and lets ParaView's pvbatch render the subdomains
10into 35_offline-load-balancing-subdomains.png. It reuses the build and
11render steps of 30_domain-decomposition.py, as the tutorial builds upon the
12setup of 30_domain-decomposition.ipynb. Call the script from anywhere:
13
14 python3 tutorials/exahype2/illustrations/35_offline-load-balancing.py
15
16All builds and outputs go into a temporary directory (or --work-directory).
17The script needs ParaView's pvbatch (--pvbatch).
18
19"""
20import argparse
21import importlib.util
22import os
23import tempfile
24
25Here = os.path.dirname(os.path.abspath(__file__))
26
27# The file name of the script starts with a digit, i.e. we cannot import it
28_specification = importlib.util.spec_from_file_location(
29 "domain_decomposition_illustrations", os.path.join(Here, "30_domain-decomposition.py")
30)
31domain_decomposition = importlib.util.module_from_spec(_specification)
32_specification.loader.exec_module(domain_decomposition)
33
35import toolbox.loadbalancing.api.output.Hardcoded as Hardcoded
36import toolbox.loadbalancing.api.strategies.Decomposition as Decomposition
37import toolbox.loadbalancing.api.strategies.SplitTrees as SplitTrees
38
39SubdomainsPicture = os.path.join(Here, "35_offline-load-balancing-subdomains.png")
40
41
43 """! Arguments of the hardcoded load balancing, as computed by the tutorial"""
44 tree = RegularGridGenerator.RegularGridGenerator(max_level=3, dimensions=2)
46 tree,
48 peano_tree=tree, number_of_subtrees=domain_decomposition.NumberOfThreads
49 ),
50 periodic_BC=[True, True],
51 )
52 destination_ranks = Hardcoded.assign_trees_to_ranks_round_Robin(
53 number_of_subtrees=tree.number_of_subtrees, max_ranks=1
54 )
55 configuration, mode = Hardcoded.create_constructor_initialisation_string(
56 tree, destination_ranks, modes=Hardcoded.BottomUp
57 )
58 return configuration
59
60
61if __name__ == "__main__":
62 parser = argparse.ArgumentParser(
63 description="Create the PNG of the tutorial 35_offline-load-balancing.ipynb"
64 )
65 parser.add_argument(
66 "--work-directory",
67 default=None,
68 help="Directory for builds and outputs (default: temporary directory)",
69 )
70 parser.add_argument(
71 "--peano-root",
72 default=domain_decomposition.PeanoRoot,
73 help="Peano installation with the compiled libraries (default: repository holding this script)",
74 )
75 parser.add_argument("--pvbatch", default="pvbatch", help="ParaView's pvbatch executable")
76 args = parser.parse_args()
77
78 work_directory = args.work_directory or tempfile.mkdtemp(prefix="35_offline-load-balancing-")
79 print("build and run in {}".format(work_directory))
80 domain_decomposition.build_and_run(
81 work_directory,
82 os.path.abspath(args.peano_root),
83 tutorial="35_offline-load-balancing",
84 namespace="offlineloadbalancing",
85 load_balancer="toolbox::loadbalancing::strategies::Hardcoded",
86 load_balancer_arguments=offline_decomposition(),
87 )
88 domain_decomposition.render_subdomains(work_directory, args.pvbatch, SubdomainsPicture)
89 print("wrote PNG into {}".format(Here))
offline_decomposition()
Arguments of the hardcoded load balancing, as computed by the tutorial.
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