00001
00005
00006
00007
00008
00009
00010
00011
00012 #include "ComboCentLB.h"
00013
00014 extern LBAllocFn getLBAllocFn(char *lbname);
00015
00016 CreateLBFunc_Def(ComboCentLB, "Allow multiple strategies to work serially")
00017
00018 ComboCentLB::ComboCentLB(const CkLBOptions &opt): CentralLB(opt)
00019 {
00020 lbname = "ComboCentLB";
00021 const char *lbs = theLbdb->loadbalancer(opt.getSeqNo());
00022 if (CkMyPe() == 0)
00023 CkPrintf("[%d] ComboCentLB created with %s\n",CkMyPe(), lbs);
00024
00025 char *lbcopy = strdup(lbs);
00026 char *p = strchr(lbcopy, ':');
00027 if (p==NULL) return;
00028 p = strtok(p+1, ",");
00029 while (p) {
00030 LBAllocFn fn = getLBAllocFn(p);
00031 if (fn == NULL) {
00032 CkPrintf("LB> Invalid load balancer: %s.\n", p);
00033 CmiAbort("");
00034 }
00035 BaseLB *alb = fn();
00036 clbs.push_back((CentralLB*)alb);
00037 p = strtok(NULL, ",");
00038 }
00039 }
00040
00041 void ComboCentLB::work(LDStats* stats)
00042 {
00043 int nlbs = clbs.length();
00044 int n_objs = stats->n_objs;
00045 int *from_orig = new int[n_objs];
00046 int obj;
00047
00048
00049 for (obj=0; obj<n_objs; obj++) from_orig[obj] = stats->from_proc[obj];
00050
00051 for (int i=0; i<nlbs; i++) {
00052 clbs[i]->work(stats);
00053 if (i!=nlbs-1) {
00054 for (obj=0; obj<stats->n_objs; obj++)
00055 stats->from_proc[obj] = stats->to_proc[obj];
00056 }
00057 }
00058
00059 for (obj=0; obj<n_objs; obj++) stats->from_proc[obj] = from_orig[obj];
00060
00061 delete [] from_orig;
00062 }
00063
00064 #include "ComboCentLB.def.h"
00065
00066