6 #include "AdaptiveLB.h"
11 #define percent_overhead 10
13 extern LBAllocFn getLBAllocFn(const char *lbname);
15 CreateLBFunc_Def(AdaptiveLB, "Allow multiple strategies to work serially")
17 AdaptiveLB::AdaptiveLB(const CkLBOptions &opt): CBase_AdaptiveLB(opt)
19 lbname = "AdaptiveLB";
20 const char *lbs = theLbdb->loadbalancer(opt.getSeqNo());
22 CkPrintf("[%d] AdaptiveLB created with %s\n",CkMyPe(), lbs);
24 char *lbcopy = strdup(lbs);
25 const char *greedyLBString = "GreedyLB";
26 const char *refineLBString = "RefineLB";
27 const char *metisLBString = "MetisLB";
28 const char *commRefineLBString = "CommAwareRefineLB";
30 LBAllocFn fn = getLBAllocFn(greedyLBString);
32 CkPrintf("LB> Invalid load balancer: %s.\n", greedyLBString);
36 greedyLB = (CentralLB*)glb;
38 fn = getLBAllocFn(refineLBString);
40 CkPrintf("LB> Invalid load balancer: %s.\n", refineLBString);
44 refineLB = (CentralLB*)rlb;
46 fn = getLBAllocFn(metisLBString);
48 CkPrintf("LB> Invalid load balancer: %s.\n", metisLBString);
52 metisLB = (CentralLB*)slb;
54 fn = getLBAllocFn(commRefineLBString);
56 CkPrintf("LB> Invalid load balancer: %s.\n", commRefineLBString);
60 commRefineLB = (CentralLB*)crlb;
62 if (_lb_args.metaLbOn()) {
63 metabalancer = (MetaBalancer*)CkLocalBranch(_metalb);
69 void AdaptiveLB::work(LDStats* stats)
72 ProcArray *parr = new ProcArray(stats);
73 ObjGraph *ogr = new ObjGraph(stats);
74 CkPrintf("Adaptive work\n");
76 //bool isComm = theLbdb->isStrategyComm();
78 // Calculate the load and total messages
79 double totalLoad = 0.0;
81 long long totalBytes = 0;
82 int vertnbr = ogr->vertices.size();
84 /** the object load is normalized to an integer between 0 and 256 */
85 for(int i = 0; i < vertnbr; i++) {
86 totalLoad += ogr->vertices[i].getVertexLoad();
89 for(int i = 0; i < vertnbr; i++) {
90 for(int j = 0; j < ogr->vertices[i].sendToList.size(); j++) {
91 totalMsgs += ogr->vertices[i].sendToList[j].getNumMsgs();
92 totalBytes += ogr->vertices[i].sendToList[j].getNumBytes();
95 double commOverhead = (totalMsgs * alpha) + (totalBytes * beta);
97 CkPrintf("AdaptiveLB> Total load %E\n", totalLoad);
98 CkPrintf("AdaptiveLB> Total Msgs %d\n", totalMsgs);
99 CkPrintf("AdaptiveLB> Total Bytes %ld\n", totalBytes);
100 CkPrintf("AdaptiveLB> Total Comm Overhead %E Total Load %E\n", commOverhead, totalLoad);
103 double refine_max_avg_ratio, lb_max_avg_ratio, greedy_max_avg_ratio;
105 double comm_ratio, comm_refine_ratio;
107 refine_max_avg_ratio = lb_max_avg_ratio = greedy_max_avg_ratio = 1.0;
108 comm_ratio = comm_refine_ratio = 1.0;
110 if (metabalancer != NULL) {
111 metabalancer->GetPrevLBData(lb_type, lb_max_avg_ratio, tmp);
112 metabalancer->GetLBDataForLB(0, greedy_max_avg_ratio, tmp);
113 metabalancer->GetLBDataForLB(1, refine_max_avg_ratio, tmp);
114 metabalancer->GetLBDataForLB(2, tmp, comm_ratio);
115 metabalancer->GetLBDataForLB(3, tmp, comm_refine_ratio);
118 CkPrintf("AdaptiveLB> Previous LB %d\n", lb_type);
120 // Choose the right LB
122 // If communication overhead is 10% computation, then choose Scotch LB
123 //if (isComm || (commOverhead > (totalLoad * percent_overhead / 100))) {
124 if ((commOverhead > (totalLoad * percent_overhead / 100))) {
127 metisLB->work(stats);
128 CkPrintf("---METIS LB\n");
129 } else if (comm_refine_ratio <= 1.01) {
131 commRefineLB->work(stats);
132 CkPrintf("---CommAwareRefineLB\n");
133 } else if (comm_ratio <= 1.01) {
135 metisLB->work(stats);
136 CkPrintf("---METIS LB\n");
139 commRefineLB->work(stats);
140 CkPrintf("---CommAwareRefineLB\n");
146 greedyLB->work(stats);
147 CkPrintf("---GREEDY LB\n");
148 } else if (refine_max_avg_ratio <= 1.01) {
150 refineLB->work(stats);
151 CkPrintf("---REFINE LB\n");
152 } else if (greedy_max_avg_ratio <= 1.01) {
154 greedyLB->work(stats);
155 CkPrintf("---GREEDY LB\n");
158 refineLB->work(stats);
159 CkPrintf("---REFINE LB\n");
162 // UpdateLBDBWithData(lb_type, stats->after_lb_max, stats->after_lb_avg,
163 // stats->local_comm, stats->remote_comm);
170 #include "AdaptiveLB.def.h"