00001
00015
00016 #include "TempAwareGreedyLB.h"
00017 #include "ckgraph.h"
00018 #include <algorithm>
00019
00020 extern int quietModeRequested;
00021
00022 CreateLBFunc_Def(TempAwareGreedyLB, "always assign the heaviest obj onto lightest loaded processor.")
00023
00024 TempAwareGreedyLB::TempAwareGreedyLB(const CkLBOptions &opt): CBase_TempAwareGreedyLB(opt)
00025 {
00026 lbname = "TempAwareGreedyLB";
00027 if (CkMyPe()==0 && !quietModeRequested)
00028 CkPrintf("CharmLB> TempAwareGreedyLB created.\n");
00029 }
00030
00031 bool TempAwareGreedyLB::QueryBalanceNow(int _step)
00032 {
00033
00034 return true;
00035 }
00036
00037 class TempAwareGreedyLB::ProcLoadGreater {
00038 public:
00039 bool operator()(ProcInfo p1, ProcInfo p2) {
00040 return (p1.getTotalLoad() > p2.getTotalLoad());
00041 }
00042 };
00043
00044 class TempAwareGreedyLB::ObjLoadGreater {
00045 public:
00046 bool operator()(Vertex v1, Vertex v2) {
00047 return (v1.getVertexLoad() > v2.getVertexLoad());
00048 }
00049 };
00050
00051 void TempAwareGreedyLB::work(LDStats* stats)
00052 {
00053 CkPrintf("----------------- in TempAwareGreedyLB -----------\n");
00055 ProcArray *parr = new ProcArray(stats);
00056 ObjGraph *ogr = new ObjGraph(stats);
00057
00059 parr->resetTotalLoad();
00060
00061 if (_lb_args.debug()>1)
00062 CkPrintf("[%d] In TempAwareGreedyLB strategy\n",CkMyPe());
00063
00064 int vert;
00065
00066
00067 std::sort(ogr->vertices.begin(), ogr->vertices.end(), TempAwareGreedyLB::ObjLoadGreater());
00068
00069 std::make_heap(parr->procs.begin(), parr->procs.end(), TempAwareGreedyLB::ProcLoadGreater());
00070
00071 for(vert = 0; vert < ogr->vertices.size(); vert++) {
00072
00073 ProcInfo p = parr->procs.front();
00074 std::pop_heap(parr->procs.begin(), parr->procs.end(), TempAwareGreedyLB::ProcLoadGreater());
00075 parr->procs.pop_back();
00076
00077
00078
00079 p.totalLoad() += ogr->vertices[vert].getVertexLoad();
00080 ogr->vertices[vert].setNewPe(p.getProcId());
00081
00082
00083 parr->procs.push_back(p);
00084 std::push_heap(parr->procs.begin(), parr->procs.end(), TempAwareGreedyLB::ProcLoadGreater());
00085 }
00086
00088 ogr->convertDecisions(stats);
00089 }
00090
00091 #include "TempAwareGreedyLB.def.h"
00092