forked from N-BodyShop/changa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHierarchOrbLB.C
81 lines (65 loc) · 2.12 KB
/
HierarchOrbLB.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/**
* Author: [email protected] (Harshitha Menon)
* Hierarchical load balancer for ChaNGa. It has 3 level of tree where the top
* level applies either RefineLB or uses VectorStrategy. At level 1, it applies
* OrbLB_notopo.
*/
#include "HierarchOrbLB.h"
#include "LBDBManager.h"
#include "GreedyLB.h"
#include "RefineLB.h"
#include "Orb3dLB_notopo.h"
#define DEBUGF(x) // CmiPrintf x;
CreateLBFunc_Def(HierarchOrbLB, "Hybrid load balancer")
CkpvExtern(int, _lb_obj_index);
extern BaseLB* AllocateOrb3dLB_notopo();
void HierarchOrbLB::init() {
lbname = (char *)"HierarchOrbLB";
thisProxy = CProxy_HierarchOrbLB(thisgroup);
}
HierarchOrbLB::HierarchOrbLB(const CkLBOptions &opt): CBase_HierarchOrbLB(opt) {
#if CMK_LBDB_ON
init();
// decide which load balancer to call
// IMPORTANT: currently, the greedy LB must allow objects that
// are not from existing processors.
refinelb = (CentralLB *)AllocateRefineLB();
orblb = (CentralLB *)AllocateOrb3dLB_notopo();
initTree();
#endif
}
HierarchOrbLB::~HierarchOrbLB() {
delete orblb;
delete refinelb;
}
void HierarchOrbLB::GetObjsToMigrate(int toPe, double load, LDStats *stats,
int atlevel, CkVec<LDCommData>& comms, CkVec<LDObjData>& objs) {
for (int obj=stats->n_objs-1; obj>=0; obj--) {
LDObjData &objData = stats->objData[obj];
if (!objData.migratable) continue;
TaggedVector3D* udata = (TaggedVector3D *)objData.getUserData(CkpvAccess(_lb_obj_index));
if (udata->myNumParticles <= 0) continue;
if (objData.wallTime <= load) {
if (_lb_args.debug()>2)
CkPrintf("[%d] send obj: %d to PE %d (load: %f).\n", CkMyPe(), obj, toPe, objData.wallTime);
objs.push_back(objData);
// send comm data
collectCommData(obj, comms, atlevel);
load -= objData.wallTime;
CreateMigrationOutObjs(atlevel, stats, obj);
stats->removeObject(obj);
if (load <= 0.0) break;
}
}
}
void HierarchOrbLB::work(LDStats* stats) {
#if CMK_LBDB_ON
LevelData *lData = levelData[currentLevel];
if (currentLevel == 1) {
orblb->work(stats);
}
else
refinelb->work(stats);
#endif
}
#include "HierarchOrbLB.def.h"