source: tests/concurrent/examples/matrixSum.c @ 5ea5b28

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resnenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprno_listpersistent-indexerpthread-emulationqualifiedEnum
Last change on this file since 5ea5b28 was 200fcb3, checked in by Peter A. Buhr <pabuhr@…>, 5 years ago

add auto newline to sout, change endl to nl

  • Property mode set to 100644
File size: 1.6 KB
RevLine 
[73abe95]1//                               -*- Mode: C -*-
2//
[d6655bd]3// Cforall Version 1.0.0 Copyright (C) 2017 University of Waterloo
4//
5// The contents of this file are covered under the licence agreement in the
6// file "LICENCE" distributed with Cforall.
[73abe95]7//
[dc8511c]8// matrixSum.cfa --
[73abe95]9//
[d6655bd]10// Author           : Peter A. Buhr
11// Created On       : Mon Oct  9 08:29:28 2017
12// Last Modified By : Peter A. Buhr
[200fcb3]13// Last Modified On : Tue Dec 11 21:54:55 2018
14// Update Count     : 15
[73abe95]15//
[d6655bd]16
[73abe95]17#include <fstream.hfa>
18#include <kernel.hfa>
19#include <thread.hfa>
[b8a17e2]20
21thread Adder {
[c107f4ec]22        int * row, cols, & subtotal;                                            // communication
[b8a17e2]23};
24
25void ?{}( Adder & adder, int row[], int cols, int & subtotal ) {
[c107f4ec]26        adder.[ row, cols ] = [ row, cols ];                            // expression disallowed in multi-member access
27        &adder.subtotal = &subtotal;
[b8a17e2]28}
29
[c107f4ec]30void main( Adder & adder ) with( adder ) {                              // thread starts here
31        subtotal = 0;
[8f34661]32        for ( c; cols ) {
[c107f4ec]33                subtotal += row[c];
34        } // for
[b8a17e2]35}
36
37int main() {
[8f34661]38        /* const */ int rows = 10, cols = 1000;
[c107f4ec]39        int matrix[rows][cols], subtotals[rows], total = 0;
40        processor p;                                                                            // add kernel thread
[b8a17e2]41
[8f34661]42        for ( r; rows ) {
43                for ( c; cols ) {
[9f865d1]44                        matrix[r][c] = 1;
45                } // for
[c107f4ec]46        } // for
47        Adder * adders[rows];
[8f34661]48        for ( r; rows ) {                                                                       // start threads to sum rows
[9f865d1]49                adders[r] = &(*malloc()){ matrix[r], cols, subtotals[r] };
50//              adders[r] = new( matrix[r], cols, &subtotals[r] );
[c107f4ec]51        } // for
[8f34661]52        for ( r; rows ) {                                                                       // wait for threads to finish
[9f865d1]53                delete( adders[r] );
54                total += subtotals[r];                                                  // total subtotals
[c107f4ec]55        } // for
[200fcb3]56        sout | total;
[b8a17e2]57}
[d6655bd]58
59// Local Variables: //
60// tab-width: 4 //
[dc8511c]61// compile-command: "cfa matrixSum.cfa" //
[d6655bd]62// End: //
Note: See TracBrowser for help on using the repository browser.