00001 00005 00006 /* 00007 Status: 00008 * support nonmigratable attrib 00009 * support processor avail bitvector 00010 */ 00011 00012 #include "RandCentLB.h" 00013 00014 extern int quietModeRequested; 00015 00016 CreateLBFunc_Def(RandCentLB, "Assign objects to processors randomly") 00017 00018 RandCentLB::RandCentLB(const CkLBOptions &opt): CBase_RandCentLB(opt) 00019 { 00020 lbname = "RandCentLB"; 00021 if (CkMyPe() == 0 && !quietModeRequested) 00022 CkPrintf("CharmLB> RandCentLB created.\n"); 00023 } 00024 00025 bool RandCentLB::QueryBalanceNow(int _step) 00026 { 00027 return true; 00028 } 00029 00030 inline int chooseProc(int count) 00031 { 00032 return (int)(CrnDrand()*count); 00033 } 00034 00035 void RandCentLB::work(LDStats* stats) 00036 { 00037 if (_lb_args.debug()) CkPrintf("Calling RandCentLB strategy\n",CkMyPe()); 00038 00039 int proc, n_pes = stats->nprocs(); 00040 00041 for (proc=0; proc<n_pes; proc++) { 00042 if (stats->procs[proc].available) break; 00043 } 00044 if (proc == n_pes) CmiAbort("RandCentLB> no available processor!"); 00045 00046 int nmigrated = 0; 00047 for(int obj=0; obj < stats->n_objs; obj++) { 00048 LDObjData &odata = stats->objData[obj]; 00049 if (odata.migratable) { 00050 int dest = chooseProc(n_pes); 00051 while (!stats->procs[dest].available) dest = chooseProc(n_pes); 00052 if (dest != stats->from_proc[obj]) { 00053 if (_lb_args.debug() >= 2) 00054 CkPrintf("[%d] Obj %d migrating from %d to %d\n", CkMyPe(),obj,stats->from_proc[obj],dest); 00055 nmigrated ++; 00056 stats->to_proc[obj] = dest; 00057 } 00058 } 00059 } 00060 } 00061 00062 #include "RandCentLB.def.h" 00063