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