New balancer AdaptiveLB
authorHarshitha <gplkrsh2@illinois.edu>
Tue, 13 Mar 2012 21:20:19 +0000 (16:20 -0500)
committerHarshitha <gplkrsh2@illinois.edu>
Tue, 13 Mar 2012 21:20:19 +0000 (16:20 -0500)
src/ck-ldb/AdaptiveLB.C [new file with mode: 0644]
src/ck-ldb/AdaptiveLB.ci [new file with mode: 0644]
src/ck-ldb/AdaptiveLB.h [new file with mode: 0644]
src/ck-ldb/Makefile_lb.sh

diff --git a/src/ck-ldb/AdaptiveLB.C b/src/ck-ldb/AdaptiveLB.C
new file mode 100644 (file)
index 0000000..2687d4e
--- /dev/null
@@ -0,0 +1,101 @@
+/**
+ * \addtogroup CkLdb
+*/
+/*@{*/
+
+#include "AdaptiveLB.h"
+#include "ckgraph.h"
+
+#define alpha 4.0e-6
+#define beta 2.67e-9
+#define percent_overhead 10
+
+extern LBAllocFn getLBAllocFn(char *lbname);
+
+CreateLBFunc_Def(AdaptiveLB, "Allow multiple strategies to work serially")
+
+AdaptiveLB::AdaptiveLB(const CkLBOptions &opt): CentralLB(opt)
+{
+  lbname = "AdaptiveLB";
+  const char *lbs = theLbdb->loadbalancer(opt.getSeqNo());
+  if (CkMyPe() == 0)
+    CkPrintf("[%d] AdaptiveLB created with %s\n",CkMyPe(), lbs);
+
+  char *lbcopy = strdup(lbs);
+  char *greedyLBString = "GreedyLB";
+  char *refineLBString = "RefineLB";
+//  char *scotchLBString = "ScotchLB";
+
+  LBAllocFn fn = getLBAllocFn(greedyLBString);
+  if (fn == NULL) {
+    CkPrintf("LB> Invalid load balancer: %s.\n", greedyLBString);
+    CmiAbort("");
+  }
+  BaseLB *glb = fn();
+  greedyLB = (CentralLB*)glb;
+
+  fn = getLBAllocFn(refineLBString);
+  if (fn == NULL) {
+    CkPrintf("LB> Invalid load balancer: %s.\n", refineLBString);
+    CmiAbort("");
+  }
+  BaseLB *rlb = fn();
+  refineLB = (CentralLB*)rlb;
+
+//  fn = getLBAllocFn(scotchLBString);
+//  if (fn == NULL) {
+//    CkPrintf("LB> Invalid load balancer: %s.\n", scotchLBString);
+//    CmiAbort("");
+//  }
+//  BaseLB *slb = fn();
+//  scotchLB = (CentralLB*)slb;
+}
+
+void AdaptiveLB::work(LDStats* stats)
+{
+
+  ProcArray *parr = new ProcArray(stats);
+  ObjGraph *ogr = new ObjGraph(stats);
+  CkPrintf("Adaptive work\n");
+
+  // Calculate the load and total messages
+//  double totalLoad = 0.0;
+//  long totalMsgs = 0;
+//  long long totalBytes = 0;
+//  int vertnbr = ogr->vertices.size();
+//
+//  /** the object load is normalized to an integer between 0 and 256 */
+//  for(int i = 0; i < vertnbr; i++) {
+//    totalLoad += ogr->vertices[i].getVertexLoad();
+//  }
+//
+//  for(int i = 0; i < vertnbr; i++) {
+//    for(int j = 0; j < ogr->vertices[i].sendToList.size(); j++) {
+//      totalMsgs += ogr->vertices[i].sendToList[j].getNumMsgs();
+//      totalBytes += ogr->vertices[i].sendToList[j].getNumBytes();
+//    }
+//  }
+//  double commOverhead = (totalMsgs * alpha) + (totalBytes * beta);
+//
+//  CkPrintf("AdaptiveLB> Total load %E\n", totalLoad);
+//  CkPrintf("AdaptiveLB> Total Msgs %d\n", totalMsgs);
+//  CkPrintf("AdaptiveLB> Total Bytes %ld\n", totalBytes);
+//  CkPrintf("AdaptiveLB> Total Comm %E\n", commOverhead);
+//
+//  // Choose the right LB
+//  //
+//  // If communication overhead is 10% computation, then choose Scotch LB
+//  if (commOverhead > (totalLoad * percent_overhead / 100)) {
+//    scotchLB->work(stats);
+//  } else {
+//    refineLB->work(stats);
+//  }
+  delete parr;
+  delete ogr;
+
+}
+
+#include "AdaptiveLB.def.h"
+
+
+/*@}*/
diff --git a/src/ck-ldb/AdaptiveLB.ci b/src/ck-ldb/AdaptiveLB.ci
new file mode 100644 (file)
index 0000000..29a3b4e
--- /dev/null
@@ -0,0 +1,9 @@
+module AdaptiveLB {
+
+extern module CentralLB;
+initnode void lbinit(void);
+group [migratable] AdaptiveLB : CentralLB {
+  entry void AdaptiveLB(const CkLBOptions &);  
+};
+
+};
diff --git a/src/ck-ldb/AdaptiveLB.h b/src/ck-ldb/AdaptiveLB.h
new file mode 100644 (file)
index 0000000..e48036a
--- /dev/null
@@ -0,0 +1,39 @@
+/**
+ * \addtogroup CkLdb
+*/
+/*@{*/
+
+#ifndef CENTRAL_ADAPTIVE_LB_H
+#define CENTRAL_ADAPTIVE_LB_H
+
+#include "CentralLB.h"
+#include "AdaptiveLB.decl.h"
+
+void CreateAdaptiveLB();
+
+/// for backward compatibility
+typedef LBMigrateMsg  CLBMigrateMsg;
+
+class AdaptiveLB : public CentralLB
+{
+public:
+  AdaptiveLB(const CkLBOptions &);
+  AdaptiveLB(CkMigrateMessage *m):CentralLB(m) {}
+
+protected:
+  virtual CmiBool QueryBalanceNow(int) { return CmiTrue; };  
+  virtual void work(LDStats* stats);
+  void computeNonlocalComm(long long &nmsgs, long long &nbytes);
+
+private:  
+//  CProxy_CentralLB thisProxy;
+  CentralLB *greedyLB;
+  CentralLB *refineLB;
+  CentralLB *scotchLB;
+};
+
+#endif /* CENTRAL_ADAPTIVE_LB_H */
+
+/*@}*/
+
+
index e59e977e3ad320fa56b009d910974c9e12cab3b6..ccb3ccc1d0c740d04f531824dc7ee71250181bc7 100755 (executable)
@@ -1,6 +1,6 @@
 #!/bin/sh
 UNCOMMON_LDBS="TempAwareGreedyLB MetisLB ScotchLB TeamLB WSLB"
 #!/bin/sh
 UNCOMMON_LDBS="TempAwareGreedyLB MetisLB ScotchLB TeamLB WSLB"
