An example for 2D array sections, and its usage 68/4568/5
authorraghavendrak <raghavendra066@gmail.com>
Wed, 12 Sep 2018 20:08:54 +0000 (15:08 -0500)
committerSam White <white67@illinois.edu>
Sun, 16 Sep 2018 19:44:07 +0000 (14:44 -0500)
Change-Id: I616cd280d7c6bf2a35b0cdfb84ccd2e4f50bbd03

doc/charm++/sections.tex
examples/charm++/arraysection/Makefile
examples/charm++/arraysection/check1d.C [moved from examples/charm++/arraysection/check.C with 97% similarity]
examples/charm++/arraysection/check1d.ci [moved from examples/charm++/arraysection/check.ci with 94% similarity]
examples/charm++/arraysection/check2d.C [new file with mode: 0644]
examples/charm++/arraysection/check2d.ci [new file with mode: 0644]

index 0b5d25c9d7335dc320d1ffd4978974c25ec08ce1..b2667e5f2320e9d5f4c05ce475411eacf67f4315 100644 (file)
@@ -91,15 +91,14 @@ If the section is created from inside an array element there is no such risk.
 \label {array_section_multicast}
 
 Once the proxy is obtained at section creation time, the user can broadcast to all the
-section members, or send messages to one member using its offset index within the section, like this:
+section members, like this:
 
 \begin{alltt}
   CProxySection_Hello proxy;
   proxy.someEntry(...)          // section broadcast
-  proxy[0].someEntry(...)       // send to the first element in the section
 \end{alltt}
 
-See examples/charm++/arraysection for an example on how sections are used.
+See examples/charm++/arraysection for examples on how sections are used.
 
 You can send the section proxy in a message to another processor, and still
 safely invoke the entry functions on the section proxy.
index 2b90e2963bb2cd717afdf7d6493e52cba0a5c00b..cf607a7a029201a0e0ad9bd7eca165756cc1385e 100644 (file)
@@ -1,20 +1,30 @@
 -include ../../common.mk
 CHARMC=../../../bin/charmc $(OPTS)
 
-all: check
+all: check1d check2d
 
-check: check.o
-       $(CHARMC) $(OPTS) -language charm++ -o check check.o 
+check1d: check1d.o
+       $(CHARMC) $(OPTS) -language charm++ -o check1d check1d.o
 
-check.o: check.C check.decl.h
-       $(CHARMC) $(OPTS) -language charm++ -o check.o check.C 
+check1d.o: check1d.C check1d.decl.h
+       $(CHARMC) $(OPTS) -language charm++ -o check1d.o check1d.C
 
+check1d.decl.h: check1d.ci
+       $(CHARMC) $(OPTS) -language charm++ check1d.ci
 
-check.decl.h: check.ci
-       $(CHARMC) $(OPTS) -language charm++ check.ci
+check2d: check2d.o
+       $(CHARMC) $(OPTS) -language charm++ -o check2d check2d.o
 
-test: check
-       $(call run, +p4 ./check 20 )
+check2d.o: check2d.C check2d.decl.h
+       $(CHARMC) $(OPTS) -language charm++ -o check2d.o check2d.C
+
+check2d.decl.h: check2d.ci
+       $(CHARMC) $(OPTS) -language charm++ check2d.ci
+
+
+test: check1d check2d
+       $(call run, +p4 ./check1d 20 )
+       $(call run, +p4 ./check2d 20 20)
 
 clean:
-       rm -f *.decl.h *.def.h *.o check charmrun
+       rm -f *.decl.h *.def.h *.o check1d check2d charmrun
similarity index 97%
rename from examples/charm++/arraysection/check.C
rename to examples/charm++/arraysection/check1d.C
index 3af428effb99d6dda1f4462612ac916713750893..b6b63e7d75709e28bb1d4ffdd0cc26b0938e1062 100644 (file)
@@ -1,5 +1,5 @@
 #include <math.h>
-#include "check.decl.h"
+#include "check1d.decl.h"
 #include "ckmulticast.h"
 
 /* readonly */ CProxy_Main mainProxy;
@@ -80,4 +80,4 @@ public:
        }
 };
 
