add a 1d array example with msgs
authorYanhuaSun <sun51@illinois.edu>
Mon, 28 Jan 2013 22:23:33 +0000 (16:23 -0600)
committerYanhuaSun <sun51@illinois.edu>
Mon, 28 Jan 2013 22:23:33 +0000 (16:23 -0600)
examples/charm++/hello/1darraymsg/Makefile [new file with mode: 0644]
examples/charm++/hello/1darraymsg/README [new file with mode: 0644]
examples/charm++/hello/1darraymsg/hello.C [new file with mode: 0644]
examples/charm++/hello/1darraymsg/hello.ci [new file with mode: 0644]

diff --git a/examples/charm++/hello/1darraymsg/Makefile b/examples/charm++/hello/1darraymsg/Makefile
new file mode 100644 (file)
index 0000000..a2cd44a
--- /dev/null
@@ -0,0 +1,23 @@
+CHARMC=../../../../bin/charmc $(OPTS)
+
+OBJS = hello.o
+
+all: hello
+
+hello: $(OBJS)
+       $(CHARMC) -language charm++ -o hello $(OBJS)
+
+hello.decl.h: hello.ci
+       $(CHARMC)  hello.ci
+
+clean:
+       rm -f *.decl.h *.def.h conv-host *.o hello charmrun
+
+hello.o: hello.C hello.decl.h
+       $(CHARMC) -c hello.C
+
+test: all
+       ./charmrun hello +p4 10 $(TESTOPTS)
+
+bgtest: all
+       ./charmrun hello +p4 10 +x2 +y2 +z1 $(TESTOPTS)
diff --git a/examples/charm++/hello/1darraymsg/README b/examples/charm++/hello/1darraymsg/README
new file mode 100644 (file)
index 0000000..60c4c3b
--- /dev/null
@@ -0,0 +1,7 @@
+Hello World in Charm with a Chare Array.
+
+Demonstrates basic chare array creation and use.  The Hi message is
+passed along the array from 0th to Nth.  Illustrates output
+nondeterminism as an interesting side effect.
+
+
diff --git a/examples/charm++/hello/1darraymsg/hello.C b/examples/charm++/hello/1darraymsg/hello.C
new file mode 100644 (file)
index 0000000..6de4a40
--- /dev/null
@@ -0,0 +1,68 @@
+#include <stdio.h>
+#include "hello.decl.h"
+
+/*readonly*/ CProxy_Main mainProxy;
+/*readonly*/ int nElements;
+/*readonly*/ int msgSize;
+
+/*mainchare*/
+class dataMsg : public CMessage_dataMsg {
+
+public :
+    char *data;
+};
+class Main : public CBase_Main
+{
+    double startTimer;
+    int back;
+public:
+  Main(CkArgMsg* m)
+  {
+    //Process command-line arguments
+    nElements=5;
+    msgSize = 2048;
+    if(m->argc >1 ) nElements=atoi(m->argv[1]);
+    if(m->argc >2 ) msgSize =atoi(m->argv[2]);
+    delete m;
+
+    //Start the computation
+    CkPrintf("Running Hello on %d processors for %d elements\n",
+            CkNumPes(),nElements);
+    mainProxy = thisProxy;
+    back = 0;
+    
+    CProxy_Hello arr = CProxy_Hello::ckNew(nElements);
+    dataMsg *datamsg = new (msgSize) dataMsg();
+    startTimer = CmiWallTimer();
+    arr.SayHi(datamsg);
+  };
+
+  void done(void)
+  {
+      back++;
+      if(back == nElements)
+          CkPrintf("All done %d %d  cost  %lf \n", nElements, msgSize, CmiWallTimer()-startTimer);
+    CkExit();
+  };
+};
+
+/*array [1D]*/
+class Hello : public CBase_Hello
+{
+public:
+  Hello()
+  {
+    CkPrintf("Hello %d created\n",thisIndex);
+  }
+
+  Hello(CkMigrateMessage *m) {}
+  
+  void SayHi(dataMsg *dm)
+  {
+    CkPrintf("Hi[%d] from element \n",thisIndex);
+    delete dm;  
+    mainProxy.done();
+  }
+};
+
+#include "hello.def.h"
diff --git a/examples/charm++/hello/1darraymsg/hello.ci b/examples/charm++/hello/1darraymsg/hello.ci
new file mode 100644 (file)
index 0000000..42280b2
--- /dev/null
@@ -0,0 +1,20 @@
+mainmodule hello {
+  readonly CProxy_Main mainProxy;
+  readonly int nElements;
+  readonly int msgSize;
+
+  mainchare Main {
+    entry Main(CkArgMsg *m);
+    entry void done(void);
+  };
+    
+  message dataMsg
+  {
+      char  data[];
+  };
+
+  array [1D] Hello {
+    entry Hello(void);
+    entry void SayHi(dataMsg*);
+  };           
+};