- File:
-
- 1 edited
-
src/tests/concurrent/examples/matrixSum.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/tests/concurrent/examples/matrixSum.c
rc107f4ec r971d9f2 11 11 // Created On : Mon Oct 9 08:29:28 2017 12 12 // Last Modified By : Peter A. Buhr 13 // Last Modified On : Fri May 25 09:34:27 201814 // Update Count : 1013 // Last Modified On : Tue Dec 5 22:56:46 2017 14 // Update Count : 4 15 15 // 16 16 … … 20 20 21 21 thread Adder { 22 int * row, cols, &subtotal; // communication22 int * row, cols, * subtotal; // communication 23 23 }; 24 24 25 25 void ?{}( Adder & adder, int row[], int cols, int & subtotal ) { 26 adder.[ row, cols ] = [ row, cols ]; // expression disallowed in multi-member access 27 &adder.subtotal = &subtotal; 26 adder.row = row; 27 adder.cols = cols; 28 adder.subtotal = &subtotal; 28 29 } 29 30 30 void main( Adder & adder ) with( adder ) { // thread starts here31 subtotal = 0;32 for ( int c = 0; c < cols; c += 1 ) {33 subtotal += row[c];34 } // for31 void main( Adder & adder ) with( adder ) { 32 *subtotal = 0; 33 for ( int c = 0; c < cols; c += 1 ) { 34 *subtotal += row[c]; 35 } // for 35 36 } 36 37 37 38 int main() { 38 const int rows = 10, cols = 1000;39 int matrix[rows][cols], subtotals[rows], total = 0;40 processor p; // addkernel thread39 const int rows = 10, cols = 1000; 40 int matrix[rows][cols], subtotals[rows], total = 0; 41 processor p; // extra kernel thread 41 42 42 for ( int r = 0; r < rows; r += 1 ) {43 for ( int r = 0; r < rows; r += 1 ) { 43 44 for ( int c = 0; c < cols; c += 1 ) { 44 45 matrix[r][c] = 1; 45 46 } // for 46 } // for47 Adder * adders[rows];48 for ( int r = 0; r < rows; r += 1 ) { // start threads to sum rows47 } // for 48 Adder * adders[rows]; 49 for ( int r = 0; r < rows; r += 1 ) { // start threads to sum rows 49 50 adders[r] = &(*malloc()){ matrix[r], cols, subtotals[r] }; 50 51 // adders[r] = new( matrix[r], cols, &subtotals[r] ); 51 } // for52 for ( int r = 0; r < rows; r += 1 ) { // wait for threads to finish52 } // for 53 for ( int r = 0; r < rows; r += 1 ) { // wait for threads to finish 53 54 delete( adders[r] ); 54 55 total += subtotals[r]; // total subtotals 55 } // for56 sout | total | endl;56 } // for 57 sout | total | endl; 57 58 } 58 59
Note:
See TracChangeset
for help on using the changeset viewer.