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 toolbox::loadbalancing::Undefined.

◆ ~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.

Member Function Documentation

◆ areRanksUnemployed()

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

Definition at line 170 of file AbstractLoadBalancing.cpp.

References tarch::la::equals().

Here is the call graph for this function:

◆ enable()

◆ finishSimulation()

void toolbox::loadbalancing::AbstractLoadBalancing::finishSimulation ( )
virtual

◆ 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 _state(), tarch::getFreeMemory(), tarch::getMemoryUsage(), and tarch::MByte.

Here is the call graph for this function:

◆ getGlobalNumberOfTrees()

int toolbox::loadbalancing::AbstractLoadBalancing::getGlobalNumberOfTrees ( ) const
virtual

◆ 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 peano4::parallel::SpacetreeSet::getGridStatistics(), peano4::parallel::SpacetreeSet::getInstance(), peano4::parallel::SpacetreeSet::getLocalSpacetrees(), peano4::grid::GridStatistics::getNumberOfLocalUnrefinedCells(), and ThreePowerD.

Here is the call 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 peano4::parallel::SpacetreeSet::getGridStatistics(), peano4::parallel::SpacetreeSet::getInstance(), peano4::parallel::SpacetreeSet::getLocalSpacetrees(), peano4::grid::GridStatistics::getNumberOfLocalUnrefinedCells(), tarch::la::greaterEquals(), logInfo, 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 peano4::parallel::SpacetreeSet::getInstance(), and logDebug.

Here is the call graph for this function:

◆ hasSplitRecently()

bool toolbox::loadbalancing::AbstractLoadBalancing::hasSplitRecently ( ) const
virtual

◆ hasStagnated()

bool toolbox::loadbalancing::AbstractLoadBalancing::hasStagnated ( ) const
virtual

A load balancing can either be stagnating or be switched off for this predicate to hold.

Reimplemented in toolbox::loadbalancing::strategies::cascade::Cascade< HostedLoadBalancing0, HostedLoadBalancing1 >.

Definition at line 72 of file AbstractLoadBalancing.cpp.

References _state(), toolbox::loadbalancing::Stagnation, and toolbox::loadbalancing::SwitchedOff.

Here is the call graph for this function:

◆ 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(), 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 _state(), peano4::parallel::SpacetreeSet::getInstance(), tarch::mpi::Rank::getInstance(), tarch::mpi::Rank::getNumberOfRanks(), and logInfo.

Here is the call 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 _state(), assertion, peano4::parallel::SpacetreeSet::getInstance(), peano4::parallel::SpacetreeSet::getLocalSpacetrees(), and logDebug.

Here is the call 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.

◆ 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 _state(), and toString().

Referenced by 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

Blacklist toolbox::loadbalancing::AbstractLoadBalancing::_blacklist
protected

Definition at line 133 of file AbstractLoadBalancing.h.

◆ _configuration

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

Definition at line 137 of file AbstractLoadBalancing.h.

◆ _costMetrics

CostMetrics* toolbox::loadbalancing::AbstractLoadBalancing::_costMetrics
protected

Definition at line 139 of file AbstractLoadBalancing.h.

◆ _log

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

Definition at line 131 of file AbstractLoadBalancing.h.

◆ _state

◆ _statistics

◆ NoHeaviestTreeAvailable

constexpr 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.


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