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