From 42404720547b2a6c730af4fb9f9875c867e55922 Mon Sep 17 00:00:00 2001 From: Jaemin Choi Date: Wed, 27 Feb 2019 18:50:30 -0500 Subject: [PATCH] Add hello load balancing example with GreedyRefineLB 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 | 1 + examples/charm++/load_balancing/hello/Makefile | 21 ++++++++ examples/charm++/load_balancing/hello/hello.C | 66 ++++++++++++++++++++++++++ examples/charm++/load_balancing/hello/hello.ci | 14 ++++++ 4 files changed, 102 insertions(+) create mode 100644 examples/charm++/load_balancing/hello/Makefile create mode 100644 examples/charm++/load_balancing/hello/hello.C create mode 100644 examples/charm++/load_balancing/hello/hello.ci diff --git a/examples/charm++/load_balancing/Makefile b/examples/charm++/load_balancing/Makefile index ca6b8d4861..0267c178b4 100644 --- a/examples/charm++/load_balancing/Makefile +++ b/examples/charm++/load_balancing/Makefile @@ -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 index 0000000000..57f280bc59 --- /dev/null +++ b/examples/charm++/load_balancing/hello/Makefile @@ -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 index 0000000000..435692f362 --- /dev/null +++ b/examples/charm++/load_balancing/hello/hello.C @@ -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 index 0000000000..e1aeb82726 --- /dev/null +++ b/examples/charm++/load_balancing/hello/hello.ci @@ -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(); + }; +} -- 2.11.4.GIT