2
//@+node:gcross.20081014213606.10:@thin cleanroom.C
8
cleanroom::cleanroom(CkArgMsg *m) {
10
CProxy_cleanroom self(thishandle);
17
void cleanroom::start() {
20
//@+node:gcross.20081014213606.11:<< Play >>
21
// Create a 2x3x4 rank 3 array distributed among 6 array elements.
22
DistributedArray<int,3> vec(6,2,3,4);
27
// Create a local 2x3x4 array.
28
Array<int,3> x(2,3,4);
31
// Populate the array.
41
// Scatter the array among the elements.
45
// Add 1 to all elements.
48
// Negate all elements.
51
// Retrieve and print (0,0,0), which should be = -2.
52
cout << "0,0,0 = " << (int)vec(0,0,0) << endl;
55
// Negate every other element
56
for(int i = 0; i < 2; i++)
57
for(int j = 0; j < 3; j++)
58
for(int k = 0; k < 4; k += 2)
61
// NOTE: The above code is really inefficient since it sends out a
62
// separate message for each position in the array! In the future I plan
63
// to implement slice objects which will let you do this with something
66
// vec(Range::all,Range::all,Range(0,4,2)) *= -1;
68
// which will only send out a single message to each Charm++ array element
69
// telling it how to act on its segment of the distributed array.
73
// Add 10 to everything.
76
// Compute the absolute value of all elements.
79
// Gather the array back up and print it out.
81
cout << "x=" << x << endl;
86
//@-node:gcross.20081014213606.11:<< Play >>
94
#include "cleanroom.def.h"
96
//@-node:gcross.20081014213606.10:@thin cleanroom.C