New example code with two arrays executing at the same time.
authorChee Wai Lee <cheelee@illinois.edu>
Mon, 22 Oct 2007 23:27:56 +0000 (23:27 +0000)
committerChee Wai Lee <cheelee@illinois.edu>
Mon, 22 Oct 2007 23:27:56 +0000 (23:27 +0000)
examples/charm++/hello/3dmultiarrays/Makefile [new file with mode: 0644]
examples/charm++/hello/3dmultiarrays/README [new file with mode: 0644]
examples/charm++/hello/3dmultiarrays/hello.C [new file with mode: 0644]
examples/charm++/hello/3dmultiarrays/hello.ci [new file with mode: 0644]

diff --git a/examples/charm++/hello/3dmultiarrays/Makefile b/examples/charm++/hello/3dmultiarrays/Makefile
new file mode 100644 (file)
index 0000000..5a547fb
--- /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
+
+bgtest: all
+       ./charmrun hello +p4 10 +x2 +y2 +z2
diff --git a/examples/charm++/hello/3dmultiarrays/README b/examples/charm++/hello/3dmultiarrays/README
new file mode 100644 (file)
index 0000000..9ece0b6
--- /dev/null
@@ -0,0 +1,9 @@
+Hello World in Charm with two 3D Arrays.
+
+Similar to the 3darrays except that this demonstrates 2 3D chare
+arrays running simultaneously. This example was primarily created to
+test that array ids are properly assigned to multiple arrays in the
+same charm++ application.
+
+
+
diff --git a/examples/charm++/hello/3dmultiarrays/hello.C b/examples/charm++/hello/3dmultiarrays/hello.C
new file mode 100644 (file)
index 0000000..8952356
--- /dev/null
@@ -0,0 +1,102 @@
+#include <stdio.h>
+#include "hello.decl.h"
+
+/*readonly*/ CProxy_Main mainProxy;
+/*readonly*/ int nElements;
+
+/*mainchare*/
+class Main : public CBase_Main
+{
+public:
+  int count;
+  Main(CkArgMsg* m)
+  {
+    count = 2;
+    //Process command-line arguments
+    nElements=5;
+    if(m->argc >1 ) nElements=atoi(m->argv[1]);
+    delete m;
+
+    //Start the computation
+    CkPrintf("Running Hello on %d processors for %d elements\n",
+            CkNumPes(),nElements);
+    mainProxy = thisProxy;
+
+    //Allocate elements scattered down a sparse 3D line
+    CProxy_Hello arr = CProxy_Hello::ckNew();
+    for (int y=0;y<nElements;y++)
+        arr(37,y,2*y+1).insert();
+    arr.doneInserting();
+
+    CProxy_Hello2 arr2 = CProxy_Hello2::ckNew();
+    for (int y=0;y<nElements;y++)
+        arr2(37,y,2*y+1).insert();
+    arr2.doneInserting();
+
+    arr(37,0,1).SayHi(17);
+    arr2(37,0,1).SayHi2(17);
+  };
+
+  void done(void)
+  {
+    count--;
+    if (count == 0) {
+      CkPrintf("All done\n");
+      CkExit();
+    }
+  };
+};
+
+/*array [3D]*/
+class Hello : public CBase_Hello
+{
+public:
+  Hello()
+  {
+    CkPrintf("Hello %d created\n",thisIndex.y);
+  }
+
+  Hello(CkMigrateMessage *m) {}
+  
+  void SayHi(int hiNo)
+  {
+    CkPrintf("Hi[%d] from element (%d,%d,%d)\n",hiNo,
+       thisIndex.x,thisIndex.y,thisIndex.z);
+    int y=thisIndex.y+1;
+    if (y < nElements) {
+      //Pass the hello on:
+      thisProxy(37,y,2*y+1).SayHi(hiNo+1);
+    }
+    else 
+      //We've been around once-- we're done.
+      mainProxy.done();
+  }
+};
+
+/*array [3D]*/
+class Hello2 : public CBase_Hello2
+{
+public:
+  Hello2()
+  {
+    CkPrintf("Hello2 %d created\n",thisIndex.y);
+  }
+
+  Hello2(CkMigrateMessage *m) {}
+  
+  void SayHi2(int hiNo)
+  {
+    CkPrintf("Hi 2 [%d] from element (%d,%d,%d)\n",hiNo,
+       thisIndex.x,thisIndex.y,thisIndex.z);
+    int y=thisIndex.y+1;
+    if (y < nElements) {
+      //Pass the hello on:
+      thisProxy(37,y,2*y+1).SayHi2(hiNo+1);
+    }
+    else 
+      //We've been around once-- we're done.
+      mainProxy.done();
+  }
+};
+
+#include "hello.def.h"
diff --git a/examples/charm++/hello/3dmultiarrays/hello.ci b/examples/charm++/hello/3dmultiarrays/hello.ci
new file mode 100644 (file)
index 0000000..b015c3c
--- /dev/null
@@ -0,0 +1,19 @@
+mainmodule hello {
+  readonly CProxy_Main mainProxy;
+  readonly int nElements;
+
+  mainchare Main {
+    entry Main(CkArgMsg *m);
+    entry void done(void);
+  };
+
+  array [3D] Hello {
+    entry Hello(void);
+    entry void SayHi(int hiNo);
+  };           
+
+  array [3D] Hello2 {
+    entry Hello2(void);
+    entry void SayHi2(int hiNo);
+  };           
+};