OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
DLB.hpp
1/*
2 * DLB.hpp
3 *
4 * Created on: Nov 20, 2015
5 * Author: Antonio Leo
6 */
7
8#ifndef SRC_DECOMPOSITION_DLB_HPP_
9#define SRC_DECOMPOSITION_DLB_HPP_
10
12struct Times
13{
16
19
21 double timeStep = 0.1;
22
24
27
30};
31
53class DLB
54{
55public:
56
59 {
60 SAR_HEURISTIC, UNBALANCE_THRLD
61 };
62
65 {
66 THRLD_LOW = 5, THRLD_MEDIUM = 7, THRLD_HIGH = 10
67 };
68
69private:
70
73
76
78 float w_n = -1;
79
81 float c_c = 5;
82
84 size_t n_ts = 1;
85
87 float i_time = 0;
88
91
93 Heuristic heuristic = UNBALANCE_THRLD;
94
96 float unbalance = -1;
97
99 ThresholdLevel thl = THRLD_MEDIUM;
100
106 inline bool SAR()
107 {
109 float t_max = t, t_avg = t;
110
111 // Exchange time informations through processors
112 v_cl.max(t_max);
113 v_cl.sum(t_avg);
114 v_cl.execute();
115
116 t_avg /= v_cl.getProcessingUnits();
117
118 // add idle time to vector
119 i_time += t_max - t_avg;
120
121 // Compute Wn
122 float nw_n = (i_time + c_c) / n_ts;
123
124 if (w_n == -1)
125 w_n = nw_n;
126
127 if (nw_n > w_n)
128 {
129 i_time = 0;
130 n_ts = 1;
131 w_n = nw_n;
132 return true;
133 }
134 else
135 {
136 ++n_ts;
137 w_n = nw_n;
138 return false;
139 }
140 }
141
147 {
148 if (unbalance == -1)
149 {
150 std::cerr << "Error: Un-balance value must be set before checking DLB.";
151 return false;
152 }
153
154 if (unbalance > thl)
155 {
156 return true;
157 }
158
159 return false;
160 }
161
162public:
163
169 v_cl(v_cl)
170 {
171 }
172
178 {
179 heuristic = h;
180 }
181
191 {
192 return heuristic;
193 }
194
201 {
202 if (heuristic == SAR_HEURISTIC)
203 {
204 return SAR();
205 }
206 else
207 {
208 return unbalanceThreshold();
209 }
210 }
211
217 {
219 }
220
227 {
229 }
230
235 void setSimulationEndTime(size_t t)
236 {
238 }
239
246 {
248 }
249
254 {
256 }
257
262 void startIteration(size_t t)
263 {
265 }
266
273 {
274 timeInfo.iterationEndTime = clock();
275 }
276
281 void endIteration(size_t t)
282 {
284 }
285
290 void setTimeStep(double t)
291 {
292 timeInfo.timeStep = t;
293 }
294
299 void setComputationCost(size_t computation)
300 {
301 c_c = computation;
302 }
303
310 {
311 return n_ts;
312 }
313
318 void setUnbalance(float u)
319 {
320 unbalance = u;
321 }
322
328 {
329 thl = t;
330 }
331
332};
333
334#endif /* SRC_DECOMPOSITION_DLB_HPP_ */
Definition DLB.hpp:54
void endIteration(size_t t)
Set the end time when the previous rebalance has been performed.
Definition DLB.hpp:281
void setSimulationStartTime(size_t t)
Set start time for the simulation.
Definition DLB.hpp:216
DLB(Vcluster<> &v_cl)
Constructor for DLB class.
Definition DLB.hpp:168
bool SAR()
Function that gather times informations and decides if a rebalance is needed it uses the SAR heuristi...
Definition DLB.hpp:106
void setHeurisitc(Heuristic h)
Set the heuristic to use (default: un-balance threshold)
Definition DLB.hpp:177
void setThresholdLevel(ThresholdLevel t)
threshold of umbalance to start a rebalance
Definition DLB.hpp:327
float w_n
Wn for SAR heuristic.
Definition DLB.hpp:78
size_t getSimulationEndTime()
Get end time for the simulation.
Definition DLB.hpp:245
Heuristic heuristic
Type of the heuristic to use.
Definition DLB.hpp:93
ThresholdLevel
Level of un-balance needed to trigger the re-balance.
Definition DLB.hpp:65
bool unbalanceThreshold()
Check if the un-balance has exceeded the threshold.
Definition DLB.hpp:146
ThresholdLevel thl
Threshold value.
Definition DLB.hpp:99
float i_time
Idle time accumulated so far, needed for SAR heuristic.
Definition DLB.hpp:87
Heuristic
Type of DLB heuristics.
Definition DLB.hpp:59
Vcluster & v_cl
Runtime virtual cluster machine.
Definition DLB.hpp:72
bool rebalanceNeeded()
check if a re-balance is needed using the selected heuristic
Definition DLB.hpp:200
void startIteration(size_t t)
Set start time for the single iteration.
Definition DLB.hpp:262
Times timeInfo
Structure that will contain all the timings.
Definition DLB.hpp:75
void setUnbalance(float u)
Set un-balance value.
Definition DLB.hpp:318
size_t getNTimeStepSinceDLB()
Get how many time-steps have passed since the last re-balancing.
Definition DLB.hpp:309
void startIteration()
Set start time for the single iteration.
Definition DLB.hpp:253
float c_c
Computation cost for SAR heuristic.
Definition DLB.hpp:81
openfpm::vector< long > times
Vector to collect all timings.
Definition DLB.hpp:90
void setTimeStep(double t)
Set delta time step for one iteration (Computation time)
Definition DLB.hpp:290
void setComputationCost(size_t computation)
Set time step for the single iteration.
Definition DLB.hpp:299
float unbalance
Un-balance value.
Definition DLB.hpp:96
size_t n_ts
Number of time-steps since the previous DLB.
Definition DLB.hpp:84
Heuristic getHeurisitc()
Get the heuristic.
Definition DLB.hpp:190
void setSimulationEndTime(size_t t)
Set end time for the simulation.
Definition DLB.hpp:235
void endIteration()
Set end time for the single iteration.
Definition DLB.hpp:272
size_t getSimulationStartTime()
Get start time for the simulation.
Definition DLB.hpp:226
void execute()
Execute all the requests.
void sum(T &num)
Sum the numbers across all processors and get the result.
size_t getProcessingUnits()
Get the total number of processors.
void max(T &num)
Get the maximum number across all processors (or reduction with infinity norm)
Implementation of VCluster class.
Definition VCluster.hpp:59
Implementation of 1-D std::vector like structure.
Time structure for statistical purposes.
Definition DLB.hpp:13
size_t simulationStartTime
starting time of the simulation (0)
Definition DLB.hpp:15
size_t simulationEndTime
End iteration of the simulation.
Definition DLB.hpp:18
size_t iterationStartTime
Interval between teo rebalance.
Definition DLB.hpp:26
size_t iterationEndTime
End time.
Definition DLB.hpp:29
double timeStep
integration time
Definition DLB.hpp:21