added typed reduction example program
authorAaron Becker <akbecker@gmail.com>
Fri, 28 Jan 2011 18:50:26 +0000 (12:50 -0600)
committerAaron Becker <akbecker@gmail.com>
Fri, 28 Jan 2011 18:50:26 +0000 (12:50 -0600)
examples/charm++/typed_reduction/Makefile [new file with mode: 0644]
examples/charm++/typed_reduction/TypedReduction.cc [new file with mode: 0644]
examples/charm++/typed_reduction/TypedReduction.ci [new file with mode: 0644]
examples/charm++/typed_reduction/TypedReduction.h [new file with mode: 0644]

diff --git a/examples/charm++/typed_reduction/Makefile b/examples/charm++/typed_reduction/Makefile
new file mode 100644 (file)
index 0000000..4fac284
--- /dev/null
@@ -0,0 +1,27 @@
+CHARMC = ../../../bin/charmc
+BINARY = typed_reduction
+
+CHARMCFLAGS =
+CHARMCLINKFLAGS = -language charm++
+TESTFLAGS = 
+
+%.o: %.cc
+
+all: $(BINARY)
+$(BINARY): $(patsubst %.cc,%.o,$(wildcard *.cc))
+       $(CHARMC) $(CHARMCLINKFLAGS) -o $@ $+
+
+.SECONDARY: $(patsubst %.cc,%.decl.h,$(wildcard *.cc))
+.SECONDARY: $(patsubst %.cc,%.def.h,$(wildcard *.cc))
+
+%.o: %.cc %.decl.h %.def.h
+       $(CHARMC) $(CHARMCFLAGS) $<
+
+%.decl.h %.def.h: %.ci
+       $(CHARMC) $(CHARMCFLAGS) $<
+
+test: $(BINARY)
+       ./charmrun ./$(BINARY) $(TESTFLAGS)
+
+clean:
+       rm -f *.o *.decl.h *.def.h charmrun $(BINARY)
diff --git a/examples/charm++/typed_reduction/TypedReduction.cc b/examples/charm++/typed_reduction/TypedReduction.cc
new file mode 100644 (file)
index 0000000..d53133c
--- /dev/null
@@ -0,0 +1,62 @@
+#include "TypedReduction.h"
+#include <stdlib.h>
+
+Driver::Driver(CkArgMsg* args) {
+    int array_size = 10;
+    if (args->argc > 1) array_size = strtol(args->argv[1], NULL, 10);
+    w = CProxy_Worker::ckNew(array_size);
+    CkCallback *cb = new CkCallback(CkIndex_Driver::untyped_done(NULL), thisProxy);
+    w.ckSetReductionClient(cb);
+    w.reduce();
+}
+
+void Driver::untyped_done(CkReductionMsg* m) {
+    int* output = (int*)m->getData();
+    CkPrintf("Untyped Sum: %d\n", output[0]);
+    delete m;
+
+    CkCallback *cb = new CkCallback(
+            CkIndex_Driver::typed_done_redn_wrapper(NULL), thisProxy);
+    w.ckSetReductionClient(cb);
+    w.reduce();
+}
+
+void Driver::typed_done(int result)
+{
+    CkPrintf("Typed Sum: %d\n", result);
+    CkCallback *cb = new CkCallback(
+            CkIndex_Driver::typed_array_done_redn_wrapper(NULL), thisProxy);
+    w.ckSetReductionClient(cb);
+    w.reduce_array();
+}
+
+void Driver::typed_array_done(int* results, int n)
+{
+    CkPrintf("Typed Sum: [ ");
+    for (int i=0; i<n; ++i) CkPrintf("%d ", results[i]);
+    CkPrintf(" ]\n");
+    CkCallback *cb = new CkCallback(
+            CkIndex_Driver::typed_array_done2_redn_wrapper(NULL), thisProxy);
+    w.ckSetReductionClient(cb);
+    w.reduce_array();
+}
+
+void Driver::typed_array_done2(int x, int y, int z)
+{
+    CkPrintf("Typed Sum: (x, y, z) = (%d, %d, %d)\n", x, y, z);
+    CkExit();
+}
+
+Worker::Worker() { }
+
+void Worker::reduce() {
+    int contribution = 1;
+    contribute(1*sizeof(int), &contribution, CkReduction::sum_int); 
+}
+
+void Worker::reduce_array() {
+    int contribution[3] = { 1, 2, 3 };
+    contribute(3*sizeof(int), &contribution, CkReduction::sum_int); 
+}
+
+#include "TypedReduction.def.h"
diff --git a/examples/charm++/typed_reduction/TypedReduction.ci b/examples/charm++/typed_reduction/TypedReduction.ci
new file mode 100644 (file)
index 0000000..14df6e4
--- /dev/null
@@ -0,0 +1,15 @@
+mainmodule TypedReduction {
+    mainchare Driver {
+        entry Driver(CkArgMsg*);
+        entry void untyped_done(CkReductionMsg* msg);
+        entry [reductiontarget] void typed_done(int x);
+        entry [reductiontarget] void typed_array_done(int results[n], int n);
+        entry [reductiontarget] void typed_array_done2(int x, int y, int z);
+    }
+
+    array [1d] Worker {
+        entry Worker(void);
+        entry void reduce(void);
+        entry void reduce_array(void);
+    }
+}
diff --git a/examples/charm++/typed_reduction/TypedReduction.h b/examples/charm++/typed_reduction/TypedReduction.h
new file mode 100644 (file)
index 0000000..87e4b74
--- /dev/null
@@ -0,0 +1,20 @@
+#include "TypedReduction.decl.h"
+class Driver : public CBase_Driver {
+    public: 
+        Driver(CkArgMsg*);
+        void untyped_done(CkReductionMsg* m);
+        void typed_done(int x);
+        void typed_array_done(int* results, int n);
+        void typed_array_done2(int x, int y, int z);
+    private:
+        CProxy_Worker w;
+};
+
+class Worker : public CBase_Worker {
+    public:
+        Worker(void);
+        Worker(CkMigrateMessage* m) {}
+        void reduce();
+        void reduce_array();
+};
+