Test generated code for entry method template declarations
authorRamprasad Venkataraman <ramv@illinois.edu>
Fri, 30 Mar 2012 02:57:48 +0000 (21:57 -0500)
committerPhil Miller <mille121@illinois.edu>
Thu, 5 Apr 2012 21:17:53 +0000 (16:17 -0500)
tests/charm++/Makefile
tests/charm++/method_templates/Makefile [new file with mode: 0644]
tests/charm++/method_templates/mylib.C [new file with mode: 0644]
tests/charm++/method_templates/mylib.ci [new file with mode: 0644]
tests/charm++/method_templates/mylib.h [new file with mode: 0644]
tests/charm++/method_templates/pgm.C [new file with mode: 0644]
tests/charm++/method_templates/pgm.ci [new file with mode: 0644]

index 451346bf31759034a7a2d4d0005315b5b847e40b..6243e820f7051b12b7460f56e3da8d9504970204 100644 (file)
@@ -1,4 +1,4 @@
-DIRS=megatest pingpong simplearrayhello load_balancing chkpt delegation queue sdag ckAllocSysMsgTest
+DIRS=megatest pingpong simplearrayhello load_balancing chkpt delegation queue sdag ckAllocSysMsgTest method_templates
 
 all:
        for d in $(DIRS); do \
 
 all:
        for d in $(DIRS); do \
