00001
00005
00006 #include "elements.h"
00007 #include "ckheap.h"
00008 #include "RefineLB.h"
00009
00010 extern int quietModeRequested;
00011
00012 CreateLBFunc_Def(RefineLB, "Move objects away from overloaded processor to reach average")
00013
00014 RefineLB::RefineLB(const CkLBOptions &opt): CBase_RefineLB(opt)
00015 {
00016 lbname = (char *)"RefineLB";
00017 if (CkMyPe() == 0 && !quietModeRequested)
00018 CkPrintf("CharmLB> RefineLB created.\n");
00019 }
00020
00021 void RefineLB::work(LDStats* stats)
00022 {
00023 int obj;
00024 int n_pes = stats->nprocs();
00025
00026
00027
00028
00029
00030
00031 int* from_procs = Refiner::AllocProcs(n_pes, stats);
00032 for(obj=0;obj<stats->n_objs;obj++) {
00033 int pe = stats->from_proc[obj];
00034 from_procs[obj] = pe;
00035 }
00036
00037
00038 int* to_procs = Refiner::AllocProcs(n_pes, stats);
00039
00040 Refiner refiner(1.05);
00041
00042 refiner.Refine(n_pes, stats, from_procs, to_procs);
00043
00044
00045 for(obj=0;obj<stats->n_objs;obj++) {
00046 int pe = stats->from_proc[obj];
00047 if (to_procs[obj] != pe) {
00048 if (_lb_args.debug()>=2) {
00049 CkPrintf("[%d] Obj %d migrating from %d to %d\n",
00050 CkMyPe(),obj,pe,to_procs[obj]);
00051 }
00052 stats->to_proc[obj] = to_procs[obj];
00053 }
00054 }
00055
00056 if (_lb_args.metaLbOn()) {
00057 stats->is_prev_lb_refine = 1;
00058 stats->after_lb_avg = refiner.computeAverageLoad();
00059 stats->after_lb_max = refiner.computeMax();
00060
00061 if (_lb_args.debug() > 0)
00062 CkPrintf("RefineLB> Max load %lf Avg load %lf\n", stats->after_lb_max,
00063 stats->after_lb_avg);
00064 }
00065
00066
00067 Refiner::FreeProcs(from_procs);
00068 Refiner::FreeProcs(to_procs);
00069 }
00070
00071 #include "RefineLB.def.h"
00072