~gcrosswhite/charon/projects-BLACS

« back to all changes in this revision

Viewing changes to cleanroom.C

  • Committer: Gregory Crosswhite
  • Date: 2009-04-15 02:44:32 UTC
  • Revision ID: gcross@phys.washington.edu-20090415024432-mxygsxycufgosfcl
Finished clearing out all of the files that have been split into other branches.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//@+leo-ver=4-thin
2
 
//@+node:gcross.20081014213606.10:@thin cleanroom.C
3
 
//@@language C++
4
 
 
5
 
 
6
 
#include "cleanroom.h"
7
 
 
8
 
cleanroom::cleanroom(CkArgMsg *m) {
9
 
    delete m;
10
 
    CProxy_cleanroom self(thishandle);
11
 
    self.start();
12
 
}
13
 
 
14
 
#include <unistd.h>
15
 
 
16
 
 
17
 
void cleanroom::start() {
18
 
 
19
 
    //@    << Play >>
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);
23
 
 
24
 
    vec = 0;
25
 
 
26
 
 
27
 
    // Create a local 2x3x4 array.
28
 
    Array<int,3> x(2,3,4);
29
 
 
30
 
 
31
 
    // Populate the array.
32
 
    x = 1, 2, 3, 4,
33
 
        5, 6, 7, 8,
34
 
        9,10,11,12,
35
 
 
36
 
        -1,-2,-3,-5,
37
 
        -7,-9,-11,-13,
38
 
        -17,-19,-23,-29,
39
 
        -31,-37,-41,-43;
40
 
 
41
 
    // Scatter the array among the elements.
42
 
    vec = x;
43
 
 
44
 
 
45
 
    // Add 1 to all elements.
46
 
    vec++;
47
 
 
48
 
    // Negate all elements.
49
 
    vec *= -1;
50
 
 
51
 
    // Retrieve and print (0,0,0), which should be = -2.
52
 
    cout << "0,0,0 = " << (int)vec(0,0,0) << endl;
53
 
 
54
 
 
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)
59
 
                vec(i,j,k) *= -1;
60
 
    //@+at
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 
64
 
    // like
65
 
    // 
66
 
    // vec(Range::all,Range::all,Range(0,4,2)) *= -1;
67
 
    // 
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.
70
 
    //@-at
71
 
    //@@c
72
 
 
73
 
    // Add 10 to everything.
74
 
    vec += 10;
75
 
 
76
 
    // Compute the absolute value of all elements.
77
 
    vec.abs();
78
 
 
79
 
    // Gather the array back up and print it out.
80
 
    vec.gatherInto(x);
81
 
    cout << "x=" << x << endl;
82
 
 
83
 
 
84
 
    CkExit();
85
 
    //@nonl
86
 
    //@-node:gcross.20081014213606.11:<< Play >>
87
 
    //@nl
88
 
 
89
 
}
90
 
 
91
 
//@+others
92
 
//@-others
93
 
 
94
 
#include "cleanroom.def.h"
95
 
 
96
 
//@-node:gcross.20081014213606.10:@thin cleanroom.C
97
 
//@-leo