14 _previousNumberOfCells(-1),
15 _numberOfStableGridIterations(0) {
30 const int MaxTreesPerRank = std::min(
35 const int MinMeshSizeToAccommodateMaxTotalTrees = _configuration->getMinTreeSize(
_state) <= 1
37 : _configuration->getMinTreeSize(
_state) * MaxTotalTrees;
41 if (_numberOfStableGridIterations > 3) {
43 const int MinTreeSize = std::max(_configuration->getMinTreeSize(
_state), 1);
45 result = _statistics.getLocalNumberOfInnerUnrefinedCells() / MinTreeSize
48 "getNumberOfTreesPerRank()",
49 "mesh is stable, so create "
50 << result <<
" trees even though we might end up with fewer cells per tree than the lower bound "
51 << _configuration->getMinTreeSize(
_state) <<
" or might not be able to use all cores"
53 }
else if (_statistics.getLocalNumberOfInnerUnrefinedCells() >= MinMeshSizeToAccommodateMaxTotalTrees) {
56 "getNumberOfTreesPerRank()",
58 << _statistics.getLocalNumberOfInnerUnrefinedCells() <<
" cells already, so create " << result
59 <<
" trees per rank (min tree size=" << _configuration->getMinTreeSize(
_state)
60 <<
", max-trees-per-rank=" << _configuration->getMaxLocalTreesPerRank(
_state) <<
")"
70 if (_statistics.hasConsistentViewOfWorld() and _previousNumberOfCells == _statistics.getGlobalNumberOfInnerUnrefinedCells()) {
71 _numberOfStableGridIterations++;
73 _numberOfStableGridIterations = 0;
80 const int numberOfTreesPerRank = getNumberOfTreesPerRank();
82 if (numberOfTreesPerRank > 0) {
85 int cellsPerTree = std::max(
86 static_cast<int>(std::round(_statistics.getGlobalNumberOfInnerUnrefinedCells() / ranks / numberOfTreesPerRank)), 1
90 "updateLoadBalancing()",
92 << numberOfTreesPerRank <<
" trees per rank with internal state" <<
toString() <<
" to produce " << ranks <<
"x"
93 << numberOfTreesPerRank <<
" trees with approx " << cellsPerTree <<
" cells per tree"
96 int totalSplits = cellsPerTree;
97 for (
int targetRank = 0; targetRank < ranks; targetRank++)
98 for (
int treeNumber = targetRank == 0 ? 1 : 0; treeNumber < numberOfTreesPerRank; treeNumber++) {
99 int thisTreesCells = cellsPerTree;
100 if (
static_cast<int>(_statistics.getGlobalNumberOfInnerUnrefinedCells()) % (ranks * numberOfTreesPerRank) >= totalSplits) {
104 triggerSplit(thisTreesCells, targetRank);
110 }
else if (not _statistics.hasConsistentViewOfWorld()) {
111 _previousNumberOfCells = -1;
113 _previousNumberOfCells = _statistics.getGlobalNumberOfInnerUnrefinedCells();
119 _statistics.updateGlobalView();
120 _costMetrics->updateGlobalView();
123 _statistics.notifyOfStateChange(
_state);
125 updateLoadBalancing();
132 "triggerSplit(int,int,int)",
133 "trigger split from tree 0 into new tree on rank " << targetRank <<
" with " << numberOfCells <<
" cell(s)"
139 const int sourceTree = 0;
144 logInfo(
"triggerSplit()",
"wanted to split local rank " << sourceTree <<
" but failed");
147 _blacklist.triggeredSplit(sourceTree);
148 _statistics.incLocalNumberOfSplits();
#define assertionEquals(lhs, rhs)
#define logInfo(methodName, logMacroMessageStream)
Wrapper macro around tarch::tarch::logging::Log to improve logging.
bool split(int treeId, const peano4::SplitInstruction &instruction, int targetRank)
Split a local tree.
static SpacetreeSet & getInstance()
int getNumberOfRanks() const
static Rank & getInstance()
This operation returns the singleton instance.
static Core & getInstance()
int getNumberOfThreads() const
Returns the number of threads that is used.
std::string toString(Filter filter)