Add hello load balancing example with GreedyRefineLB 86/4986/8
authorJaemin Choi <jchoi157@illinois.edu>
Wed, 27 Feb 2019 23:50:30 +0000 (18:50 -0500)
committerJaemin Choi <jchoi157@illinois.edu>
Mon, 4 Mar 2019 20:29:22 +0000 (14:29 -0600)
Chares on latter half of the PEs busywait for one second,
which results in migration to the lower half of the PEs.

Change-Id: I20a2a62331c5c873005b500d6c7fa1c65d793d56

examples/charm++/load_balancing/Makefile
examples/charm++/load_balancing/hello/Makefile [new file with mode: 0644]
examples/charm++/load_balancing/hello/hello.C [new file with mode: 0644]
examples/charm++/load_balancing/hello/hello.ci [new file with mode: 0644]

index ca6b8d4..0267c17 100644 (file)
@@ -1,4 +1,5 @@
 DIRS = \
+  hello \
   stencil3d \
   kNeighbor \
 
diff --git a/examples/charm++/load_balancing/hello/Makefile b/examples/charm++/load_balancing/hello/Makefile
new file mode 100644 (file)
index 0000000..57f280b
--- /dev/null
@@ -0,0 +1,21 @@
+-include ../../../common.mk
+CHARMC = ../../../../bin/charmc $(OPTS)
+
+TARGET = hello
+
+all: $(TARGET)
+
+$(TARGET): $(TARGET).o
+       $(CHARMC) -language charm++ -module CommonLBs -o $@ $^
+
+$(TARGET).decl.h: $(TARGET).ci
+       $(CHARMC) $<
+
+$(TARGET).o: $(TARGET).C $(TARGET).decl.h
+       $(CHARMC) -c $<
+
+test: $(TARGET)
+       $(call run, +p4 ./$(TARGET) +balancer GreedyRefineLB +LBDebug 1)
+
+clean:
+       rm -f $(TARGET) *.decl.h *.def.h *.o charmrun
diff --git a/examples/charm++/load_balancing/hello/hello.C b/examples/charm++/load_balancing/hello/hello.C
new file mode 100644 (file)
index 0000000..435692f
--- /dev/null
@@ -0,0 +1,66 @@
+#include "hello.decl.h"
+
+/* readonly */ CProxy_Main mainProxy;
+/* readonly */ CProxy_Hello helloProxy;
+
+class Main : public CBase_Main {
+  public:
+    Main(CkArgMsg* m) {
+      delete m;
+
+      // 2 chares per PE
+      int n = 2 * CkNumPes();
+
+      helloProxy = CProxy_Hello::ckNew(n);
+      helloProxy.work();
+    }
+
+    void done() {
+      CkExit();
+    }
+};
+
+class Hello : public CBase_Hello {
+  int pe;
+
+  public:
+    Hello() {
+      usesAtSync = true;
+      pe = CkMyPe();
+      CkPrintf("Hello, I'm chare %d on PE %d\n", thisIndex, pe);
+    }
+
+    Hello(CkMigrateMessage* m) { }
+
+    void pup(PUP::er &p) {
+      p|pe;
+    }
+
+    void work() {
+      // For chares on latter half of the PEs, introduce artificial load
+      // so that they can be migrated to the lower half
+      bool heavy = (CkMyPe() >= (CkNumPes() / 2));
+      double start_time = CkWallTimer();
+      if (heavy) {
+        // Busy wait for one second
+        while (CkWallTimer() - start_time < 1) { }
+      }
+
+      // Informs the runtime system that the chare is ready to migrate
+      AtSync();
+    }
+
+    void ResumeFromSync() {
+      if (CkMyPe() != pe) {
+        CkPrintf("I'm chare %d, I moved to PE %d from PE %d\n", thisIndex, CkMyPe(), pe);
+      }
+      else {
+        CkPrintf("I'm chare %d, I'm staying on PE %d\n", thisIndex, pe);
+      }
+
+      CkCallback cb(CkReductionTarget(Main, done), mainProxy);
+      contribute(cb);
+    }
+};
+
+#include "hello.def.h"
diff --git a/examples/charm++/load_balancing/hello/hello.ci b/examples/charm++/load_balancing/hello/hello.ci
new file mode 100644 (file)
index 0000000..e1aeb82
--- /dev/null
@@ -0,0 +1,14 @@
+mainmodule hello {
+  readonly CProxy_Main mainProxy;
+  readonly CProxy_Hello helloProxy;
+
+  mainchare Main {
+    entry Main(CkArgMsg *m);
+    entry [reductiontarget] void done();
+  };
+
+  array [1D] Hello {
+    entry Hello();
+    entry void work();
+  };
+}