-COMMON_LDBS="BlockLB CommLB DummyLB GreedyAgentLB GreedyCommLB GreedyLB NeighborCommLB NeighborLB OrbLB PhasebyArrayLB RandCentLB RecBipartLB RefineLB RefineCommLB RotateLB TreeMatchLB"
+COMMON_LDBS="BlockLB CommLB DummyLB GreedyAgentLB GreedyCommLB GreedyLB NeighborCommLB NeighborLB OrbLB PhasebyArrayLB RandCentLB RecBipartLB RefineLB RefineCommLB RotateLB TreeMatchLB AdaptiveLB"
 OTHER_LDBS="ComboCentLB GraphPartLB GraphBFTLB GridCommLB GridCommRefineLB GridHybridLB GridHybridSeedLB GridMetisLB HbmLB HybridLB RefineKLB RefineTopoLB TopoCentLB TopoLB"
 ALL_LDBS="$COMMON_LDBS $OTHER_LDBS"
 
 OTHER_LDBS="ComboCentLB GraphPartLB GraphBFTLB GridCommLB GridCommRefineLB GridHybridLB GridHybridSeedLB GridMetisLB HbmLB HybridLB RefineKLB RefineTopoLB TopoCentLB TopoLB"
 ALL_LDBS="$COMMON_LDBS $OTHER_LDBS"