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