HeapObject implemented using STL vector
authorEric Bohm <ebohm@illinois.edu>
Tue, 31 Jul 2012 22:56:29 +0000 (17:56 -0500)
committerEric Bohm <ebohm@illinois.edu>
Tue, 31 Jul 2012 23:51:33 +0000 (18:51 -0500)
examples/charm++/PUP/STLPUP/HeapObjectSTL.h [new file with mode: 0644]
examples/charm++/PUP/STLPUP/Makefile [new file with mode: 0644]
examples/charm++/PUP/STLPUP/SimplePUP.C [new file with mode: 0644]
examples/charm++/PUP/STLPUP/SimplePUP.ci [new file with mode: 0644]
examples/charm++/PUP/STLPUP/SimplePUP.h [new file with mode: 0644]

diff --git a/examples/charm++/PUP/STLPUP/HeapObjectSTL.h b/examples/charm++/PUP/STLPUP/HeapObjectSTL.h
new file mode 100644 (file)
index 0000000..e029cd1
--- /dev/null
@@ -0,0 +1,41 @@
+#include <vector>
+#include <pup_stl.h>
+class HeapObject
+{
+
+ public:
+
+  int publicInt;
+
+ HeapObject(int param1, bool param2):publicInt(param1), privateBool(param2) {}
+
+ HeapObject():publicInt(0), privateBool(false) {}
+ void pup(PUP::er &p)
+ {
+   // remember to pup your superclass if there is one
+   p|publicInt;
+   p|privateBool;
+   p|data;
+ }
+ inline HeapObject &operator=(const HeapObject &indata) {
+    publicInt=indata.publicInt;
+    privateBool=indata.privateBool;
+    data=indata.data;
+    return *this;
+  }
+
+
+ void doWork()
+ {
+   // here is where a useful object would do something
+   privateBool=publicInt<20;
+ }
+
+ ~HeapObject(){}
+
+ private:
+
+  // PUP is orthogonal to public vs private member choices
+  bool privateBool;
+  std::vector<float> data;
+};
diff --git a/examples/charm++/PUP/STLPUP/Makefile b/examples/charm++/PUP/STLPUP/Makefile
new file mode 100644 (file)
index 0000000..3de42c1
--- /dev/null
@@ -0,0 +1,24 @@
+CHARMC=../../../../bin/charmc $(OPTS)
+
+OBJS = SimplePUP.o
+
+all: SimplePUP
+
+SimplePUP: $(OBJS)
+       $(CHARMC) -language charm++ -o SimplePUP $(OBJS)
+
+SimplePUP.decl.h: SimplePUP.ci
+       $(CHARMC)  SimplePUP.ci
+
+clean:
+       rm -f *.decl.h *.def.h conv-host *.o SimplePUP charmrun
+
+SimplePUP.o: SimplePUP.C SimplePUP.h HeapObjectSTL.h SimplePUP.decl.h
+       $(CHARMC) -c SimplePUP.C
+
+test: all
+       ./charmrun SimplePUP +p4  $(TESTOPTS)
+       ./charmrun SimplePUP +p4  $(TESTOPTS)
+
+bgtest: all
+       ./charmrun SimplePUP +p4 +x2 +y2 +z1
diff --git a/examples/charm++/PUP/STLPUP/SimplePUP.C b/examples/charm++/PUP/STLPUP/SimplePUP.C
new file mode 100644 (file)
index 0000000..e7c9923
--- /dev/null
@@ -0,0 +1,26 @@
+/////////////////////////////////////
+//
+//  SimplePUP.C
+//
+//  Definition of chares in SimplePUP
+//
+//  Author: Eric Bohm
+//  Date: 2012/7/30
+//
+/////////////////////////////////////
+
+#include "SimplePUP.h"
+
+main::main(CkArgMsg *m)
+{
+ //normal object construction
+  HeapObject exampleObject(20,false);
+
+  //normal chare array construction
+  CProxy_SimpleArray simpleProxy= CProxy_SimpleArray::ckNew(30);
+
+  //pass object to remote method invocation on the chare array
+  simpleProxy[29].acceptData(exampleObject);
+}
+
+#include "SimplePUP.def.h"
diff --git a/examples/charm++/PUP/STLPUP/SimplePUP.ci b/examples/charm++/PUP/STLPUP/SimplePUP.ci
new file mode 100644 (file)
index 0000000..8857e20
--- /dev/null
@@ -0,0 +1,23 @@
+////////////////////////////////////////////////
+//
+//  SimplePUP.ci
+//
+//  Interface file for SimplePUP
+//
+//  Author: Eric Bohm
+//  Date: 2012/7/30
+//
+////////////////////////////////////////////////
+
+mainmodule SimplePUP {
+  include "HeapObjectSTL.h";
+  mainchare main {
+    entry main(CkArgMsg *m);
+  };
+
+  array [1D] SimpleArray{
+    entry SimpleArray();
+    entry void acceptData(HeapObject &inData);
+  };
+
+};
diff --git a/examples/charm++/PUP/STLPUP/SimplePUP.h b/examples/charm++/PUP/STLPUP/SimplePUP.h
new file mode 100644 (file)
index 0000000..95735bd
--- /dev/null
@@ -0,0 +1,61 @@
+///////////////////////////////////////
+//
+//  SimplePUP.h  
+//
+//  Declaration of chares in SimplePUP
+//
+//  Author: Eric Bohm
+//  Date: 2012/01/23
+//
+///////////////////////////////////////
+
+#include "SimplePUP.decl.h"
+
+class main : public CBase_main {
+
+public:
+
+  main(CkMigrateMessage *m) {}
+
+  main(CkArgMsg *m);
+
+};
+
+
+class SimpleArray : public CBase_SimpleArray {
+
+ public:
+  
+  SimpleArray(CkMigrateMessage *m) {}
+
+  SimpleArray(){}
+
+  void done(){
+    CkPrintf("done int %d\n",localCopy.publicInt);
+    CkExit();
+  }
+
+  ~SimpleArray(){}
+
+  void acceptData(HeapObject &inData){
+
+    //do something to the object
+    localCopy=inData;
+    localCopy.doWork();
+
+    if(thisIndex==0) //no one lower to pass to
+      {
+       done();
+      }
+    else
+      { // pass object down one index
+       thisProxy[thisIndex-1].acceptData(localCopy);
+      }
+  }
+
+ private:
+
+  HeapObject localCopy;
+
+};
+