source: tests/concurrent/examples/matrixSum.cfa@ ba01b14

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr persistent-indexer pthread-emulation qualifiedEnum
Last change on this file since ba01b14 was 107b01a, checked in by Thierry Delisle <tdelisle@…>, 7 years ago

Several changes to the makefiles

  • change .c tests to .cfa
  • add require for libtool in configure
  • libtoolize to fix some warnings
  • Property mode set to 100644
File size: 1.6 KB
Line 
1// -*- Mode: C -*-
2//
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.
7//
8// matrixSum.cfa --
9//
10// Author : Peter A. Buhr
11// Created On : Mon Oct 9 08:29:28 2017
12// Last Modified By : Peter A. Buhr
13// Last Modified On : Tue Dec 11 21:54:55 2018
14// Update Count : 15
15//
16
17#include <fstream.hfa>
18#include <kernel.hfa>
19#include <thread.hfa>
20
21thread Adder {
22 int * row, cols, & subtotal; // communication
23};
24
25void ?{}( Adder & adder, int row[], int cols, int & subtotal ) {
26 adder.[ row, cols ] = [ row, cols ]; // expression disallowed in multi-member access
27 &adder.subtotal = &subtotal;
28}
29
30void main( Adder & adder ) with( adder ) { // thread starts here
31 subtotal = 0;
32 for ( c; cols ) {
33 subtotal += row[c];
34 } // for
35}
36
37int main() {
38 /* const */ int rows = 10, cols = 1000;
39 int matrix[rows][cols], subtotals[rows], total = 0;
40 processor p; // add kernel thread
41
42 for ( r; rows ) {
43 for ( c; cols ) {
44 matrix[r][c] = 1;
45 } // for
46 } // for
47 Adder * adders[rows];
48 for ( r; rows ) { // start threads to sum rows
49 adders[r] = &(*malloc()){ matrix[r], cols, subtotals[r] };
50// adders[r] = new( matrix[r], cols, &subtotals[r] );
51 } // for
52 for ( r; rows ) { // wait for threads to finish
53 delete( adders[r] );
54 total += subtotals[r]; // total subtotals
55 } // for
56 sout | total;
57}
58
59// Local Variables: //
60// tab-width: 4 //
61// compile-command: "cfa matrixSum.cfa" //
62// End: //
Note: See TracBrowser for help on using the repository browser.