![]() |
Peano
|
#include <AbstractLoadBalancing.h>
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 |
Definition at line 24 of file AbstractLoadBalancing.h.
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.
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.
|
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.
|
protected |
Definition at line 170 of file AbstractLoadBalancing.cpp.
References tarch::la::equals().
Switch on/off.
Reimplemented in toolbox::loadbalancing::strategies::cascade::Cascade< HostedLoadBalancing0, HostedLoadBalancing1 >, and toolbox::loadbalancing::strategies::NoLoadBalancing.
Definition at line 53 of file AbstractLoadBalancing.cpp.
References _state(), toolbox::loadbalancing::InterRankBalancing, logInfo, toolbox::loadbalancing::SwitchedOff, and toString().
Referenced by toolbox::loadbalancing::strategies::cascade::Cascade< HostedLoadBalancing0, HostedLoadBalancing1 >::enable(), and toolbox::loadbalancing::strategies::NoLoadBalancing::enable().
|
virtual |
Reimplemented in toolbox::loadbalancing::strategies::cascade::Cascade< HostedLoadBalancing0, HostedLoadBalancing1 >, and toolbox::loadbalancing::strategies::Hardcoded.
Definition at line 94 of file AbstractLoadBalancing.cpp.
|
pure virtual |
Finish the step.
No matter what you do here, you have to invoke
_statistics.updateGlobalView(); _blacklist.update();
in this routine.
Implemented in toolbox::loadbalancing::strategies::cascade::Cascade< HostedLoadBalancing0, HostedLoadBalancing1 >, toolbox::loadbalancing::strategies::Hardcoded, toolbox::loadbalancing::strategies::NoLoadBalancing, toolbox::loadbalancing::strategies::RecursiveBipartition, toolbox::loadbalancing::strategies::SplitOversizedTree, toolbox::loadbalancing::strategies::SpreadOut, toolbox::loadbalancing::strategies::SpreadOutHierarchically, and toolbox::loadbalancing::strategies::SpreadOutOnceGridStagnates.
Ensure enough memory is left-over.
Definition at line 82 of file AbstractLoadBalancing.cpp.
References _state(), tarch::getFreeMemory(), tarch::getMemoryUsage(), and tarch::MByte.
|
virtual |
Delegate to stats.
Reimplemented in toolbox::loadbalancing::strategies::cascade::Cascade< HostedLoadBalancing0, HostedLoadBalancing1 >.
Definition at line 77 of file AbstractLoadBalancing.cpp.
|
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.
If two or more trees have the same weight, the routine should randomly return one of them.
tolerance | By default, you get the last heaviest tree. But you can ask for a random tree |
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.
|
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.
|
protected |
Definition at line 176 of file AbstractLoadBalancing.cpp.
References peano4::parallel::SpacetreeSet::getInstance(), and logDebug.
|
virtual |
Reimplemented in toolbox::loadbalancing::strategies::cascade::Cascade< HostedLoadBalancing0, HostedLoadBalancing1 >.
Definition at line 48 of file AbstractLoadBalancing.cpp.
|
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.
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().
|
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:
Definition at line 100 of file AbstractLoadBalancing.cpp.
References _state(), peano4::parallel::SpacetreeSet::getInstance(), tarch::mpi::Rank::getInstance(), tarch::mpi::Rank::getNumberOfRanks(), and logInfo.
|
protected |
Is the balancing on the rank ok.
Similar to isInterRankBalancingBad(), this operation runs through a series of checks:
Definition at line 128 of file AbstractLoadBalancing.cpp.
References _state(), assertion, peano4::parallel::SpacetreeSet::getInstance(), peano4::parallel::SpacetreeSet::getLocalSpacetrees(), and logDebug.
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.
|
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().
|
protected |
Definition at line 133 of file AbstractLoadBalancing.h.
|
protected |
Definition at line 137 of file AbstractLoadBalancing.h.
|
protected |
Definition at line 139 of file AbstractLoadBalancing.h.
|
staticprotected |
Definition at line 131 of file AbstractLoadBalancing.h.
|
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 toolbox::loadbalancing::strategies::Hardcoded::finishStep(), toolbox::loadbalancing::strategies::cascade::Cascade< HostedLoadBalancing0, HostedLoadBalancing1 >::hasStagnated(), 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().
|
protected |
Definition at line 135 of file AbstractLoadBalancing.h.
Referenced by 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().
|
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.