Peano
Loading...
Searching...
No Matches
test_hardcoded_output.py
Go to the documentation of this file.
1import pytest
2
3from toolbox.loadbalancing.api.input.RegularGridGenerator import RegularGridGenerator
4import toolbox.loadbalancing.api.output.Hardcoded as Hardcoded
5import toolbox.loadbalancing.api.strategies.Decomposition as Decomposition
6import toolbox.loadbalancing.api.strategies.SplitTrees as split_strategy
7
8
9def _split_regular_grid(number_of_subtrees, periodic_BC=None):
10 """Split the 27x27 mesh of tutorial 35 into number_of_subtrees subtrees"""
11 tree = RegularGridGenerator(name="pytest-hardcoded", max_level=3, dimensions=2)
12 split_strategy.split_tree(
13 tree,
15 peano_tree=tree, number_of_subtrees=number_of_subtrees
16 ),
17 periodic_BC=periodic_BC,
18 )
19 return tree
20
21
22def _cells_per_subtree(tree, number_of_subtrees):
23 counts = [0] * number_of_subtrees
24 for a in range(27):
25 for b in range(27):
26 weight, subtree = tree._tree_arrays[2][a][b]
27 counts[subtree] += weight
28 return counts
29
30
31# ---------------------------------------------------------------------------
32# Periodic boundaries
33# ---------------------------------------------------------------------------
34
35
37 """All cells along a periodic boundary remain on subtree 0, and the shares still add up."""
38 tree = _split_regular_grid(4, periodic_BC=[True, True])
39 for a in range(27):
40 for b in range(27):
41 if min(a, b) == 0 or max(a, b) == 26:
42 assert tree._tree_arrays[2][a][b][1] == 0, (a, b)
43 assert _cells_per_subtree(tree, 4) == [183, 182, 182, 182]
44
45
47 """Only the faces of periodic axes are kept on subtree 0."""
48 tree = _split_regular_grid(4, periodic_BC=[True, False])
49 owners_along_x_faces = {
50 tree._tree_arrays[2][a][b][1] for a in (0, 26) for b in range(27)
51 }
52 owners_along_y_faces = {
53 tree._tree_arrays[2][a][b][1] for a in range(27) for b in (0, 26)
54 }
55 assert owners_along_x_faces == {0}
56 assert owners_along_y_faces != {0}
57
58
60 """periodic_BC=None and all-False yield the same decomposition."""
61 plain = _split_regular_grid(4)
62 non_periodic = _split_regular_grid(4, periodic_BC=[False, False])
63 assert (plain._tree_arrays[2] == non_periodic._tree_arrays[2]).all()
64
65
66# ---------------------------------------------------------------------------
67# Split mode markers
68# ---------------------------------------------------------------------------
69
70
72 tree = _split_regular_grid(4)
73 configuration, mode = Hardcoded.create_constructor_initialisation_string(
74 tree, [0, 0, 0], modes=Hardcoded.BottomUp
75 )
76 assert mode == "peano4::SplitInstruction::Mode::BottomUp"
77 assert (
78 configuration
79 == "{{0, 0, 0}, {182, 182, 182}, {0, 0, 0}, peano4::SplitInstruction::Mode::BottomUp}"
80 )
81
82
84 tree = _split_regular_grid(4)
85 configuration, mode = Hardcoded.create_constructor_initialisation_string(
86 tree,
87 [0, 0, 0],
88 modes=[Hardcoded.TopDown, Hardcoded.TopDown, Hardcoded.BottomUp],
89 )
90 assert mode == (
91 "{peano4::SplitInstruction::Mode::AggressiveTopDown, "
92 "peano4::SplitInstruction::Mode::AggressiveTopDown, "
93 "peano4::SplitInstruction::Mode::BottomUp}"
94 )
95 assert configuration.endswith(mode + "}")
96
97
98@pytest.mark.parametrize("modes", [[Hardcoded.BottomUp], ["sideways"] * 3])
100 tree = _split_regular_grid(4)
101 with pytest.raises(ValueError):
102 Hardcoded.create_constructor_initialisation_string(tree, [0, 0, 0], modes=modes)
103
104
105# ---------------------------------------------------------------------------
106# Round-robin assignment of subtrees to ranks
107# ---------------------------------------------------------------------------
108
109
110@pytest.mark.parametrize("number_of_ranks", [1, 2, 3, 8])
112 tree = _split_regular_grid(8)
113 destination_ranks = Hardcoded.assign_trees_to_ranks_round_Robin(
114 number_of_subtrees=8, max_ranks=number_of_ranks
115 )
116 Hardcoded.create_constructor_initialisation_string(
117 tree, destination_ranks, number_of_ranks=number_of_ranks
118 )
119
120
122 """Subtree s has to live on rank s%R, as Peano numbers its trees round robin."""
123 tree = _split_regular_grid(8)
124 with pytest.raises(ValueError):
125 Hardcoded.create_constructor_initialisation_string(tree, [1, 1, 1, 2, 2, 2, 0])
126
127
129 """Round robin over three ranks is no round robin over four ranks."""
130 tree = _split_regular_grid(8)
131 destination_ranks = Hardcoded.assign_trees_to_ranks_round_Robin(
132 number_of_subtrees=8, max_ranks=3
133 )
134 with pytest.raises(ValueError):
135 Hardcoded.create_constructor_initialisation_string(
136 tree, destination_ranks, number_of_ranks=4
137 )
equidistant_splitting(Tree peano_tree, int number_of_subtrees, verbose=False)
test_periodic_frame_only_along_periodic_axes()
Only the faces of periodic axes are kept on subtree 0.
test_no_periodic_boundaries_keeps_plain_split()
periodic_BC=None and all-False yield the same decomposition.
_cells_per_subtree(tree, number_of_subtrees)
test_periodic_frame_stays_on_subtree_zero()
All cells along a periodic boundary remain on subtree 0, and the shares still add up.
test_other_assignments_are_rejected()
Subtree s has to live on rank sR, as Peano numbers its trees round robin.
test_number_of_ranks_is_taken_into_account()
Round robin over three ranks is no round robin over four ranks.
_split_regular_grid(number_of_subtrees, periodic_BC=None)
Split the 27x27 mesh of tutorial 35 into number_of_subtrees subtrees.
test_round_robin_assignment_is_accepted(number_of_ranks)