SimplePUP variant with an object containing heap data
authorEric Bohm <ebohm@illinois.edu>
Tue, 31 Jul 2012 22:38:56 +0000 (17:38 -0500)
committerEric Bohm <ebohm@illinois.edu>
Tue, 31 Jul 2012 23:51:33 +0000 (18:51 -0500)
examples/charm++/PUP/HeapPUP/HeapObject.h [new file with mode: 0644]
examples/charm++/PUP/HeapPUP/Makefile [new file with mode: 0644]
examples/charm++/PUP/HeapPUP/SimplePUP.C [new file with mode: 0644]
examples/charm++/PUP/HeapPUP/SimplePUP.ci [new file with mode: 0644]
examples/charm++/PUP/HeapPUP/SimplePUP.h [new file with mode: 0644]

diff --git a/examples/charm++/PUP/HeapPUP/HeapObject.h b/examples/charm++/PUP/HeapPUP/HeapObject.h
new file mode 100644 (file)
index 0000000..f27e79a
--- /dev/null
@@ -0,0 +1,43 @@
+class HeapObject
+{
+
+ public:
+
+  int publicInt;
+
+ HeapObject(int param1, bool param2):publicInt(param1), privateBool(param2) {data=new float[publicInt];}
+
+ HeapObject():publicInt(0), privateBool(false) {data=NULL;}
+ void pup(PUP::er &p)
+ {
+   // remember to pup your superclass if there is one
+   p|publicInt;
+   p|privateBool;
+   if(p.isUnpacking())
+     data=new float[publicInt];
+   PUParray(p,data,publicInt);
+ }
+ inline HeapObject &operator=(const HeapObject &indata) {
+    if(data && publicInt>0) delete [] data;
+    publicInt=indata.publicInt;
+    privateBool=indata.privateBool;
+    if(publicInt>0)  data=new float[publicInt];
+    for(int i=0; i<publicInt; ++i) data[i]=indata.data[i];
+    return *this;
+  }
+
+
+ void doWork()
+ {
+   // here is where a useful object would do something
+   privateBool=publicInt<20;
+ }
+
+ ~HeapObject(){if(publicInt>0) delete [] data;}
+
+ private:
+
+  // PUP is orthogonal to public vs private member choices
+  bool privateBool;
+  float *data;
+};
diff --git a/examples/charm++/PUP/HeapPUP/Makefile b/examples/charm++/PUP/HeapPUP/Makefile
new file mode 100644 (file)
index 0000000..88ba825
--- /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 HeapObject.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/HeapPUP/SimplePUP.C b/examples/charm++/PUP/HeapPUP/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/HeapPUP/SimplePUP.ci b/examples/charm++/PUP/HeapPUP/SimplePUP.ci
new file mode 100644 (file)
index 0000000..20f1073
--- /dev/null
@@ -0,0 +1,23 @@
+////////////////////////////////////////////////
+//
+//  SimplePUP.ci
+//
+//  Interface file for SimplePUP
+//
+//  Author: Eric Bohm
+//  Date: 2012/7/30
+//
+////////////////////////////////////////////////
+
+mainmodule SimplePUP {
+  include "HeapObject.h";
+  mainchare main {
+    entry main(CkArgMsg *m);
+  };
+
+  array [1D] SimpleArray{
+    entry SimpleArray();
+    entry void acceptData(HeapObject &inData);
+  };
+
+};
diff --git a/examples/charm++/PUP/HeapPUP/SimplePUP.h b/examples/charm++/PUP/HeapPUP/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;
+
+};
+