Peano
Loading...
Searching...
No Matches
Cascade.h
Go to the documentation of this file.
1// This file is part of the Peano project. For conditions of distribution and
2// use, please see the copyright notice at www.peano-framework.org
3#pragma once
4
8
9namespace toolbox {
10 namespace loadbalancing {
11 namespace strategies {
12 namespace cascade {
13 template<typename HostedLoadBalancing0, typename HostedLoadBalancing1>
14 class Cascade;
15 }
16 }
17 }
18}
19
20
30template<typename HostedLoadBalancing0, typename HostedLoadBalancing1>
32 public:
34 Configuration* configuration = new DefaultConfiguration(),
36 ):
37 AbstractLoadBalancing( configuration, costMetrics),
38 _hostedLoadBalancing0(configuration, costMetrics),
39 _hostedLoadBalancing1(configuration, costMetrics),
41 }
42
43
50 virtual ~Cascade() {
51 _hostedLoadBalancing0.setConfigurationAndMetricsNullWithoutDelete();
52 _hostedLoadBalancing1.setConfigurationAndMetricsNullWithoutDelete();
53 }
54
55
61 virtual void finishStep() override {
62 switch (_activeLoadBalancing) {
63 case 0:
64 {
65 _hostedLoadBalancing0.finishStep();
66 if (_hostedLoadBalancing0.hasStagnated()) {
68 logInfo( "finishStep()", "one load balancing scheme has stagnated, to switch to " << _activeLoadBalancing );
69 }
70 }
71 break;
72 case 1:
73 {
74 _hostedLoadBalancing1.finishStep();
75 }
76 break;
77 default:
79 break;
80 }
81 }
82
83
84 virtual bool hasSplitRecently() const override {
85 switch (_activeLoadBalancing) {
86 case 0:
87 return _hostedLoadBalancing0.hasSplitRecently();
88 case 1:
89 return _hostedLoadBalancing1.hasSplitRecently();
90 default:
92 break;
93 }
94 return false;
95 }
96
97
98 virtual int getGlobalNumberOfTrees() const override {
99 switch (_activeLoadBalancing) {
100 case 0:
101 return _hostedLoadBalancing0.getGlobalNumberOfTrees();
102 case 1:
103 return _hostedLoadBalancing1.getGlobalNumberOfTrees();
104 default:
106 break;
107 }
108 return -1;
109 }
110
111
112 virtual bool hasStagnated() const override {
113 return _state == State::SwitchedOff
114 or (
116 and
117 _hostedLoadBalancing1.hasStagnated()
118 );
119 }
120
121
122 virtual void finishSimulation() override {
123 switch (_activeLoadBalancing) {
124 case 0:
125 _hostedLoadBalancing0.finishSimulation();
126 break;
127 case 1:
128 _hostedLoadBalancing1.finishSimulation();
129 break;
130 default:
132 break;
133 }
134 }
135
136
137 virtual void enable(bool value) override {
138 _hostedLoadBalancing0.enable(value);
139 _hostedLoadBalancing1.enable(value);
141 if (_activeLoadBalancing==0) {
142 logInfo( "enable(bool)", "lb0=" << _hostedLoadBalancing0.toString() );
143 }
144 else {
145 logInfo( "enable(bool)", "lb1=" << _hostedLoadBalancing1.toString() );
146 }
147 }
148
149 private:
151
152 HostedLoadBalancing0 _hostedLoadBalancing0;
153 HostedLoadBalancing1 _hostedLoadBalancing1;
154
159};
160
161
162template<typename HostedLoadBalancing0, typename HostedLoadBalancing1>
#define assertion1(expr, param)
#define logInfo(methodName, logMacroMessageStream)
Wrapper macro around tarch::tarch::logging::Log to improve logging.
Definition Log.h:411
Log Device.
Definition Log.h:516
Abstract interface to tweak the behaviour of the recursive subdivision.
Cost metrics based solely on cell counts.
Definition CellCount.h:23
Cascade of load balancing schemes.
Definition Cascade.h:31
virtual void finishStep() override
Inform the active aggregate about finishStep() and then check afterwards if the active load balancing...
Definition Cascade.h:61
int _activeLoadBalancing
Pick the active load balancing.
Definition Cascade.h:158
virtual bool hasStagnated() const override
A load balancing can either be stagnating or be switched off for this predicate to hold.
Definition Cascade.h:112
virtual ~Cascade()
We have piped through any pointers to a configuration and the cost metrics.
Definition Cascade.h:50
virtual int getGlobalNumberOfTrees() const override
Delegate to stats.
Definition Cascade.h:98
virtual void enable(bool value) override
Switch on/off.
Definition Cascade.h:137
Cascade(Configuration *configuration=new DefaultConfiguration(), CostMetrics *costMetrics=new toolbox::loadbalancing::metrics::CellCount())
Definition Cascade.h:33
virtual bool hasSplitRecently() const override
Definition Cascade.h:84
@ SwitchedOff
You usually don't get this state when we query the configuration, i.e.