Peano
Loading...
Searching...
No Matches
toolbox::loadbalancing::AbstractLoadBalancing Class Referenceabstract

#include <AbstractLoadBalancing.h>

Inheritance diagram for toolbox::loadbalancing::AbstractLoadBalancing:
Collaboration diagram for toolbox::loadbalancing::AbstractLoadBalancing:

Public Member Functions

 AbstractLoadBalancing (Configuration *configuration, CostMetrics *costMetrics)
 Constructor.
virtual ~AbstractLoadBalancing ()
 Destructor.
virtual std::string toString () const
 Generic string serialisation.
virtual void enable (bool)
 Switch on/off.
virtual bool hasSplitRecently () const
bool isEnabled (bool globally) const
 Clarifies whether load balancing is, in principle, enabled.
virtual int getGlobalNumberOfTrees () const
 Delegate to stats.
virtual bool hasStagnated () const
 A load balancing can either be stagnating or be switched off for this predicate to hold.
virtual void finishSimulation ()
virtual void finishStep ()=0
 Finish the step.
void setConfigurationAndMetricsNullWithoutDelete ()
 This is only used when you concatenate balancing rules and you want to disable any deletion.

Static Public Attributes

static constexpr int NoHeaviestTreeAvailable = -1
 Is used by tree identification and either indicates that there are no trees at all or means that the heaviest tree is on the blacklist.

Protected Member Functions

bool fitsIntoMemory (State state) const
 Ensure enough memory is left-over.
bool isInterRankBalancingBad () const
 Is the balancing between the ranks ok.
bool isIntraRankBalancingBad () const
 Is the balancing on the rank ok.
bool areRanksUnemployed () const
double getWeightOfHeaviestLocalSpacetree () const
int getIdOfHeaviestLocalSpacetree () const
 Determines the maximum spacetree size a tree should have in the optimal case.
int getIdOfHeaviestLocalSpacetree (double tolerance) const
 Similar to getIdOfHeaviestLocalSpacetree() but you might get one of the trees back that is close to the heaviest one up to tolerance.

Protected Attributes

Blacklist _blacklist
Statistics _statistics
Configuration_configuration
CostMetrics_costMetrics
State _state
 Ensure that you invoke.

Static Protected Attributes

static tarch::logging::Log _log

Detailed Description

Definition at line 24 of file AbstractLoadBalancing.h.

Constructor & Destructor Documentation

◆ AbstractLoadBalancing()

toolbox::loadbalancing::AbstractLoadBalancing::AbstractLoadBalancing ( Configuration * configuration,
CostMetrics * costMetrics )

Constructor.

Data ownership is handed over to the load balancing, i.e. the balancing has to delete the configuration object unless you pass in the nullptr. If you pass in the nullptr, you cannot use the object, so this should be done with care by any subclass.

Many implementations of AbstractLoadBalancing change the _state field immediately in their constructor. Please ensure that you invoke

  _statistics.notifyOfStateChange(_state);

afterwards to ensure that the statistics are correct right from the start.

Rationale

I originally thought it might be reasonable to add assertions to ensure that configuration and costMetrics are not nullptr. However, there are specific hard-coded load balancing schemes which do explicitly use nullptr arguments. Hardcoded is the prime example. Therefore, I do not nullptr checks here and I leave it to subclasses to add the corresponding assertions if they require proper pointers here.

Definition at line 13 of file AbstractLoadBalancing.cpp.

References _blacklist, _configuration, _costMetrics, _state, _statistics, and toolbox::loadbalancing::Undefined.

Referenced by toolbox::loadbalancing::strategies::cascade::Cascade< toolbox::loadbalancing::strategies::SpreadOut, toolbox::loadbalancing::strategies::RecursiveBipartition >::Cascade(), toolbox::loadbalancing::strategies::Hardcoded::Hardcoded(), toolbox::loadbalancing::strategies::Hardcoded::Hardcoded(), toolbox::loadbalancing::strategies::NoLoadBalancing::NoLoadBalancing(), toolbox::loadbalancing::strategies::RecursiveBipartition::RecursiveBipartition(), toolbox::loadbalancing::strategies::SplitOversizedTree::SplitOversizedTree(), toolbox::loadbalancing::strategies::SpreadOut::SpreadOut(), toolbox::loadbalancing::strategies::SpreadOutHierarchically::SpreadOutHierarchically(), and toolbox::loadbalancing::strategies::SpreadOutOnceGridStagnates::SpreadOutOnceGridStagnates().

