6 #include "AdaptiveLB.h"
11 #define percent_overhead 10
13 extern LBAllocFn getLBAllocFn(const char *lbname);
15 extern int quietModeRequested;
17 CreateLBFunc_Def(AdaptiveLB, "Allow multiple strategies to work serially")
19 AdaptiveLB::AdaptiveLB(const CkLBOptions &opt): CBase_AdaptiveLB(opt)
21 lbname = "AdaptiveLB";
22 const char *lbs = theLbdb->loadbalancer(opt.getSeqNo());
23 if (CkMyPe() == 0 && !quietModeRequested)
24 CkPrintf("CharmLB> AdaptiveLB created with %s.\n", lbs);
26 char *lbcopy = strdup(lbs);
27 const char *greedyLBString = "GreedyLB";
28 const char *refineLBString = "RefineLB";
29 const char *metisLBString = "MetisLB";
30 const char *commRefineLBString = "CommAwareRefineLB";
32 LBAllocFn fn = getLBAllocFn(greedyLBString);
34 CkPrintf("LB> Invalid load balancer: %s.\n", greedyLBString);
38 greedyLB = (CentralLB*)glb;
40 fn = getLBAllocFn(refineLBString);
42 CkPrintf("LB> Invalid load balancer: %s.\n", refineLBString);
46 refineLB = (CentralLB*)rlb;
48 fn = getLBAllocFn(metisLBString);
50 CkPrintf("LB> Invalid load balancer: %s.\n", metisLBString);
54 metisLB = (CentralLB*)slb;
56 fn = getLBAllocFn(commRefineLBString);
58 CkPrintf("LB> Invalid load balancer: %s.\n", commRefineLBString);
62 commRefineLB = (CentralLB*)crlb;
64 if (_lb_args.metaLbOn()) {
65 metabalancer = (MetaBalancer*)CkLocalBranch(_metalb);
71 void AdaptiveLB::work(LDStats* stats)
74 ProcArray *parr = new ProcArray(stats);
75 ObjGraph *ogr = new ObjGraph(stats);
76 CkPrintf("Adaptive work\n");
78 //bool isComm = theLbdb->isStrategyComm();
80 // Calculate the load and total messages
81 double totalLoad = 0.0;
83 long long totalBytes = 0;
84 int vertnbr = ogr->vertices.size();
86 /** the object load is normalized to an integer between 0 and 256 */
87 for(int i = 0; i < vertnbr; i++) {
88 totalLoad += ogr->vertices[i].getVertexLoad();
91 for(int i = 0; i < vertnbr; i++) {
92 for(int j = 0; j < ogr->vertices[i].sendToList.size(); j++) {
93 totalMsgs += ogr->vertices[i].sendToList[j].getNumMsgs();
94 totalBytes += ogr->vertices[i].sendToList[j].getNumBytes();
97 double commOverhead = (totalMsgs * alpha) + (totalBytes * beta);
99 CkPrintf("AdaptiveLB> Total load %E\n", totalLoad);
100 CkPrintf("AdaptiveLB> Total Msgs %d\n", totalMsgs);
101 CkPrintf("AdaptiveLB> Total Bytes %ld\n", totalBytes);
102 CkPrintf("AdaptiveLB> Total Comm Overhead %E Total Load %E\n", commOverhead, totalLoad);
105 double refine_max_avg_ratio, lb_max_avg_ratio, greedy_max_avg_ratio;
107 double comm_ratio, comm_refine_ratio;
109 refine_max_avg_ratio = lb_max_avg_ratio = greedy_max_avg_ratio = 1.0;
110 comm_ratio = comm_refine_ratio = 1.0;
112 if (metabalancer != NULL) {
113 metabalancer->GetPrevLBData(lb_type, lb_max_avg_ratio, tmp);
114 metabalancer->GetLBDataForLB(0, greedy_max_avg_ratio, tmp);
115 metabalancer->GetLBDataForLB(1, refine_max_avg_ratio, tmp);
116 metabalancer->GetLBDataForLB(2, tmp, comm_ratio);
117 metabalancer->GetLBDataForLB(3, tmp, comm_refine_ratio);
120 CkPrintf("AdaptiveLB> Previous LB %d\n", lb_type);
122 // Choose the right LB
124 // If communication overhead is 10% computation, then choose Scotch LB
125 //if (isComm || (commOverhead > (totalLoad * percent_overhead / 100))) {
126 if ((commOverhead > (totalLoad * percent_overhead / 100))) {
129 metisLB->work(stats);
130 CkPrintf("---METIS LB\n");
131 } else if (comm_refine_ratio <= 1.01) {
133 commRefineLB->work(stats);
134 CkPrintf("---CommAwareRefineLB\n");
135 } else if (comm_ratio <= 1.01) {
137 metisLB->work(stats);
138 CkPrintf("---METIS LB\n");
141 commRefineLB->work(stats);
142 CkPrintf("---CommAwareRefineLB\n");
148 greedyLB->work(stats);
149 CkPrintf("---GREEDY LB\n");
150 } else if (refine_max_avg_ratio <= 1.01) {
152 refineLB->work(stats);
153 CkPrintf("---REFINE LB\n");
154 } else if (greedy_max_avg_ratio <= 1.01) {
156 greedyLB->work(stats);
157 CkPrintf("---GREEDY LB\n");
160 refineLB->work(stats);
161 CkPrintf("---REFINE LB\n");
164 // UpdateLBDBWithData(lb_type, stats->after_lb_max, stats->after_lb_avg,
165 // stats->local_comm, stats->remote_comm);
172 #include "AdaptiveLB.def.h"