ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change
on this file since 90cb6f7 was
2e457d8,
checked in by Peter A. Buhr <pabuhr@…>, 6 years ago
|
formatting
|
-
Property mode set to
100644
|
File size:
1.5 KB
|
Rev | Line | |
---|
[73abe95] | 1 | // |
---|
[d6655bd] | 2 | // Cforall Version 1.0.0 Copyright (C) 2017 University of Waterloo |
---|
| 3 | // |
---|
| 4 | // The contents of this file are covered under the licence agreement in the |
---|
| 5 | // file "LICENCE" distributed with Cforall. |
---|
[73abe95] | 6 | // |
---|
[dc8511c] | 7 | // matrixSum.cfa -- |
---|
[73abe95] | 8 | // |
---|
[d6655bd] | 9 | // Author : Peter A. Buhr |
---|
| 10 | // Created On : Mon Oct 9 08:29:28 2017 |
---|
| 11 | // Last Modified By : Peter A. Buhr |
---|
[2e457d8] | 12 | // Last Modified On : Wed Feb 20 08:37:53 2019 |
---|
| 13 | // Update Count : 16 |
---|
[73abe95] | 14 | // |
---|
[d6655bd] | 15 | |
---|
[73abe95] | 16 | #include <fstream.hfa> |
---|
| 17 | #include <kernel.hfa> |
---|
| 18 | #include <thread.hfa> |
---|
[b8a17e2] | 19 | |
---|
| 20 | thread Adder { |
---|
[c107f4ec] | 21 | int * row, cols, & subtotal; // communication |
---|
[b8a17e2] | 22 | }; |
---|
| 23 | |
---|
| 24 | void ?{}( Adder & adder, int row[], int cols, int & subtotal ) { |
---|
[c107f4ec] | 25 | adder.[ row, cols ] = [ row, cols ]; // expression disallowed in multi-member access |
---|
| 26 | &adder.subtotal = &subtotal; |
---|
[b8a17e2] | 27 | } |
---|
| 28 | |
---|
[c107f4ec] | 29 | void main( Adder & adder ) with( adder ) { // thread starts here |
---|
| 30 | subtotal = 0; |
---|
[8f34661] | 31 | for ( c; cols ) { |
---|
[c107f4ec] | 32 | subtotal += row[c]; |
---|
| 33 | } // for |
---|
[b8a17e2] | 34 | } |
---|
| 35 | |
---|
| 36 | int main() { |
---|
[8f34661] | 37 | /* const */ int rows = 10, cols = 1000; |
---|
[c107f4ec] | 38 | int matrix[rows][cols], subtotals[rows], total = 0; |
---|
| 39 | processor p; // add kernel thread |
---|
[b8a17e2] | 40 | |
---|
[8f34661] | 41 | for ( r; rows ) { |
---|
| 42 | for ( c; cols ) { |
---|
[9f865d1] | 43 | matrix[r][c] = 1; |
---|
| 44 | } // for |
---|
[c107f4ec] | 45 | } // for |
---|
| 46 | Adder * adders[rows]; |
---|
[8f34661] | 47 | for ( r; rows ) { // start threads to sum rows |
---|
[9f865d1] | 48 | adders[r] = &(*malloc()){ matrix[r], cols, subtotals[r] }; |
---|
| 49 | // adders[r] = new( matrix[r], cols, &subtotals[r] ); |
---|
[c107f4ec] | 50 | } // for |
---|
[8f34661] | 51 | for ( r; rows ) { // wait for threads to finish |
---|
[9f865d1] | 52 | delete( adders[r] ); |
---|
| 53 | total += subtotals[r]; // total subtotals |
---|
[c107f4ec] | 54 | } // for |
---|
[200fcb3] | 55 | sout | total; |
---|
[b8a17e2] | 56 | } |
---|
[d6655bd] | 57 | |
---|
| 58 | // Local Variables: // |
---|
| 59 | // tab-width: 4 // |
---|
[dc8511c] | 60 | // compile-command: "cfa matrixSum.cfa" // |
---|
[d6655bd] | 61 | // End: // |
---|
Note: See
TracBrowser
for help on using the repository browser.