5Create the PNG illustration of the tutorial 35_offline-load-balancing.ipynb
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:
14 python3 tutorials/exahype2/illustrations/35_offline-load-balancing.py
16All builds and outputs go into a temporary directory (or --work-directory).
17The script needs ParaView's pvbatch (--pvbatch).
25Here = os.path.dirname(os.path.abspath(__file__))
28_specification = importlib.util.spec_from_file_location(
29 "domain_decomposition_illustrations", os.path.join(Here,
"30_domain-decomposition.py")
31domain_decomposition = importlib.util.module_from_spec(_specification)
32_specification.loader.exec_module(domain_decomposition)
35import toolbox.loadbalancing.api.output.Hardcoded
as Hardcoded
36import toolbox.loadbalancing.api.strategies.Decomposition
as Decomposition
37import toolbox.loadbalancing.api.strategies.SplitTrees
as SplitTrees
39SubdomainsPicture = os.path.join(Here,
"35_offline-load-balancing-subdomains.png")
43 """! Arguments of the hardcoded load balancing, as computed by the tutorial"""
48 peano_tree=tree, number_of_subtrees=domain_decomposition.NumberOfThreads
50 periodic_BC=[
True,
True],
52 destination_ranks = Hardcoded.assign_trees_to_ranks_round_Robin(
53 number_of_subtrees=tree.number_of_subtrees, max_ranks=1
55 configuration, mode = Hardcoded.create_constructor_initialisation_string(
56 tree, destination_ranks, modes=Hardcoded.BottomUp
61if __name__ ==
"__main__":
62 parser = argparse.ArgumentParser(
63 description=
"Create the PNG of the tutorial 35_offline-load-balancing.ipynb"
68 help=
"Directory for builds and outputs (default: temporary directory)",
72 default=domain_decomposition.PeanoRoot,
73 help=
"Peano installation with the compiled libraries (default: repository holding this script)",
75 parser.add_argument(
"--pvbatch", default=
"pvbatch", help=
"ParaView's pvbatch executable")
76 args = parser.parse_args()
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(
82 os.path.abspath(args.peano_root),
83 tutorial=
"35_offline-load-balancing",
84 namespace=
"offlineloadbalancing",
85 load_balancer=
"toolbox::loadbalancing::strategies::Hardcoded",
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.