-#include "check.def.h"
+#include "check1d.def.h"
similarity index 94%
rename from examples/charm++/arraysection/check.ci
rename to examples/charm++/arraysection/check1d.ci
index 42344a6a8c6a7778e5e9a1d7c54c24e136c67f30..25a59d20ab8a4f2c0a05ec7c1a73eb41f02e7a4c 100644 (file)
@@ -1,4 +1,4 @@
-mainmodule check {
+mainmodule check1d {
 
        readonly CProxy_Main mainProxy;
        readonly CProxy_Check checkArray;
diff --git a/examples/charm++/arraysection/check2d.C b/examples/charm++/arraysection/check2d.C
new file mode 100644 (file)
index 0000000..27465a7
--- /dev/null
@@ -0,0 +1,83 @@
+#include <math.h>
+#include "check2d.decl.h"
+#include "ckmulticast.h"
+
+/* readonly */ CProxy_Main mainProxy;
+/* readonly */ CProxy_Check checkArray;
+/* readonly */ int numchares_x;
+/* readonly */ int numchares_y;
+
+struct sectionBcastMsg : public CkMcastBaseMsg, public CMessage_sectionBcastMsg {
+       int k;
+       sectionBcastMsg(int _k) : k(_k) {}
+       void pup(PUP::er &p) {
+               CMessage_sectionBcastMsg::pup(p);
+               p|k;
+       }
+};
+
+class Main : public CBase_Main {
+       int sum;
+
+public:
+       Main(CkArgMsg* msg) {
+               if (msg->argc < 3) {
+                       ckout << "Usage: " << msg->argv[0] << " [number of x_chares] [number of y_chares]" << endl;
+                       CkExit(1);
+               }
+               numchares_x = atoi(msg->argv[1]);
+               numchares_y = atoi(msg->argv[2]);
+               ckout << "Numchares_x: " << numchares_x << " Numchares_y: " << numchares_y << endl;
+               sum = 0;
+               mainProxy = thisProxy;
+               checkArray = CProxy_Check::ckNew(numchares_x, numchares_y);
+               checkArray.createSection();
+       }
+
+       void done1It(int q, int output[]) {
+               CkAssert(q == 2);
+               int expected[2];
+               int n_x = ((numchares_x - 1) % 2 == 0) ? (numchares_x - 1) : (numchares_x - 2);
+               int n_y = ((numchares_y - 1) % 2 == 0) ? (numchares_y - 1) : (numchares_y - 2);
+               int sumofIndices_x = n_x * (n_x + 2) / 4;  // even numbered chares are part of the section
+               int sumofIndices_y = n_y * (n_y + 2) / 4;
+               expected[0] = sumofIndices_x * ceil(numchares_y / 2.0);
+               expected[1] = sumofIndices_y * ceil(numchares_x / 2.0);
+               CkAssert((output[0] - expected[0]) == 0);
+               CkAssert((output[1] - expected[1]) == 0);
+               ckout << "Vector reduction: " << output[0] << " " << output[1] << endl;
+               ckout << "Test passed successfully" << endl;
+               CkExit();
+       }
+};
+
+class Check : public CBase_Check {
+       CProxySection_Check secProxy;
+
+public:
+       Check() {}
+
+       void createSection() {
+               if (thisIndex.x == 0 && thisIndex.y == 0) {
+                       // Use index range to create a section [lbound:ubound:stride]
+                       secProxy = CProxySection_Check::ckNew(checkArray.ckGetArrayID(), 0, numchares_x - 1, 2, 0, numchares_y - 1, 2);
+                       sectionBcastMsg *msg = new sectionBcastMsg(0);
+                       secProxy.recvMsg(msg);
+               }
+       }
+
+       void recvMsg(sectionBcastMsg *msg) {
+               ckout << "ArrayIndex: [" << thisIndex.x << ", " << thisIndex.y << "] - " << CkMyPe() << endl;
+               int k = msg->k;
+               std::vector<int> outVals(2);
+               outVals[0] = k + thisIndex.x;
+               outVals[1] = k + thisIndex.y;
+               CkSectionInfo cookie;
+               CkGetSectionInfo(cookie, msg);
+               CkCallback cb(CkReductionTarget(Main, done1It), mainProxy);
+               CProxySection_Check::contribute(outVals, CkReduction::sum_int, cookie, cb);
+               delete msg;
+       }
+};
+
+#include "check2d.def.h"
diff --git a/examples/charm++/arraysection/check2d.ci b/examples/charm++/arraysection/check2d.ci
new file mode 100644 (file)
index 0000000..0a61fcc
--- /dev/null
@@ -0,0 +1,20 @@
+mainmodule check2d {
+
+       readonly CProxy_Main mainProxy;
+       readonly CProxy_Check checkArray;
+       readonly int numchares_x;
+       readonly int numchares_y;
+
+       message sectionBcastMsg;
+
+       mainchare Main {
+               entry [nokeep] Main(CkArgMsg* msg);
+               entry [reductiontarget] void done1It(int q, int output[q]);
+       };
+
+       array[2D] Check {
+               entry Check();
+               entry void createSection();
+               entry void recvMsg(sectionBcastMsg *msg);
+       };
+};