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