Here is the caller graph for this function:

◆ ~AbstractLoadBalancing()

toolbox::loadbalancing::AbstractLoadBalancing::~AbstractLoadBalancing ( )
virtual

Destructor.

Free the configuration and cost metrics objects. See the discussion in the constructor for contextual information re the validity of nullptr arguments here.

Definition at line 22 of file AbstractLoadBalancing.cpp.

References _configuration, and _costMetrics.

Member Function Documentation

◆ areRanksUnemployed()

bool toolbox::loadbalancing::AbstractLoadBalancing::areRanksUnemployed ( ) const
protected

Definition at line 170 of file AbstractLoadBalancing.cpp.

References _costMetrics, _statistics, and tarch::la::equals().

Referenced by toolbox::loadbalancing::strategies::RecursiveBipartition::updateState(), and toolbox::loadbalancing::strategies::SplitOversizedTree::updateState().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ enable()

◆ finishSimulation()

◆ finishStep()

◆ fitsIntoMemory()

bool toolbox::loadbalancing::AbstractLoadBalancing::fitsIntoMemory ( State state) const
protected

Ensure enough memory is left-over.

Definition at line 82 of file AbstractLoadBalancing.cpp.

References _configuration, _state, tarch::getFreeMemory(), tarch::getMemoryUsage(), tarch::MByte, and state.

Referenced by toolbox::loadbalancing::strategies::RecursiveBipartition::updateLoadBalancing(), and toolbox::loadbalancing::strategies::SplitOversizedTree::updateLoadBalancing().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getGlobalNumberOfTrees()

◆ getIdOfHeaviestLocalSpacetree() [1/2]

int toolbox::loadbalancing::AbstractLoadBalancing::getIdOfHeaviestLocalSpacetree ( ) const
protected

Determines the maximum spacetree size a tree should have in the optimal case.

As this routine does not really adopt the blacklist, it can introduce cyclles: If we repeatedly try to split the same rank this means that we have tried to split it, have not been successful, and tried again. This can happen, as not all trees can be split. See peano4::grid::Spacetree::isCellTopDownSplitCandidate() and peano4::grid::Spacetree::isCellBottomUpSplitCandidate() for a discussion which cells can be split and which can't. As not all cells can't be given away, not all trees can be split up.

Randomisation

If two or more trees have the same weight, the routine should randomly return one of them.

Parameters
toleranceBy default, you get the last heaviest tree. But you can ask for a random tree
Returns
NoHeaviestTreeAvailable If there are no local trees or if the heaviest tree is on the blacklist, i.e. we have to assume that it still is splitting.

Definition at line 190 of file AbstractLoadBalancing.cpp.

References _costMetrics, peano4::parallel::SpacetreeSet::getInstance(), peano4::parallel::SpacetreeSet::getLocalSpacetrees(), NoHeaviestTreeAvailable, and ThreePowerD.

Referenced by getWeightOfHeaviestLocalSpacetree(), toolbox::loadbalancing::strategies::RecursiveBipartition::toString(), toolbox::loadbalancing::strategies::SplitOversizedTree::toString(), toolbox::loadbalancing::strategies::RecursiveBipartition::updateLoadBalancing(), toolbox::loadbalancing::strategies::SplitOversizedTree::updateLoadBalancing(), and toolbox::loadbalancing::strategies::SpreadOutHierarchically::updateLoadBalancing().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getIdOfHeaviestLocalSpacetree() [2/2]

int toolbox::loadbalancing::AbstractLoadBalancing::getIdOfHeaviestLocalSpacetree ( double tolerance) const
protected

Similar to getIdOfHeaviestLocalSpacetree() but you might get one of the trees back that is close to the heaviest one up to tolerance.

Tolerance here is the relative difference: So you are guaranteed that

\( m_i \geq tolerance \cdot m_{max} \)

or

\( \frac{m_i}{m_{max}} \geq tolerance \)

Definition at line 209 of file AbstractLoadBalancing.cpp.

