Peano
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
24 int result = 0;
25
26 if (
28 and
29 _statistics.hasConsistentViewOfWorld()
30 and
31 _numberOfStableGridIterations>3
32 ) {
33 int maxPermittedTreesPerRank = _configuration->getMaxLocalTreesPerRank(_state)>=1
34 ? _configuration->getMaxLocalTreesPerRank(_state)
35 : std::numeric_limits<int>::max();
36
37 int treesPerRankToExploitAllThreads = std::min(
38 maxPermittedTreesPerRank,
39 tarch::multicore::Core::getInstance().getNumberOfThreads()
40 );
41
42 int minTreeSize = std::max(
43 _configuration->getMinTreeSize(_state),
44 1
45 );
46
47 int treesPerRankAccommodatingMinTreeSize = std::max(
48 _statistics.getLocalNumberOfInnerUnrefinedCells() / minTreeSize / tarch::mpi::Rank::getInstance().getNumberOfRanks(),
49 1
50 );
51
52 result = std::min( treesPerRankAccommodatingMinTreeSize, treesPerRankToExploitAllThreads );
53
54 logInfo(
55 "getNumberOfTreesPerRank()",
56 "mesh has " << _statistics.getLocalNumberOfInnerUnrefinedCells() <<
57 " cells, so split " << result << " times " <<
58 "(maxPermittedTreesPerRank=" << maxPermittedTreesPerRank <<
59 ",treesPerRankToExploitAllThreads=" << treesPerRankToExploitAllThreads <<
60 ",minTreeSize=" << minTreeSize <<
61 ",treesPerRankAccommodatingMinTreeSize" << treesPerRankAccommodatingMinTreeSize <<
62 ")"
63 );
64 }
65
66 return result;
67}
68
69
71 if (
72 _statistics.hasConsistentViewOfWorld()
73 and
74 _previousNumberOfCells == _statistics.getGlobalNumberOfInnerUnrefinedCells()
75 ) {
76 _numberOfStableGridIterations++;
77 }
78 else {
79 _numberOfStableGridIterations = 0;
80 }
81
82 if (
83 not tarch::mpi::Rank::getInstance().isGlobalMaster()
84 and
86 ) {
88 }
89
90 const int numberOfTreesPerRank = getNumberOfTreesPerRank();
91
92 if ( numberOfTreesPerRank>0 ) {
94
95 int cellsPerTree = std::max(
96 static_cast<int>(std::round(_statistics.getGlobalNumberOfInnerUnrefinedCells() / ranks / numberOfTreesPerRank )),
97 1
98 );
99
100 logInfo(
101 "updateLoadBalancing()",
102 "try to create " << numberOfTreesPerRank <<
103 " trees per rank with internal state" << toString() <<
104 " to produce " << ranks << "x" << numberOfTreesPerRank <<
105 " trees with approx " << cellsPerTree << " cells per tree"
106 );
107
108 int totalSplits = cellsPerTree;
109 for (int targetRank=0; targetRank<ranks; targetRank++ )
110 for (int treeNumber= targetRank==0 ? 1 : 0; treeNumber<numberOfTreesPerRank; treeNumber++ ) {
111 int thisTreesCells = cellsPerTree;
112 if (static_cast<int>(_statistics.getGlobalNumberOfInnerUnrefinedCells()) % (ranks*numberOfTreesPerRank) >= totalSplits) {
113 thisTreesCells++;
114 }
115
116 triggerSplit(thisTreesCells, targetRank);
117
118 totalSplits++;
119 }
120
122 }
123 else if (not _statistics.hasConsistentViewOfWorld()) {
124 _previousNumberOfCells = -1;
125 }
126 else {
127 _previousNumberOfCells = _statistics.getGlobalNumberOfInnerUnrefinedCells();
128 }
129}
130
131
133 _statistics.updateGlobalView();
134 _costMetrics->updateGlobalView();
135 _blacklist.update();
136
137 _statistics.notifyOfStateChange( _state );
138
139 updateLoadBalancing();
141}
142
143
145 logInfo( "triggerSplit(int,int,int)", "trigger split from tree 0 into new tree on rank " << targetRank << " with " << numberOfCells << " cell(s)" );
146
147 assertionEquals( peano4::parallel::SpacetreeSet::getInstance().getLocalSpacetrees().size(), 1 );
148 assertion( tarch::mpi::Rank::getInstance().isGlobalMaster() );
149
150 const int sourceTree = 0;
152 if (not success) {
153 logInfo( "triggerSplit()", "wanted to split local rank " << sourceTree << " but failed" );
154 }
155
156 _blacklist.triggeredSplit( sourceTree );
157 _statistics.incLocalNumberOfSplits();
158}
159
160
#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:552
static Rank & getInstance()
This operation returns the singleton instance.
Definition Rank.cpp:539
static Core & getInstance()
Definition Core.cpp:56
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