Ignore:
Timestamp:
May 25, 2018, 9:48:17 AM (6 years ago)
Author:
Peter A. Buhr <pabuhr@…>
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
Message:

formatting

File:
1 edited

Legend:

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

    rcc2eda7 rc107f4ec  
    1111// Created On       : Mon Oct  9 08:29:28 2017
    1212// Last Modified By : Peter A. Buhr
    13 // Last Modified On : Tue Dec  5 22:56:46 2017
    14 // Update Count     : 4
     13// Last Modified On : Fri May 25 09:34:27 2018
     14// Update Count     : 10
    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 = 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;
    2928}
    3029
    31 void main( Adder & adder ) with( adder ) {
    32     *subtotal = 0;
    33     for ( int c = 0; c < cols; c += 1 ) {
    34                 *subtotal += row[c];
    35     } // for
     30void 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
    3635}
    3736
    3837int main() {
    39     const int rows = 10, cols = 1000;
    40     int matrix[rows][cols], subtotals[rows], total = 0;
    41     processor p;                                                                                // extra kernel thread
     38        const int rows = 10, cols = 1000;
     39        int matrix[rows][cols], subtotals[rows], total = 0;
     40        processor p;                                                                            // add kernel thread
    4241
    43     for ( int r = 0; r < rows; r += 1 ) {
     42        for ( int r = 0; r < rows; r += 1 ) {
    4443                for ( int c = 0; c < cols; c += 1 ) {
    4544                        matrix[r][c] = 1;
    4645                } // for
    47     } // for
    48     Adder * adders[rows];
    49     for ( int r = 0; r < rows; r += 1 ) {                               // start threads to sum rows
     46        } // for
     47        Adder * adders[rows];
     48        for ( int r = 0; r < rows; r += 1 ) {                           // start threads to sum rows
    5049                adders[r] = &(*malloc()){ matrix[r], cols, subtotals[r] };
    5150//              adders[r] = new( matrix[r], cols, &subtotals[r] );
    52     } // for
    53     for ( int r = 0; r < rows; r += 1 ) {                               // wait for threads to finish
     51        } // for
     52        for ( int r = 0; r < rows; r += 1 ) {                           // wait for threads to finish
    5453                delete( adders[r] );
    5554                total += subtotals[r];                                                  // total subtotals
    56     } // for
    57     sout | total | endl;
     55        } // for
     56        sout | total | endl;
    5857}
    5958
Note: See TracChangeset for help on using the changeset viewer.