References _costMetrics, peano4::parallel::SpacetreeSet::getInstance(), peano4::parallel::SpacetreeSet::getLocalSpacetrees(), logInfo, NoHeaviestTreeAvailable, and ThreePowerD.

Here is the call graph for this function:

◆ getWeightOfHeaviestLocalSpacetree()

double toolbox::loadbalancing::AbstractLoadBalancing::getWeightOfHeaviestLocalSpacetree ( ) const
protected
Returns
-1 if there is no local tree yet

Definition at line 176 of file AbstractLoadBalancing.cpp.

References _costMetrics, getIdOfHeaviestLocalSpacetree(), peano4::parallel::SpacetreeSet::getInstance(), logDebug, and NoHeaviestTreeAvailable.

Here is the call graph for this function:

◆ hasSplitRecently()

◆ hasStagnated()

◆ isEnabled()

bool toolbox::loadbalancing::AbstractLoadBalancing::isEnabled ( bool globally) const

Clarifies whether load balancing is, in principle, enabled.

Might however mean that the load balancing is currently (temporarily) disabled. In this case, the routine still returns true.

Definition at line 66 of file AbstractLoadBalancing.cpp.

References _state, _statistics, logDebug, toolbox::loadbalancing::SwitchedOff, and toString().

Here is the call graph for this function:

◆ isInterRankBalancingBad()

bool toolbox::loadbalancing::AbstractLoadBalancing::isInterRankBalancingBad ( ) const
protected

Is the balancing between the ranks ok.

This operation checks if the inter-rank load decomposition does violate the overall load balancing constraints. The global balancing is determined by a cascade of checks:

  • If we have an inconsistent data view, i.e. if the stats are not valid, we have to assume that everything is fine.
  • If we have fewer trees globally than we have ranks, the balancing is by definition poor.
  • If we host more trees than allowed, the balancing by definition is good, since we could not refine further anyway.
  • Otherwise, we look if the max load per rank and the min load per rank differ more than the tolerance.

Definition at line 100 of file AbstractLoadBalancing.cpp.

References _configuration, _costMetrics, _state, _statistics, peano4::parallel::SpacetreeSet::getInstance(), tarch::mpi::Rank::getInstance(), tarch::mpi::Rank::getNumberOfRanks(), and logInfo.

Referenced by toolbox::loadbalancing::strategies::RecursiveBipartition::toString(), toolbox::loadbalancing::strategies::SplitOversizedTree::toString(), toolbox::loadbalancing::strategies::RecursiveBipartition::updateState(), and toolbox::loadbalancing::strategies::SplitOversizedTree::updateState().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isIntraRankBalancingBad()

bool toolbox::loadbalancing::AbstractLoadBalancing::isIntraRankBalancingBad ( ) const
protected

Is the balancing on the rank ok.

Similar to isInterRankBalancingBad(), this operation runs through a series of checks:

  • If there are no trees on the rank, then the result is false. By definition, everything is well-balanced.
  • If there is only one tree, the balancing is by definition bad, as we cannot make a balancing statement.
  • If we host more trees than allowed, the balancing by definition is good, since we could not refine further anyway.
  • Otherwise, we compare the minimum and maximum tree.

Definition at line 128 of file AbstractLoadBalancing.cpp.

References _configuration, _costMetrics, _state, _statistics, assertion, peano4::parallel::SpacetreeSet::getInstance(), and logDebug.

Referenced by toolbox::loadbalancing::strategies::RecursiveBipartition::toString(), toolbox::loadbalancing::strategies::SplitOversizedTree::toString(), toolbox::loadbalancing::strategies::RecursiveBipartition::updateState(), and toolbox::loadbalancing::strategies::SplitOversizedTree::updateState().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setConfigurationAndMetricsNullWithoutDelete()

void toolbox::loadbalancing::AbstractLoadBalancing::setConfigurationAndMetricsNullWithoutDelete ( )

This is only used when you concatenate balancing rules and you want to disable any deletion.

Please do not invoke it unless you know exactly what you are doing.

Definition at line 32 of file AbstractLoadBalancing.cpp.

References _configuration, and _costMetrics.

◆ toString()

std::string toolbox::loadbalancing::AbstractLoadBalancing::toString ( ) const
virtual

