Fix hash table usage for XLC
[charm.git] / src / ck-ldb / NodeLevelLB.C
blob3bf8d3d2060072fdcef7396446eb43f0259daf33
1 /**
2  * Author Harshitha Menon (gplkrsh2@illinois.edu)
3  * Node level load balancer which first performs load balancing across nodes and
4  * then within a node.
5  * Eg Usage: +balancer NodeLevelLB:MetisLB,RefineLB where first MetisLB will be
6  * applied across nodes followed by RefineLB within a node
7 */
8 #include "NodeLevelLB.h"
10 extern LBAllocFn getLBAllocFn(const char *lbname);
12 CreateLBFunc_Def(NodeLevelLB, "Node level load balancer")
14 #if defined(_WIN32)
15   /* strtok is thread safe in Windows */
16 #define strtok_r(x,y,z) strtok(x,y)
17 #endif
19 NodeLevelLB::NodeLevelLB(const CkLBOptions &opt): CBase_NodeLevelLB(opt) {
20   lbname = "NodeLevelLB";
21   const char *lbs = theLbdb->loadbalancer(opt.getSeqNo());
22   if (CkMyPe() == 0)
23     CkPrintf("[%d] NodeLevelLB created with %s\n",CkMyPe(), lbs);
25   char *lbcopy = strdup(lbs);
26   char *p = strchr(lbcopy, ':');
27   char *ptr = NULL;
28   char *lbname;
29   if (p==NULL) {
30     CmiAbort("LB> Nodelevel load balancer not specified\n");
31   }
32   lbname = strtok_r(p+1, ",", &ptr);
33   while (lbname) {
34     LBAllocFn fn = getLBAllocFn(lbname);
35     if (fn == NULL) {
36       CkPrintf("LB> Invalid load balancer: %s.\n", lbname);
37       CmiAbort("");
38     }
39     BaseLB *alb = fn();
40     clbs.push_back((CentralLB*)alb);
41     lbname = strtok_r(NULL, ",", &ptr);
42   }
44   // HybridBaseLB constructs a default tree
45   if (tree) {
46     delete tree;
47   }
49   // Construct a tree with three levels where the lowest level is at the node
50   // level
51   tree = new ThreeLevelTree(CmiMyNodeSize());
52   num_levels = tree->numLevels();
53   initTree();
56 void NodeLevelLB::work(LDStats* stats) {
57   if (currentLevel > 2) {
58     CkAbort("NodeLevelLB> Maximum levels can only be 3\n");
59   }
61   CentralLB* clb;
62   int idx_lb = num_levels - currentLevel - 1;
63   if (clbs.length() > idx_lb) {
64     clb = clbs[idx_lb];
65   } else {
66     clb = clbs[clbs.length() - 1];
67   }
68   clb->work(stats);
70 #include "NodeLevelLB.def.h"