Cleanup #48: Move SdagConstruct::numberNodes into each subclass
[charm.git] / src / ck-ldb / ComboCentLB.C
blob342a8da4fbf12996158020732583e6c33f96686e
1 /**
2  * \addtogroup CkLdb
3 */
4 /*@{*/
6 /*
7 Status:
8   * support nonmigratable attrib
9   * does not support processor avail bitvector
12 #include "ComboCentLB.h"
14 extern LBAllocFn getLBAllocFn(const char *lbname);
16 CreateLBFunc_Def(ComboCentLB, "Allow multiple strategies to work serially")
18 ComboCentLB::ComboCentLB(const CkLBOptions &opt): CBase_ComboCentLB(opt)
20   lbname = "ComboCentLB";
21   const char *lbs = theLbdb->loadbalancer(opt.getSeqNo());
22   if (CkMyPe() == 0)
23     CkPrintf("[%d] ComboCentLB created with %s\n",CkMyPe(), lbs);
24   
25   char *lbcopy = strdup(lbs);
26   char *p = strchr(lbcopy, ':');
27   if (p==NULL) return;
28   p = strtok(p+1, ",");
29   while (p) {
30     LBAllocFn fn = getLBAllocFn(p);
31     if (fn == NULL) {
32       CkPrintf("LB> Invalid load balancer: %s.\n", p);
33       CmiAbort("");
34     }
35     BaseLB *alb = fn();
36     clbs.push_back((CentralLB*)alb);
37     p = strtok(NULL, ",");
38   }
41 void ComboCentLB::work(LDStats* stats)
43   int nlbs = clbs.length();
44   int n_objs = stats->n_objs;
45   int *from_orig = new int[n_objs];
46   int obj;
48   // stats->from_proc should remain untouched at end
49   for (obj=0; obj<n_objs; obj++) from_orig[obj] = stats->from_proc[obj];
51   for (int i=0; i<nlbs; i++) {
52     clbs[i]->work(stats);
53     if (i!=nlbs-1) {
54       for (obj=0; obj<stats->n_objs; obj++) 
55         stats->from_proc[obj] = stats->to_proc[obj];
56     }
57   }
59   for (obj=0; obj<n_objs; obj++) stats->from_proc[obj] = from_orig[obj];
61   delete [] from_orig;
64 #include "ComboCentLB.def.h"
67 /*@}*/