Completion detector example.
authorJonathan Lifflander <jliffl2@illinois.edu>
Sat, 2 Jul 2011 02:26:44 +0000 (19:26 -0700)
committerJonathan Lifflander <jliffl2@illinois.edu>
Sat, 2 Jul 2011 02:26:44 +0000 (19:26 -0700)
examples/charm++/completion/Makefile [new file with mode: 0644]
examples/charm++/completion/comp.cc [new file with mode: 0644]
examples/charm++/completion/comp.ci [new file with mode: 0644]

diff --git a/examples/charm++/completion/Makefile b/examples/charm++/completion/Makefile
new file mode 100644 (file)
index 0000000..cf53fb0
--- /dev/null
@@ -0,0 +1,27 @@
+CXX = charmc
+CXXFLAGS = -g -O3 -Wall
+
+SRC = $(wildcard *.cc)
+SRCCI = $(wildcard *.ci)
+OBJ = $(SRC:.cc=.o)
+EXEC_NAME = comp.x
+DECLS := $(SRCCI:.ci=.decl.h)
+DEFS := $(SRCCI:.ci=.def.h)
+
+all: $(EXEC_NAME)
+
+.PHONY: clean
+
+clean:
+       -rm $(OBJ) $(EXEC_NAME) $(DECLS) $(DEFS) charmrun
+
+$(SRC): $(DECLS)
+
+$(EXEC_NAME): $(OBJ)
+       $(CXX) -o $@ $^ -module completion
+
+%.decl.h: %.ci
+       $(CXX) -c $*.ci
+
+comp.o: comp.cc $(DECLS)
+       $(CXX) $(CXXFLAGS) -c $*.cc -o $*.o
\ No newline at end of file
diff --git a/examples/charm++/completion/comp.cc b/examples/charm++/completion/comp.cc
new file mode 100644 (file)
index 0000000..4f7a796
--- /dev/null
@@ -0,0 +1,39 @@
+#include "comp.decl.h"
+#include "completion.h"
+
+struct Main : public CBase_Main {
+  CProxy_CompletionDetector detector;
+  const int num;
+
+  Main(CkArgMsg* msg)
+    : num(10) {
+    delete msg;
+    detector = CProxy_CompletionDetector::ckNew();
+    detector.start_detection(num,
+                             CkCallback(CkIndex_Main::startTest(), thisProxy),
+                             CkCallback(CkIndex_Main::finishTest(), thisProxy), 0);
+  }
+
+  void startTest() {
+    CkPrintf("completion module initialized\n");
+    CProxy_completion_array::ckNew(detector, num, num);
+  }
+
+  void finishTest() {
+    CkPrintf("completion completed successfully\n");
+    CkExit();
+  }
+};
+
+struct completion_array : public CBase_completion_array {
+  completion_array(CProxy_CompletionDetector det, int n) {
+    CkPrintf("Array element %d producing %d elements\n", thisIndex, thisIndex + 1);
+    det.ckLocalBranch()->produce(thisIndex + 1);
+    det.ckLocalBranch()->done();
+    CkPrintf("Array element %d consuming %d elements\n", thisIndex, n - thisIndex);
+    det.ckLocalBranch()->consume(n - thisIndex);
+  }
+  completion_array(CkMigrateMessage *) {}
+};
+
+#include "comp.def.h"
diff --git a/examples/charm++/completion/comp.ci b/examples/charm++/completion/comp.ci
new file mode 100644 (file)
index 0000000..76987c1
--- /dev/null
@@ -0,0 +1,13 @@
+mainmodule comp {
+  extern module completion;
+
+  mainchare Main {
+    entry Main(CkArgMsg*);
+    entry void startTest();
+    entry void finishTest();
+  };
+
+  array [1D] completion_array {
+    entry completion_array(CProxy_CompletionDetector detector, int n);
+  };
+}
\ No newline at end of file