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