diff --git a/tests/charm++/method_templates/Makefile b/tests/charm++/method_templates/Makefile
new file mode 100644 (file)
index 0000000..414045d
--- /dev/null
@@ -0,0 +1,71 @@
+# Point this to your charm installation
+CHARMHOME = ../../..
+
+# Charm directory structure
+CHARMBIN := $(CHARMHOME)/bin
+CHARMINC := $(CHARMHOME)/include
+
+# The relevant source files for this project
+HDR       = mylib.h
+SRC       = mylib.C pgm.C
+OBJ       = $(SRC:.C=.o)
+INTF      = mylib.ci pgm.ci   
+
+# Specify the exe name and the arguments to run it with
+NP        = 4
+TARGET    = testTemplateEP
+ARGS      = 
+
+# Specify the compilers, run script, flags etc.
+CXX       = $(CHARMBIN)/charmc
+CXXFLAGS += -language charm++ $(OPTS)
+CPPFLAGS +=
+LDFLAGS  +=
+EXEC      = ./charmrun
+EXECFLAGS = +p$(NP)
+ifdef $(NODELIST)
+  EXECFLAGS += ++nodelist $(NODELIST)
+endif
+
+
+########### This stuff should be able take care of itself ############
+
+.PHONY: all clean again test bgtest translateInterface
+
+all: $(TARGET)
+
+$(TARGET): $(OBJ) 
+       $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) -o $@ $^
+
+clean:
+       $(RM) $(wildcard *.decl.h *.def.h *.d *.di *.ci.stamp *.o) $(TARGET) charmrun 
+
+again: 
+       $(MAKE) clean; $(MAKE)
+
+test: all
+       @echo "########################################################################################"
+       $(EXEC) $(EXECFLAGS) $(TARGET) $(ARGS)
+
+
+####### Pattern rules
+# Rule to generate dependency information for C++ source files
+%.d: %.C
+       $(info Generating dependencies for $<)
+       @g++ -MM -MG $(CPPFLAGS) $(INCDIRS:%=-I%) -I$(CHARMINC) $< | perl $(CHARMBIN)/dep.pl $(CHARMINC) > $@
+#      @$(SHELL) -ec 'g++ -MM -MG $(CPPFLAGS) $(INCDIRS:%=-I%) $< \
+#      | sed '\''s/\($*\)\.o[ :]*/\1.o $@ : /g'\'' > $@; \
+#      [ -s $@ ] || rm -f $@'
+
+# Rule to generate dependency info for charm++ interface (ci) definition files
+%.di: %.ci
+       $(info Generating dependencies for $<)
+       @$(CXX) -M $< > $@
+
+%.ci.stamp: %.ci
+       $(CXX) $< && touch $@
+
+# Include the generated files containing dependency info
+-include $(SRC:.C=.d)
+-include $(INTF:.ci=.di)
+
diff --git a/tests/charm++/method_templates/mylib.C b/tests/charm++/method_templates/mylib.C
new file mode 100644 (file)
index 0000000..64ebff7
--- /dev/null
@@ -0,0 +1,2 @@
+#include "mylib.h"
+#include "mylib.def.h"
diff --git a/tests/charm++/method_templates/mylib.ci b/tests/charm++/method_templates/mylib.ci
new file mode 100644 (file)
index 0000000..8f39124
--- /dev/null
@@ -0,0 +1,8 @@
+module mylib {
+    array [1D] libArray {
+        entry libArray();
+        template <typename T>
+        entry void doSomething(T t);
+    };
+};
+
diff --git a/tests/charm++/method_templates/mylib.h b/tests/charm++/method_templates/mylib.h
new file mode 100644 (file)
index 0000000..bf3ab24
--- /dev/null
@@ -0,0 +1,31 @@
+#ifndef MYLIB_H
+#define MYLIB_H
+
+#include "mylib.decl.h"
+#include <sstream>
+
+class libArray: public CBase_libArray
+{
+    public:
+        libArray() {}
+        libArray(CkMigrateMessage *msg) {}
+
+        // Allows client to visit and operate on library-owned data
+        // @note: Clients should supply type that provides void operator() (int) and an ostream inserter
+        template <typename T>
+        void doSomething(T t)
+        {
+            // Apply client specified operation to my chunk of data
+            for (int i = thisIndex*10; i< (thisIndex+1)*10; i++)
+                t(i);
+            // Do something with the result
+            std::ostringstream out;
+            out << "\nlibArray[" << thisIndex << "] " << t;
+            CkPrintf("%s", out.str().c_str());
+            // Notify completion
+            contribute();
+        }
+};
+
+#endif // MYLIB_H
+
diff --git a/tests/charm++/method_templates/pgm.C b/tests/charm++/method_templates/pgm.C
new file mode 100644 (file)
index 0000000..942619b
--- /dev/null
@@ -0,0 +1,76 @@
+#include "client.decl.h"
+#include "mylib.h"
+#define CK_TEMPLATES_ONLY
+#include "mylib.def.h"
+#undef CK_TEMPLATES_ONLY
+#include <iostream>
+
+// Utility functors
+class add {
+    private:
+        int sum;
+    public:
+        add(): sum(0) {}
+        inline void operator() (int i) { sum += i; }
+        void pup(PUP::er &p) { p | sum; }
+        friend std::ostream& operator<< (std::ostream& out, const add& obj) {
+            out << "sum = " << obj.sum;
+            return out;
+        }
+};
+
+
+class avg {
+    private:
+        int sum, num;
+    public:
+        avg(): sum(0), num(0) {}
+        inline void operator() (int i) { sum += i; num++; }
+        void pup(PUP::er &p) { p | sum; p | num; }
+        friend std::ostream& operator<< (std::ostream& out, const avg& obj) {
+            out << "num = " << obj.num << "; "
+                << "avg = " << ( obj.num ? obj.sum/obj.num : obj.sum );
+            return out;
+        }
+};
+
+
+// Temporary initproc to register the instantiated EPs
+void register_instantiations()
+{
+    add adder;
+    avg avger;
+    CkIndex_libArray::doSomething<add>(adder);
+    CkIndex_libArray::doSomething<avg>(avger);
+};
+
+
+// Test driver
+class pgm : public CBase_pgm
+{
+    public:
+        pgm(CkArgMsg *m): nElements(CkNumPes()), nDone(0)
+        {
+            arrProxy = CProxy_libArray::ckNew(nElements);
+            arrProxy.ckSetReductionClient( new CkCallback(CkIndex_pgm::endTest(), thisProxy) );
+            thisProxy.startTest();
+            delete m;
+        }
+        
+        void startTest() {
+            arrProxy.doSomething(add());
+            arrProxy.doSomething(avg());
+        }
+
+        void endTest() {
+            if (++nDone == 2)
+                CkExit();
+        }
+
+    private:
+        CProxy_libArray arrProxy;
+        int nElements, nDone;
+};
+
+#include "client.def.h"
+
diff --git a/tests/charm++/method_templates/pgm.ci b/tests/charm++/method_templates/pgm.ci
new file mode 100644 (file)
index 0000000..0b87983
--- /dev/null
@@ -0,0 +1,13 @@
+mainmodule client  {
+  extern module mylib;
+  initproc register_instantiations();
+
+  mainchare pgm {
+    entry pgm (CkArgMsg *m);
+
+    entry void startTest();
+    entry[reductiontarget] void endTest();
+  };
+
+}
+