00001
00013
00014 #include "GraphBFTLB.h"
00015 #include "ckgraph.h"
00016 #include <queue>
00017
00018 extern int quietModeRequested;
00019
00020 CreateLBFunc_Def(GraphBFTLB, "Algorithm which does breadth first traversal for communication aware load balancing")
00021
00022 GraphBFTLB::GraphBFTLB(const CkLBOptions &opt) : CBase_GraphBFTLB(opt) {
00023 lbname = "GraphBFTLB";
00024 if(CkMyPe() == 0 && !quietModeRequested)
00025 CkPrintf("CharmLB> GraphBFTLB created\n");
00026 }
00027
00028 bool GraphBFTLB::QueryBalanceNow(int _step) {
00029 return true;
00030 }
00031
00032 void GraphBFTLB::work(LDStats *stats) {
00034 ProcArray *parr = new ProcArray(stats);
00035 ObjGraph *ogr = new ObjGraph(stats);
00036
00038 double avgLoad = parr->getAverageLoad();
00039 int numPes = parr->procs.size();
00040
00041
00042
00043
00044 parr->resetTotalLoad();
00045
00046 int start = 0, nextPe = 0;
00047 std::queue<int> vertexq;
00048
00049
00050 vertexq.push(start);
00051 if(parr->procs[nextPe].getTotalLoad() + ogr->vertices[start].getVertexLoad() > avgLoad) {
00052 nextPe++;
00053 avgLoad += (avgLoad - parr->procs[nextPe].getTotalLoad())/(numPes-nextPe);
00054 }
00055 ogr->vertices[start].setNewPe(nextPe);
00056
00057 parr->procs[nextPe].totalLoad() += ogr->vertices[start].getVertexLoad();
00058
00059 int i, nbr;
00060
00061 while(!vertexq.empty()) {
00062 start = vertexq.front();
00063 vertexq.pop();
00064
00065 for(i = 0; i < ogr->vertices[start].sendToList.size(); i++) {
00066
00067
00068 nbr = ogr->vertices[start].sendToList[i].getNeighborId();
00069 if(ogr->vertices[nbr].getNewPe() == -1) {
00070 vertexq.push(nbr);
00071
00072 if(parr->procs[nextPe].getTotalLoad() + ogr->vertices[nbr].getVertexLoad() > avgLoad) {
00073 nextPe++;
00074 avgLoad += (avgLoad - parr->procs[nextPe].getTotalLoad())/(numPes-nextPe);
00075 }
00076 ogr->vertices[nbr].setNewPe(nextPe);
00077
00078 parr->procs[nextPe].totalLoad() += ogr->vertices[nbr].getVertexLoad();
00079 }
00080 }
00081 }
00082
00084 ogr->convertDecisions(stats);
00085 }
00086
00087 #include "GraphBFTLB.def.h"
00088