Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/tests/concurrent/examples/matrixSum.c

    rc107f4ec r971d9f2  
    1111// Created On       : Mon Oct  9 08:29:28 2017
    1212// Last Modified By : Peter A. Buhr
    13 // Last Modified On : Fri May 25 09:34:27 2018
    14 // Update Count     : 10
     13// Last Modified On : Tue Dec  5 22:56:46 2017
     14// Update Count     : 4
    1515//
    1616
     
    2020
    2121thread Adder {
    22         int * row, cols, & subtotal;                                            // communication
     22    int * row, cols, * subtotal;                                                // communication
    2323};
    2424
    2525void ?{}( 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;
    2829}
    2930
    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
     31void main( Adder & adder ) with( adder ) {
     32    *subtotal = 0;
     33    for ( int c = 0; c < cols; c += 1 ) {
     34                *subtotal += row[c];
     35    } // for
    3536}
    3637
    3738int main() {
    38         const int rows = 10, cols = 1000;
    39         int matrix[rows][cols], subtotals[rows], total = 0;
    40         processor p;                                                                            // add kernel thread
     39    const int rows = 10, cols = 1000;
     40    int matrix[rows][cols], subtotals[rows], total = 0;
     41    processor p;                                                                                // extra kernel thread
    4142
    42         for ( int r = 0; r < rows; r += 1 ) {
     43    for ( int r = 0; r < rows; r += 1 ) {
    4344                for ( int c = 0; c < cols; c += 1 ) {
    4445                        matrix[r][c] = 1;
    4546                } // for
    46         } // for
    47         Adder * adders[rows];
    48         for ( int r = 0; r < rows; r += 1 ) {                           // start threads to sum rows
     47    } // for
     48    Adder * adders[rows];
     49    for ( int r = 0; r < rows; r += 1 ) {                               // start threads to sum rows
    4950                adders[r] = &(*malloc()){ matrix[r], cols, subtotals[r] };
    5051//              adders[r] = new( matrix[r], cols, &subtotals[r] );
    51         } // for
    52         for ( int r = 0; r < rows; r += 1 ) {                           // wait for threads to finish
     52    } // for
     53    for ( int r = 0; r < rows; r += 1 ) {                               // wait for threads to finish
    5354                delete( adders[r] );
    5455                total += subtotals[r];                                                  // total subtotals
    55         } // for
    56         sout | total | endl;
     56    } // for
     57    sout | total | endl;
    5758}
    5859
Note: See TracChangeset for help on using the changeset viewer.