Peano
Loading...
Searching...
No Matches
Hardcoded.cpp
Go to the documentation of this file.
2
4
5#include "tarch/Assertions.h"
7
10
11
12tarch::logging::Log toolbox::loadbalancing::strategies::Hardcoded::_log( "toolbox::loadbalancing::strategies::Hardcoded" );
13
14
16 std::initializer_list<int> gridSweeps,
17 std::initializer_list<int> splittingTrees,
18 std::initializer_list<int> numberOfCells,
19 std::initializer_list<int> destinationRanks,
20 std::initializer_list<peano4::SplitInstruction::Mode> modes
21):
22 AbstractLoadBalancing( nullptr, nullptr ),
24 assertionEquals4( gridSweeps.size(), numberOfCells.size(), gridSweeps.size(), splittingTrees.size(), numberOfCells.size(), destinationRanks.size() );
25 assertionEquals4( splittingTrees.size(), numberOfCells.size(), gridSweeps.size(), splittingTrees.size(), numberOfCells.size(), destinationRanks.size() );
26 assertionEquals4( destinationRanks.size(), numberOfCells.size(), gridSweeps.size(), splittingTrees.size(), numberOfCells.size(), destinationRanks.size() );
27 assertionEquals4( modes.size(), numberOfCells.size(), gridSweeps.size(), splittingTrees.size(), numberOfCells.size(), destinationRanks.size() );
28
29 auto gridSweep = gridSweeps.begin();
30 auto splittingTree = splittingTrees.begin();
31 auto cells = numberOfCells.begin();
32 auto destinationRank = destinationRanks.begin();
33 auto mode = modes.begin();
34
35 while (gridSweep != gridSweeps.end()) {
36 _splits.push( Split( *gridSweep, *splittingTree, *cells, *destinationRank, *mode ) );
37 gridSweep++;
38 splittingTree++;
39 cells++;
40 destinationRank++;
41 mode++;
42 }
43}
44
45
47 std::initializer_list<int> gridSweeps,
48 std::initializer_list<int> splittingTrees,
49 std::initializer_list<int> numberOfCells,
50 std::initializer_list<int> destinationRanks,
52):
53 AbstractLoadBalancing( nullptr, nullptr ),
55 assertionEquals4( gridSweeps.size(), numberOfCells.size(), gridSweeps.size(), splittingTrees.size(), numberOfCells.size(), destinationRanks.size() );
56 assertionEquals4( splittingTrees.size(), numberOfCells.size(), gridSweeps.size(), splittingTrees.size(), numberOfCells.size(), destinationRanks.size() );
57 assertionEquals4( destinationRanks.size(), numberOfCells.size(), gridSweeps.size(), splittingTrees.size(), numberOfCells.size(), destinationRanks.size() );
58
59 auto gridSweep = gridSweeps.begin();
60 auto splittingTree = splittingTrees.begin();
61 auto cells = numberOfCells.begin();
62 auto destinationRank = destinationRanks.begin();
63
64 while (gridSweep != gridSweeps.end()) {
65 _splits.push( Split( *gridSweep, *splittingTree, *cells, *destinationRank, mode ) );
66 gridSweep++;
67 splittingTree++;
68 cells++;
69 destinationRank++;
70 }
71}
72
73
81
82
84 int splittingTree_,
85 int numberOfCells_,
86 int destinationRank_,
88):
89 gridSweep(gridSweep_),
90 splittingTree(splittingTree_),
91 numberOfCells(numberOfCells_),
92 destinationRank(destinationRank_),
93 mode(mode_) {
94}
95
96
99
100 while (not _splits.empty() and _currentGridSweep >= _splits.front().gridSweep) {
101 if (_currentGridSweep > _splits.front().gridSweep) {
102 logError(
103 "finishStep()",
104 "splitting instructions lag behind actual simulation evolution (current grid sweep "
105 << _currentGridSweep << " while split should have happened in sweep "
106 << _splits.front().gridSweep << "). Try to catch up"
107 );
108 }
109
110 Split split( _splits.front() );
111 _splits.pop();
112
113 if ( peano4::parallel::SpacetreeSet::getInstance().isLocalSpacetree( split.splittingTree) ) {
114 if ( _state==State::SwitchedOff ) {
115 logError(
116 "finishStep()",
117 "wanted to split " << split.numberOfCells << " cell(s) from tree " <<
118 split.splittingTree << " and to deploy them to new tree on rank " << split.destinationRank <<
119 ". However, load (re-)balancing is deactivated"
120 );
121 }
123 split.splittingTree,
124 peano4::SplitInstruction{split.numberOfCells,split.mode},
125 split.destinationRank
126 )) {
128 "finishStep()",
129 "had been told to split " << split.numberOfCells << " cell(s) from tree " <<
130 split.splittingTree << " and to deploy them to new tree on rank " << split.destinationRank <<
131 ". However, that failed"
132 );
133 }
134 }
135 }
136
138}
139
140
#define assertionEquals4(lhs, rhs, larg, rarg, three, four)
#define logError(methodName, logMacroMessageStream)
Wrapper macro around tarch::tarch::logging::Log to improve logging.
Definition Log.h:464
#define logWarning(methodName, logMacroMessageStream)
Wrapper macro around tarch::tarch::logging::Log to improve logging.
Definition Log.h:440
static SpacetreeSet & getInstance()
Log Device.
Definition Log.h:516
AbstractLoadBalancing(Configuration *configuration, CostMetrics *costMetrics)
Constructor.
virtual void finishStep() override
Finish the step.
Definition Hardcoded.cpp:97
int _currentGridSweep
Grid sweep represents the iteration number or finishStep() call count.
Definition Hardcoded.h:129
Hardcoded(std::initializer_list< int > gridSweeps, std::initializer_list< int > splittingTrees, std::initializer_list< int > numberOfCells, std::initializer_list< int > destinationRanks, std::initializer_list< peano4::SplitInstruction::Mode > modes)
Construct hard-coded load balancing strategy.
Definition Hardcoded.cpp:15
void dumpStatistics()
Dump the stats of the lb to the terminal (info device).
@ SwitchedOff
You usually don't get this state when we query the configuration, i.e.
Definition State.h:70
Instruction to split.
Definition grid.h:34