Changeset c107f4ec
- Timestamp:
- May 25, 2018, 9:48:17 AM (7 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, with_gc
- Children:
- 84b4ed72
- Parents:
- cc2eda7
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/tests/concurrent/examples/matrixSum.c
rcc2eda7 rc107f4ec 11 11 // Created On : Mon Oct 9 08:29:28 2017 12 12 // Last Modified By : Peter A. Buhr 13 // Last Modified On : Tue Dec 5 22:56:46 201714 // Update Count : 413 // Last Modified On : Fri May 25 09:34:27 2018 14 // Update Count : 10 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 = row; 27 adder.cols = cols; 28 adder.subtotal = &subtotal; 26 adder.[ row, cols ] = [ row, cols ]; // expression disallowed in multi-member access 27 &adder.subtotal = &subtotal; 29 28 } 30 29 31 void main( Adder & adder ) with( adder ) { 32 *subtotal = 0;33 34 *subtotal += row[c];35 30 void main( Adder & adder ) with( adder ) { // thread starts here 31 subtotal = 0; 32 for ( int c = 0; c < cols; c += 1 ) { 33 subtotal += row[c]; 34 } // for 36 35 } 37 36 38 37 int main() { 39 40 41 processor p; // extrakernel thread38 const int rows = 10, cols = 1000; 39 int matrix[rows][cols], subtotals[rows], total = 0; 40 processor p; // add kernel thread 42 41 43 42 for ( int r = 0; r < rows; r += 1 ) { 44 43 for ( int c = 0; c < cols; c += 1 ) { 45 44 matrix[r][c] = 1; 46 45 } // for 47 48 49 46 } // for 47 Adder * adders[rows]; 48 for ( int r = 0; r < rows; r += 1 ) { // start threads to sum rows 50 49 adders[r] = &(*malloc()){ matrix[r], cols, subtotals[r] }; 51 50 // adders[r] = new( matrix[r], cols, &subtotals[r] ); 52 53 51 } // for 52 for ( int r = 0; r < rows; r += 1 ) { // wait for threads to finish 54 53 delete( adders[r] ); 55 54 total += subtotals[r]; // total subtotals 56 57 55 } // for 56 sout | total | endl; 58 57 } 59 58
Note: See TracChangeset
for help on using the changeset viewer.