00001
00008 #include "NodeLevelLB.h"
00009
00010 extern LBAllocFn getLBAllocFn(const char *lbname);
00011
00012 extern int quietModeRequested;
00013
00014 CreateLBFunc_Def(NodeLevelLB, "Node level load balancer")
00015
00016 #if defined(_WIN32)
00017
00018 #define strtok_r(x,y,z) strtok(x,y)
00019 #endif
00020
00021 NodeLevelLB::NodeLevelLB(const CkLBOptions &opt): CBase_NodeLevelLB(opt) {
00022 lbname = "NodeLevelLB";
00023 const char *lbs = theLbdb->loadbalancer(opt.getSeqNo());
00024 if (CkMyPe() == 0 && !quietModeRequested)
00025 CkPrintf("CharmLB> NodeLevelLB created with %s.\n", lbs);
00026
00027 char *lbcopy = strdup(lbs);
00028 char *p = strchr(lbcopy, ':');
00029 char *ptr = NULL;
00030 char *lbname;
00031 if (p==NULL) {
00032 CmiAbort("LB> Nodelevel load balancer not specified\n");
00033 }
00034 lbname = strtok_r(p+1, ",", &ptr);
00035 while (lbname) {
00036 LBAllocFn fn = getLBAllocFn(lbname);
00037 if (fn == NULL) {
00038 CkPrintf("LB> Invalid load balancer: %s.\n", lbname);
00039 CmiAbort("");
00040 }
00041 BaseLB *alb = fn();
00042 clbs.push_back((CentralLB*)alb);
00043 lbname = strtok_r(NULL, ",", &ptr);
00044 }
00045
00046
00047 if (tree) {
00048 delete tree;
00049 }
00050
00051
00052
00053 tree = new ThreeLevelTree(CmiMyNodeSize());
00054 num_levels = tree->numLevels();
00055 initTree();
00056 }
00057
00058 void NodeLevelLB::work(LDStats* stats) {
00059 if (currentLevel > 2) {
00060 CkAbort("NodeLevelLB> Maximum levels can only be 3\n");
00061 }
00062
00063 CentralLB* clb;
00064 int idx_lb = num_levels - currentLevel - 1;
00065 if (clbs.length() > idx_lb) {
00066 clb = clbs[idx_lb];
00067 } else {
00068 clb = clbs[clbs.length() - 1];
00069 }
00070 clb->work(stats);
00071 }
00072 #include "NodeLevelLB.def.h"