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

Abstract cost metric. More...

#include <CostMetrics.h>

Inheritance diagram for toolbox::loadbalancing::CostMetrics:
Collaboration diagram for toolbox::loadbalancing::CostMetrics:

Data Structures

struct  ReductionBuffer
 It is totally annoying, but it seems that MPI's maxloc and reduction are broken in some MPI implementations. More...
 

Public Member Functions

 CostMetrics ()
 
virtual ~CostMetrics ()=default
 
virtual std::string toString () const =0
 Feel free to invoke the variant below if you want.
 
std::string toString (const std::string &metricName) const
 
virtual void updateGlobalView ()
 Please overwrite in subclass and set the value of _localRankWeight.
 
virtual double getCostOfLocalTree (int spacetreeNumber) const =0
 Query cost of one tree.
 
virtual double getCostOfLocalRank () const
 Wrapper around getCostOfLocalTree().
 
virtual double getGlobalCost () const
 
virtual int getLightestRank () const
 
virtual double getMinimumOfMaximumRankWeights () const
 

Protected Attributes

double _localRankWeight
 Weight of local rank.
 
double _globalWeight
 
ReductionBuffer _lightestRank
 
double _minimumOfMaximumOfRankWeights
 

Static Private Attributes

static tarch::logging::Log _log
 

Detailed Description

Abstract cost metric.

Base class for any cost metric that you want to use in combination with the generic load balancing strategies. To realise your own cost metric, you have to complete two steps:

  1. The most important quantity of this class is _localRankWeight which is not set by this abstract base class. I recommend to redefine the routine updateGlobalView(), to set this attribute there, and then to call CostMetric's updateGlobalView() to finish all global data exchange.
  2. Next, you have to implement getCostOfLocalTree().

updateGlobalView() all-reduces the metrics over all ranks, i.e. all ranks hold the same global weight, lightest rank and minimum of rank weights afterwards. This mirrors toolbox::loadbalancing::Statistics and peano4::parallel::SpacetreeSet::getGridStatistics(). Only _localRankWeight and getCostOfLocalRank() are rank-local.

Definition at line 37 of file CostMetrics.h.

Constructor & Destructor Documentation

◆ CostMetrics()

toolbox::loadbalancing::CostMetrics::CostMetrics ( )

◆ ~CostMetrics()

virtual toolbox::loadbalancing::CostMetrics::~CostMetrics ( )
virtualdefault

Member Function Documentation

◆ getCostOfLocalRank()

virtual double toolbox::loadbalancing::CostMetrics::getCostOfLocalRank ( ) const
virtual

Wrapper around getCostOfLocalTree().

Loops over all local trees and returns the sum.

◆ getCostOfLocalTree()

virtual double toolbox::loadbalancing::CostMetrics::getCostOfLocalTree ( int  spacetreeNumber) const
pure virtual

Query cost of one tree.

This routine is only called by the rank which owns the tree spacetreeNumber. That is, you don't need global knowledge of the tree weight distribution.

The routine is used in multiple places, but the most important one is toolbox::loadbalancing::AbstractLoadBalancing::getIdOfHeaviestLocalSpacetree(), which analyses the whole tree cost distribution on a rank.

Implemented in toolbox::loadbalancing::metrics::CellCount, and toolbox::loadbalancing::metrics::CustomCellWeight.

◆ getGlobalCost()

virtual double toolbox::loadbalancing::CostMetrics::getGlobalCost ( ) const
virtual

◆ getLightestRank()

virtual int toolbox::loadbalancing::CostMetrics::getLightestRank ( ) const
virtual

◆ getMinimumOfMaximumRankWeights()

virtual double toolbox::loadbalancing::CostMetrics::getMinimumOfMaximumRankWeights ( ) const
virtual

◆ toString() [1/2]

virtual std::string toolbox::loadbalancing::CostMetrics::toString ( ) const
pure virtual

Feel free to invoke the variant below if you want.

Or add additional info.

Implemented in toolbox::loadbalancing::metrics::CellCount, and toolbox::loadbalancing::metrics::CustomCellWeight.

◆ toString() [2/2]

std::string toolbox::loadbalancing::CostMetrics::toString ( const std::string &  metricName) const

◆ updateGlobalView()

virtual void toolbox::loadbalancing::CostMetrics::updateGlobalView ( )
virtual

Please overwrite in subclass and set the value of _localRankWeight.

Afterwards, call this superclass routine

The superclass routine all-reduces the global weight, the lightest rank and the minimum of the rank weights over all ranks through tarch::mpi::Rank::allReduce(). The reduction is blocking, i.e. all ranks hold the same values once the routine has terminated. The routine hence has to be called by all ranks at the same time, and only by one thread per rank.

Reimplemented in toolbox::loadbalancing::metrics::CellCount, and toolbox::loadbalancing::metrics::CustomCellWeight.

Field Documentation

◆ _globalWeight

double toolbox::loadbalancing::CostMetrics::_globalWeight
protected

Definition at line 109 of file CostMetrics.h.

◆ _lightestRank

ReductionBuffer toolbox::loadbalancing::CostMetrics::_lightestRank
protected

Definition at line 110 of file CostMetrics.h.

◆ _localRankWeight

double toolbox::loadbalancing::CostMetrics::_localRankWeight
protected

Weight of local rank.

Rank-local.

Weight of the whole rank. This quantity is the key quantity whenever we actually ask the metrics for information, as it feeds into the total weight, but also helps us to identify underbooked ranks.

Definition at line 107 of file CostMetrics.h.

◆ _log

tarch::logging::Log toolbox::loadbalancing::CostMetrics::_log
staticprivate

Definition at line 114 of file CostMetrics.h.

◆ _minimumOfMaximumOfRankWeights

double toolbox::loadbalancing::CostMetrics::_minimumOfMaximumOfRankWeights
protected

Definition at line 111 of file CostMetrics.h.


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