Generic string serialisation.

You might want to extend it. Therefore, the routine is labelled as virtual.

Reimplemented in toolbox::loadbalancing::strategies::RecursiveBipartition, and toolbox::loadbalancing::strategies::SplitOversizedTree.

Definition at line 38 of file AbstractLoadBalancing.cpp.

References _blacklist, _costMetrics, _state, _statistics, and toString().

Referenced by enable(), operator<<(), and toolbox::loadbalancing::strategies::SpreadOutHierarchically::updateLoadBalancing().

Here is the call graph for this function:
Here is the caller graph for this function:

Field Documentation

◆ _blacklist

◆ _configuration

Configuration* toolbox::loadbalancing::AbstractLoadBalancing::_configuration
protected

◆ _costMetrics

◆ _log

tarch::logging::Log toolbox::loadbalancing::AbstractLoadBalancing::_log
staticprotected

Definition at line 131 of file AbstractLoadBalancing.h.

◆ _state

State toolbox::loadbalancing::AbstractLoadBalancing::_state
protected

Ensure that you invoke.

   _statistics.notifyOfStateChange(_state)

whenever you change the state. Otherwise, the MPI will have an invalid view of the whole world.

Definition at line 149 of file AbstractLoadBalancing.h.

Referenced by AbstractLoadBalancing(), toolbox::loadbalancing::strategies::SplitOversizedTree::computeNumberOfSplits(), toolbox::loadbalancing::strategies::SplitOversizedTree::doesLocalTreeViolateThreshold(), enable(), toolbox::loadbalancing::strategies::Hardcoded::finishStep(), toolbox::loadbalancing::strategies::RecursiveBipartition::finishStep(), toolbox::loadbalancing::strategies::SplitOversizedTree::finishStep(), toolbox::loadbalancing::strategies::SpreadOut::finishStep(), toolbox::loadbalancing::strategies::SpreadOutHierarchically::finishStep(), toolbox::loadbalancing::strategies::SpreadOutOnceGridStagnates::finishStep(), fitsIntoMemory(), toolbox::loadbalancing::strategies::SpreadOutHierarchically::getAction(), toolbox::loadbalancing::strategies::SpreadOutHierarchically::getNumberOfSplitsOnLocalRank(), toolbox::loadbalancing::strategies::SpreadOut::getNumberOfTreesPerRank(), toolbox::loadbalancing::strategies::SpreadOutOnceGridStagnates::getNumberOfTreesPerRank(), toolbox::loadbalancing::strategies::SplitOversizedTree::getTargetTreeCost(), hasStagnated(), toolbox::loadbalancing::strategies::cascade::Cascade< toolbox::loadbalancing::strategies::SpreadOut, toolbox::loadbalancing::strategies::RecursiveBipartition >::hasStagnated(), isEnabled(), isInterRankBalancingBad(), isIntraRankBalancingBad(), toolbox::loadbalancing::strategies::NoLoadBalancing::NoLoadBalancing(), toolbox::loadbalancing::strategies::RecursiveBipartition::RecursiveBipartition(), toolbox::loadbalancing::strategies::SplitOversizedTree::SplitOversizedTree(), toolbox::loadbalancing::strategies::SpreadOut::SpreadOut(), toolbox::loadbalancing::strategies::SpreadOutHierarchically::SpreadOutHierarchically(), toolbox::loadbalancing::strategies::SpreadOutOnceGridStagnates::SpreadOutOnceGridStagnates(), toString(), toolbox::loadbalancing::strategies::RecursiveBipartition::toString(), toolbox::loadbalancing::strategies::SplitOversizedTree::toString(), toolbox::loadbalancing::strategies::RecursiveBipartition::triggerSplit(), toolbox::loadbalancing::strategies::SplitOversizedTree::triggerSplit(), toolbox::loadbalancing::strategies::SpreadOut::triggerSplit(), toolbox::loadbalancing::strategies::SpreadOutHierarchically::triggerSplit(), toolbox::loadbalancing::strategies::RecursiveBipartition::updateLoadBalancing(), toolbox::loadbalancing::strategies::SplitOversizedTree::updateLoadBalancing(), toolbox::loadbalancing::strategies::SpreadOut::updateLoadBalancing(), toolbox::loadbalancing::strategies::SpreadOutHierarchically::updateLoadBalancing(), toolbox::loadbalancing::strategies::SpreadOutOnceGridStagnates::updateLoadBalancing(), toolbox::loadbalancing::strategies::RecursiveBipartition::updateState(), toolbox::loadbalancing::strategies::SplitOversizedTree::updateState(), and toolbox::loadbalancing::strategies::SpreadOutHierarchically::updateState().

