2 #include "check2d.decl.h"
3 #include "ckmulticast.h"
5 /* readonly */ CProxy_Main mainProxy;
6 /* readonly */ CProxy_Check checkArray;
7 /* readonly */ int numchares_x;
8 /* readonly */ int numchares_y;
10 struct sectionBcastMsg : public CkMcastBaseMsg, public CMessage_sectionBcastMsg {
12 sectionBcastMsg(int _k) : k(_k) {}
13 void pup(PUP::er &p) {
14 CMessage_sectionBcastMsg::pup(p);
19 class Main : public CBase_Main {
25 ckout << "Usage: " << msg->argv[0] << " [number of x_chares] [number of y_chares]" << endl;
28 numchares_x = atoi(msg->argv[1]);
29 numchares_y = atoi(msg->argv[2]);
30 ckout << "Numchares_x: " << numchares_x << " Numchares_y: " << numchares_y << endl;
32 mainProxy = thisProxy;
33 checkArray = CProxy_Check::ckNew(numchares_x, numchares_y);
34 checkArray.createSection();
37 void done1It(int q, int output[]) {
40 int n_x = ((numchares_x - 1) % 2 == 0) ? (numchares_x - 1) : (numchares_x - 2);
41 int n_y = ((numchares_y - 1) % 2 == 0) ? (numchares_y - 1) : (numchares_y - 2);
42 int sumofIndices_x = n_x * (n_x + 2) / 4; // even numbered chares are part of the section
43 int sumofIndices_y = n_y * (n_y + 2) / 4;
44 expected[0] = sumofIndices_x * ceil(numchares_y / 2.0);
45 expected[1] = sumofIndices_y * ceil(numchares_x / 2.0);
46 CkAssert((output[0] - expected[0]) == 0);
47 CkAssert((output[1] - expected[1]) == 0);
48 ckout << "Vector reduction: " << output[0] << " " << output[1] << endl;
49 ckout << "Test passed successfully" << endl;
54 class Check : public CBase_Check {
55 CProxySection_Check secProxy;
60 void createSection() {
61 if (thisIndex.x == 0 && thisIndex.y == 0) {
62 // Use index range to create a section [lbound:ubound:stride]
63 secProxy = CProxySection_Check::ckNew(checkArray.ckGetArrayID(), 0, numchares_x - 1, 2, 0, numchares_y - 1, 2);
64 sectionBcastMsg *msg = new sectionBcastMsg(0);
65 secProxy.recvMsg(msg);
69 void recvMsg(sectionBcastMsg *msg) {
70 ckout << "ArrayIndex: [" << thisIndex.x << ", " << thisIndex.y << "] - " << CkMyPe() << endl;
72 std::vector<int> outVals(2);
73 outVals[0] = k + thisIndex.x;
74 outVals[1] = k + thisIndex.y;
76 CkGetSectionInfo(cookie, msg);
77 CkCallback cb(CkReductionTarget(Main, done1It), mainProxy);
78 CProxySection_Check::contribute(outVals, CkReduction::sum_int, cookie, cb);
83 #include "check2d.def.h"