source:tests/concurrent/examples/matrixSum.cfa@5b11c25

Last change on this file since 5b11c25 was 2e457d8, checked in by Peter A. Buhr <pabuhr@…>, 5 years ago

formatting

• Property mode set to `100644`
File size: 1.5 KB
Line
1//
2// Cforall Version 1.0.0 Copyright (C) 2017 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
7// matrixSum.cfa --
8//
9// Author           : Peter A. Buhr
10// Created On       : Mon Oct  9 08:29:28 2017
13// Update Count     : 16
14//
15
16#include <fstream.hfa>
17#include <kernel.hfa>
19
21        int * row, cols, & subtotal;                                            // communication
22};
23
24void ?{}( Adder & adder, int row[], int cols, int & subtotal ) {
25        adder.[ row, cols ] = [ row, cols ];                            // expression disallowed in multi-member access
27}
28
30        subtotal = 0;
31        for ( c; cols ) {
32                subtotal += row[c];
33        } // for
34}
35
36int main() {
37        /* const */ int rows = 10, cols = 1000;
38        int matrix[rows][cols], subtotals[rows], total = 0;
40
41        for ( r; rows ) {
42                for ( c; cols ) {
43                        matrix[r][c] = 1;
44                } // for
45        } // for
47        for ( r; rows ) {                                                                       // start threads to sum rows
48                adders[r] = &(*malloc()){ matrix[r], cols, subtotals[r] };
49//              adders[r] = new( matrix[r], cols, &subtotals[r] );
50        } // for
51        for ( r; rows ) {                                                                       // wait for threads to finish