Peano 4
Loading...
Searching...
No Matches
SpreadOutOnceGridStagnates.cpp
Go to the documentation of this file.
2
4
5
8
9
10tarch::logging::Log toolbox::loadbalancing::strategies::SpreadOutOnceGridStagnates::_log( "toolbox::loadbalancing::strategies::SpreadOutOnceGridStagnates" );
11
12
14 AbstractLoadBalancing( configuration, costMetrics ),
15 _previousNumberOfCells(-1),
16 _numberOfStableGridIterations(0) {
17 assertion( configuration!=nullptr );
20}
21
22
25
26
27
29 int result = 0;
30
31 if (
33 and
34 _statistics.hasConsistentViewOfWorld()
35 and
36 _numberOfStableGridIterations>3
37 ) {
38 const int MaxTreesPerRank = std::min(
39 _configuration->getMaxLocalTreesPerRank(_state),
41 );
42 const int MaxTotalTrees = MaxTreesPerRank * tarch::mpi::Rank::getInstance().getNumberOfRanks();
43
44 const int MinMeshSizeToAccommodateMaxTotalTrees = _configuration->getMinTreeSize(_state)<=1 ? MaxTotalTrees : _configuration->getMinTreeSize(_state) * MaxTotalTrees;
45
46 const int MinTreeSize = std::max(
47 _configuration->getMinTreeSize(_state),
48 1
49 );
50
51 result = std::min(
52 MaxTreesPerRank,
53 std::max(1,_statistics.getLocalNumberOfInnerUnrefinedCells() / MinTreeSize / tarch::mpi::Rank::getInstance().getNumberOfRanks())
54 );
55
56 logInfo(
57 "getNumberOfTreesPerRank()",
58 "mesh has " << _statistics.getLocalNumberOfInnerUnrefinedCells() <<
59 " cells already (we would need at least " << MinMeshSizeToAccommodateMaxTotalTrees <<
60 " cells)"
61 );
62 logInfo(
63 "getNumberOfTreesPerRank()",
64 "create " << result << " trees per rank to obtain up to " << MaxTotalTrees << " trees in total (min tree size=" << _configuration->getMinTreeSize(_state) <<
65 ", max-trees-per-rank=" << _configuration->getMaxLocalTreesPerRank(_state) << ")"
66 );
67 }
68
69 return result;
70}
71
72
74 if (
75 _statistics.hasConsistentViewOfWorld()
76 and
77 _previousNumberOfCells == _statistics.getGlobalNumberOfInnerUnrefinedCells()
78 ) {
79 _numberOfStableGridIterations++;
80 }
81 else {
82 _numberOfStableGridIterations = 0;
83 }
84
85 if (
86 not tarch::mpi::Rank::getInstance().isGlobalMaster()
87 and
89 ) {
90 _state = State::Stagnation;
91 }
92
93 const int numberOfTreesPerRank = getNumberOfTreesPerRank();
94
95 if ( numberOfTreesPerRank>0 ) {
97
98 int cellsPerTree = std::max(
99 static_cast<int>(std::round(_statistics.getGlobalNumberOfInnerUnrefinedCells() / ranks / numberOfTreesPerRank )),
100 1
101 );
102
103 logInfo(
104 "updateLoadBalancing()",
105 "try to create " << numberOfTreesPerRank <<
106 " trees per rank with internal state" << toString() <<
107 " to produce " << ranks << "x" << numberOfTreesPerRank <<
108 " trees with approx " << cellsPerTree << " cells per tree"
109 );
110
111 int totalSplits = cellsPerTree;
112 for (int targetRank=0; targetRank<ranks; targetRank++ )
113 for (int treeNumber= targetRank==0 ? 1 : 0; treeNumber<numberOfTreesPerRank; treeNumber++ ) {
114 int thisTreesCells = cellsPerTree;
115 if (static_cast<int>(_statistics.getGlobalNumberOfInnerUnrefinedCells()) % (ranks*numberOfTreesPerRank) >= totalSplits) {
116 thisTreesCells++;
117 }
118
119 triggerSplit(thisTreesCells, targetRank);
120
121 totalSplits++;
122 }
123
124 _state = State::Stagnation;
125 }
126 else if (not _statistics.hasConsistentViewOfWorld()) {
127 _previousNumberOfCells = -1;
128 }
129 else {
130 _previousNumberOfCells = _statistics.getGlobalNumberOfInnerUnrefinedCells();
131 }
132}
133
134
136 _statistics.updateGlobalView();
137 _costMetrics->updateGlobalView();
138 _blacklist.update();
139
140 _statistics.notifyOfStateChange( _state );
141
142 updateLoadBalancing();
144}
145
146
148 logInfo( "triggerSplit(int,int,int)", "trigger split from tree 0 into new tree on rank " << targetRank << " with " << numberOfCells << " cell(s)" );
149
150 assertionEquals( peano4::parallel::SpacetreeSet::getInstance().getLocalSpacetrees().size(), 1 );
151 assertion( tarch::mpi::Rank::getInstance().isGlobalMaster() );
152
153 const int sourceTree = 0;
155 if (not success) {
156 logInfo( "triggerSplit()", "wanted to split local rank " << sourceTree << " but failed" );
157 }
158
159 _blacklist.triggeredSplit( sourceTree );
160 _statistics.incLocalNumberOfSplits();
161}
162
163
#define assertionEquals(lhs, rhs)
#define assertion(expr)
#define logInfo(methodName, logMacroMessageStream)
Wrapper macro around tarch::tarch::logging::Log to improve logging.
Definition Log.h:411
bool split(int treeId, const peano4::SplitInstruction &instruction, int targetRank)
Split a local tree.
static SpacetreeSet & getInstance()
Log Device.
Definition Log.h:516
int getNumberOfRanks() const
Definition Rank.cpp:551
static Rank & getInstance()
This operation returns the singleton instance.
Definition Rank.cpp:538
static Core & getInstance()
Definition Core.cpp:55
int getNumberOfThreads() const
Returns the number of threads that is used.
Definition Core.cpp:66
Abstract interface to tweak the behaviour of the recursive subdivision.
void notifyOfStateChange(State state)
SpreadOutOnceGridStagnates(Configuration *configuration=new DefaultConfiguration(), CostMetrics *costMetrics=new toolbox::loadbalancing::metrics::CellCount())
int getNumberOfTreesPerRank() const
Return 0 if the load balancing should not split (yet) and otherwise return number of splits required.
std::string toString(Filter filter)
Definition convert.cpp:170
void dumpStatistics()
Dump the stats of the lb to the terminal (info device).
@ Stagnation
You usually don't get this state when we query the configuration, i.e.
@ InterRankDistribution
Code has not yet spread out over all ranks but would like to do so now.
Instruction to split.
Definition grid.h:34