Changeset 9f865d1 for src/tests/matrixSum.c
- Timestamp:
- Oct 30, 2017, 6:22:50 PM (6 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, 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, resolv-new, with_gc
- Children:
- 2ba0bc7
- Parents:
- bfc0f40
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/tests/matrixSum.c
rbfc0f40 r9f865d1 11 11 // Created On : Mon Oct 9 08:29:28 2017 12 12 // Last Modified By : Peter A. Buhr 13 // Last Modified On : Mon Oct 9 08:30:08 201714 // Update Count : 113 // Last Modified On : Sun Oct 29 21:08:48 2017 14 // Update Count : 2 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 … … 32 32 *adder.subtotal = 0; 33 33 for ( int c = 0; c < adder.cols; c += 1 ) { 34 *adder.subtotal += adder.row[c];34 *adder.subtotal += adder.row[c]; 35 35 } // for 36 36 } … … 39 39 const int rows = 10, cols = 1000; 40 40 int matrix[rows][cols], subtotals[rows], total = 0; 41 processor p; // extra kernel thread41 processor p; // extra kernel thread 42 42 43 43 for ( int r = 0; r < rows; r += 1 ) { 44 for ( int c = 0; c < cols; c += 1 ) {45 46 } // for44 for ( int c = 0; c < cols; c += 1 ) { 45 matrix[r][c] = 1; 46 } // for 47 47 } // for 48 48 Adder * adders[rows]; 49 for ( int r = 0; r < rows; r += 1 ) { // start threads to sum rows50 adders[r] = &(*malloc()){ matrix[r], cols, subtotals[r] };51 // adders[r] = new( matrix[r], cols, &subtotals[r] );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] ); 52 52 } // for 53 for ( int r = 0; r < rows; r += 1 ) { // wait for threads to finish54 delete( adders[r] );55 total += subtotals[r];// total subtotals53 for ( int r = 0; r < rows; r += 1 ) { // wait for threads to finish 54 delete( adders[r] ); 55 total += subtotals[r]; // total subtotals 56 56 } // for 57 57 sout | total | endl;
Note: See TracChangeset
for help on using the changeset viewer.