18 _configuration(configuration),
19 _costMetrics(costMetrics),
23 if (_configuration !=
nullptr) {
24 delete _configuration;
26 if (_costMetrics !=
nullptr) {
33 _configuration =
nullptr;
34 _costMetrics =
nullptr;
39 std::ostringstream msg;
41 msg <<
"(state=" <<
::toString(
_state) <<
",statistics=" << _statistics.toString()
42 <<
",cost-metrics=" << _costMetrics->toString() <<
",blacklist=" << _blacklist.toString() <<
")";
49 return _statistics.getNumberOfStateUpdatesWithoutAnySplit() < 3;
58 logInfo(
"enable()",
"switched load balancing off");
62 _statistics.notifyOfStateChange(
_state);
68 return globally ? (_statistics.getGlobalNumberOfRanksWithEnabledLoadBalancing() > 0) : (
_state !=
State::SwitchedOff);
78 return _statistics.getGlobalNumberOfTrees();
85 if (_configuration->makeSplitDependOnMemory(
_state)) {
95 _statistics.waitForGlobalDataExchange();
96 _costMetrics->waitForGlobalDataExchange();
101 if (not _statistics.hasConsistentViewOfWorld()) {
108 const double optimalCost =
static_cast<double>(_costMetrics->getGlobalCost())
111 const double illbalancing = (_costMetrics->getCostOfLocalRank() - optimalCost) / optimalCost;
112 const double balancingRatio = _configuration->getWorstCaseBalancingRatio(
_state);
113 bool result = illbalancing > 1.0 - balancingRatio;
117 "doesRankViolateBalancingCondition()",
118 "rank does violate balancing as we have ill-balancing of "
119 << illbalancing <<
" (global cost=" << _costMetrics->getGlobalCost() <<
")"
129 if (not _statistics.hasConsistentViewOfWorld()) {
139 double minCost = std::numeric_limits<double>::max();
142 maxCost = std::max(maxCost, _costMetrics->getCostOfLocalTree(p));
143 minCost = std::min(minCost, _costMetrics->getCostOfLocalTree(p));
151 if (maxCost > 0.0 and minCost > 0.0) {
152 double relativeWeightSmalltestTree = minCost / maxCost;
153 double balanceThreshold = _configuration->getWorstCaseBalancingRatio(
_state);
155 result = relativeWeightSmalltestTree < balanceThreshold;
158 "isLocalBalancingBad()",
159 "local trees are ill-balanced="
160 << result <<
", rel-weight=" << relativeWeightSmalltestTree <<
", threshold=" << balanceThreshold
161 <<
", #min-cost=" << minCost <<
", #max-cost=" << maxCost
172 and _statistics.getGlobalNumberOfTrees() > 0;
177 const int heaviestSpacetree = getIdOfHeaviestLocalSpacetree();
179 "getWeightOfHeaviestLocalSpacetree()",
181 << heaviestSpacetree <<
", #octants="
183 .getGridStatistics(heaviestSpacetree)
184 .getNumberOfLocalUnrefinedCells()
186 return heaviestSpacetree == NoHeaviestTreeAvailable ? -1 : _costMetrics->getCostOfLocalTree(heaviestSpacetree);
192 int result = NoHeaviestTreeAvailable;
193 double maxLocalCost = -1;
195 for (
auto p : idsOfLocalSpacetrees) {
197 _costMetrics->getCostOfLocalTree(p)>maxLocalCost
201 maxLocalCost = _costMetrics->getCostOfLocalTree(p) > maxLocalCost;
211 int result = NoHeaviestTreeAvailable;
212 int maxLocalCost = -1;
214 for (
auto p : idsOfLocalSpacetrees) {
216 _costMetrics->getCostOfLocalTree(p)>maxLocalCost
220 maxLocalCost = _costMetrics->getCostOfLocalTree(p);
224 if (maxLocalCost > 0.0) {
226 "getIdOfHeaviestLocalSpacetree(double)",
227 "try to find one maximum tree which has weight close to "
228 << maxLocalCost <<
", i.e. has more than " << (tolerance * maxLocalCost) <<
" cost"
230 for (
auto p : idsOfLocalSpacetrees) {
236 (rand() % 2 == 1 or result == NoHeaviestTreeAvailable)
239 "getIdOfHeaviestLocalSpacetree(double)",
240 "tree " << p <<
" meets criterion with weight of " << _costMetrics->getCostOfLocalTree(p)
std::ostream & operator<<(std::ostream &out, const toolbox::loadbalancing::AbstractLoadBalancing &balancing)
#define logDebug(methodName, logMacroMessageStream)
#define logInfo(methodName, logMacroMessageStream)
Wrapper macro around tarch::tarch::logging::Log to improve logging.
peano4::grid::GridStatistics getGridStatistics() const
Return statistics object for primary spacetree.
static SpacetreeSet & getInstance()
std::set< int > getLocalSpacetrees() const
int getNumberOfRanks() const
static Rank & getInstance()
This operation returns the singleton instance.
std::string toString(Filter filter)
bool greaterEquals(double lhs, double rhs, double tolerance=NUMERICAL_ZERO_DIFFERENCE)
bool equals(const Matrix< Rows, Cols, Scalar > &lhs, const Matrix< Rows, Cols, Scalar > &rhs, const Scalar &tolerance=NUMERICAL_ZERO_DIFFERENCE)
Compares to matrices on equality by means of a numerical accuracy.
int getMemoryUsage(MemoryUsageFormat format)
Method for getting the application's memory footprint.
int getFreeMemory(MemoryUsageFormat format)
int getNumberOfLocalUnrefinedCells() const