examples: add example program demonstrating sync entry methods
authorAaron Becker <akbecker@gmail.com>
Wed, 22 Aug 2012 22:46:36 +0000 (17:46 -0500)
committerAaron Becker <akbecker@gmail.com>
Wed, 22 Aug 2012 22:46:36 +0000 (17:46 -0500)
examples/charm++/sync_square/Makefile [new file with mode: 0644]
examples/charm++/sync_square/sync_square.cc [new file with mode: 0644]
examples/charm++/sync_square/sync_square.ci [new file with mode: 0644]
examples/charm++/sync_square/sync_square.h [new file with mode: 0644]

diff --git a/examples/charm++/sync_square/Makefile b/examples/charm++/sync_square/Makefile
new file mode 100644 (file)
index 0000000..1045571
--- /dev/null
@@ -0,0 +1,27 @@
+CHARMC = ../../../bin/charmc
+BINARY = sync_square
+
+CHARMCFLAGS = $(OPTS)
+CHARMCLINKFLAGS = -language charm++
+TESTFLAGS = $(TESTOPTS)
+
+%.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++/sync_square/sync_square.cc b/examples/charm++/sync_square/sync_square.cc
new file mode 100644 (file)
index 0000000..1b45164
--- /dev/null
@@ -0,0 +1,25 @@
+#include "sync_square.h"
+#include <stdlib.h>
+
+Driver::Driver(CkArgMsg* args) {
+    int value = 10;
+    if (args->argc > 1) value = strtol(args->argv[1], NULL, 10);
+    delete args;
+    s = CProxy_Squarer::ckNew();
+    thisProxy.get_square(value);
+}
+
+void Driver::get_square(int value)
+{
+    int_message* square_message = s.square(value);
+    int square = square_message->value;
+    CkFreeMsg(square_message);
+    CkExit();
+}
+
+int_message* Squarer::square(int x) {
+    return new int_message(x*x);
+}
+
+
+#include "sync_square.def.h"
diff --git a/examples/charm++/sync_square/sync_square.ci b/examples/charm++/sync_square/sync_square.ci
new file mode 100644 (file)
index 0000000..c39ce6b
--- /dev/null
@@ -0,0 +1,14 @@
+mainmodule sync_square {
+
+    message int_message;
+
+    mainchare Driver {
+        entry Driver(CkArgMsg*);
+        entry void get_square(int value);
+    }
+
+    chare Squarer {
+        entry Squarer(void);
+        entry [sync] int_message* square(int x);
+    }
+}
diff --git a/examples/charm++/sync_square/sync_square.h b/examples/charm++/sync_square/sync_square.h
new file mode 100644 (file)
index 0000000..8f15bc9
--- /dev/null
@@ -0,0 +1,22 @@
+#include "sync_square.decl.h"
+
+class int_message : public CMessage_int_message {
+    public:
+        int value;
+        int_message(int val) : value(val) {}
+};
+
+class Driver : public CBase_Driver {
+    public: 
+        Driver(CkArgMsg*);
+        void get_square(int value);
+        CProxy_Squarer s;
+};
+
+class Squarer : public CBase_Squarer {
+    public:
+        Squarer(void) {}
+        Squarer(CkMigrateMessage* m) {}
+        int_message* square(int x);
+};
+