◆ _statistics

Statistics toolbox::loadbalancing::AbstractLoadBalancing::_statistics
protected

Definition at line 135 of file AbstractLoadBalancing.h.

Referenced by AbstractLoadBalancing(), areRanksUnemployed(), toolbox::loadbalancing::strategies::SplitOversizedTree::doesLocalTreeViolateThreshold(), enable(), finishSimulation(), toolbox::loadbalancing::strategies::NoLoadBalancing::finishStep(), toolbox::loadbalancing::strategies::RecursiveBipartition::finishStep(), toolbox::loadbalancing::strategies::SplitOversizedTree::finishStep(), toolbox::loadbalancing::strategies::SpreadOut::finishStep(), toolbox::loadbalancing::strategies::SpreadOutHierarchically::finishStep(), toolbox::loadbalancing::strategies::SpreadOutOnceGridStagnates::finishStep(), toolbox::loadbalancing::strategies::SpreadOutHierarchically::getAction(), getGlobalNumberOfTrees(), toolbox::loadbalancing::strategies::SpreadOut::getNumberOfTreesPerRank(), toolbox::loadbalancing::strategies::SpreadOutOnceGridStagnates::getNumberOfTreesPerRank(), hasSplitRecently(), isEnabled(), isInterRankBalancingBad(), isIntraRankBalancingBad(), toolbox::loadbalancing::strategies::NoLoadBalancing::NoLoadBalancing(), toolbox::loadbalancing::strategies::RecursiveBipartition::RecursiveBipartition(), toolbox::loadbalancing::strategies::SplitOversizedTree::SplitOversizedTree(), toolbox::loadbalancing::strategies::SpreadOut::SpreadOut(), toolbox::loadbalancing::strategies::SpreadOutHierarchically::SpreadOutHierarchically(), toolbox::loadbalancing::strategies::SpreadOutOnceGridStagnates::SpreadOutOnceGridStagnates(), toString(), toolbox::loadbalancing::strategies::RecursiveBipartition::toString(), toolbox::loadbalancing::strategies::SplitOversizedTree::toString(), toolbox::loadbalancing::strategies::RecursiveBipartition::triggerSplit(), toolbox::loadbalancing::strategies::SplitOversizedTree::triggerSplit(), toolbox::loadbalancing::strategies::SpreadOut::triggerSplit(), toolbox::loadbalancing::strategies::SpreadOutHierarchically::triggerSplit(), toolbox::loadbalancing::strategies::SpreadOutOnceGridStagnates::triggerSplit(), toolbox::loadbalancing::strategies::SpreadOut::updateLoadBalancing(), toolbox::loadbalancing::strategies::SpreadOutHierarchically::updateLoadBalancing(), toolbox::loadbalancing::strategies::SpreadOutOnceGridStagnates::updateLoadBalancing(), and toolbox::loadbalancing::strategies::SpreadOutHierarchically::updateState().

◆ NoHeaviestTreeAvailable

int toolbox::loadbalancing::AbstractLoadBalancing::NoHeaviestTreeAvailable = -1
staticconstexpr

Is used by tree identification and either indicates that there are no trees at all or means that the heaviest tree is on the blacklist.

See implementation remarks in class description.

Definition at line 31 of file AbstractLoadBalancing.h.

Referenced by getIdOfHeaviestLocalSpacetree(), getIdOfHeaviestLocalSpacetree(), getWeightOfHeaviestLocalSpacetree(), toolbox::loadbalancing::strategies::RecursiveBipartition::updateLoadBalancing(), toolbox::loadbalancing::strategies::SplitOversizedTree::updateLoadBalancing(), and toolbox::loadbalancing::strategies::SpreadOutHierarchically::updateLoadBalancing().


The documentation for this class was generated from the following files: