2 * Author Harshitha Menon (gplkrsh2@illinois.edu)
3 * Node level load balancer which first performs load balancing across nodes and
5 * Eg Usage: +balancer NodeLevelLB:MetisLB,RefineLB where first MetisLB will be
6 * applied across nodes followed by RefineLB within a node
8 #include "NodeLevelLB.h"
10 extern LBAllocFn getLBAllocFn(const char *lbname);
12 CreateLBFunc_Def(NodeLevelLB, "Node level load balancer")
15 /* strtok is thread safe in Windows */
16 #define strtok_r(x,y,z) strtok(x,y)
19 NodeLevelLB::NodeLevelLB(const CkLBOptions &opt): CBase_NodeLevelLB(opt) {
20 lbname = "NodeLevelLB";
21 const char *lbs = theLbdb->loadbalancer(opt.getSeqNo());
23 CkPrintf("[%d] NodeLevelLB created with %s\n",CkMyPe(), lbs);
25 char *lbcopy = strdup(lbs);
26 char *p = strchr(lbcopy, ':');
30 CmiAbort("LB> Nodelevel load balancer not specified\n");
32 lbname = strtok_r(p+1, ",", &ptr);
34 LBAllocFn fn = getLBAllocFn(lbname);
36 CkPrintf("LB> Invalid load balancer: %s.\n", lbname);
40 clbs.push_back((CentralLB*)alb);
41 lbname = strtok_r(NULL, ",", &ptr);
44 // HybridBaseLB constructs a default tree
49 // Construct a tree with three levels where the lowest level is at the node
51 tree = new ThreeLevelTree(CmiMyNodeSize());
52 num_levels = tree->numLevels();
56 void NodeLevelLB::work(LDStats* stats) {
57 if (currentLevel > 2) {
58 CkAbort("NodeLevelLB> Maximum levels can only be 3\n");
62 int idx_lb = num_levels - currentLevel - 1;
63 if (clbs.length() > idx_lb) {
66 clb = clbs[clbs.length() - 1];
70 #include "NodeLevelLB.def.h"