Ignore:
Timestamp:
Oct 29, 2019, 4:01:24 PM (6 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
773db65, 9421f3d8
Parents:
7951100 (diff), 8364209 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

Location:
tests/concurrent/examples
Files:
4 added
11 moved

Legend:

Unmodified
Added
Removed
  • tests/concurrent/examples/boundedBufferEXT.cfa

    r7951100 rb067d9b  
    11//
     2// Cforall Version 1.0.0 Copyright (C) 2018 University of Waterloo
     3//
    24// The contents of this file are covered under the licence agreement in the
    35// file "LICENCE" distributed with Cforall.
     
    810// Created On       : Wed Apr 18 22:52:12 2018
    911// Last Modified By : Peter A. Buhr
    10 // Last Modified On : Wed May  2 16:12:58 2018
    11 // Update Count     : 7
     12// Last Modified On : Fri Jun 21 08:19:20 2019
     13// Update Count     : 14
    1214//
    1315
    14 #include <stdlib>                                                                               // random
    15 #include <fstream>
    16 #include <kernel>
    17 #include <thread>
     16#include <stdlib.hfa>                                                                   // random
     17#include <fstream.hfa>
     18#include <kernel.hfa>
     19#include <thread.hfa>
    1820#include <unistd.h>                                                                             // getpid
    1921
     
    5052}
    5153
    52 const int Sentinel = -1;
     54enum { Sentinel = -1 };
    5355
    5456thread Producer {
     
    5759};
    5860void main( Producer & prod ) with( prod ) {
    59         for ( int i = 1; i <= N; i += 1 ) {
     61        for ( i; 1 ~= N ) {
    6062                yield( random( 5 ) );
    6163                insert( buffer, 1 );
     
    7375void main( Consumer & cons ) with( cons ) {
    7476        sum = 0;
    75         for ( ;; ) {
     77        for () {
    7678                yield( random( 5 ) );
    7779                int item = remove( buffer );
     
    9799        srandom( 1003 );
    98100
    99         for ( i = 0; i < Cons; i += 1 ) {                                       // create consumers
     101        for ( i; Cons ) {                                                                       // create consumers
    100102                cons[i] = new( &buffer, sums[i] );
    101103        } // for
    102         for ( i = 0; i < Prods; i += 1 ) {                                      // create producers
     104        for ( i; Prods ) {                                                                      // create producers
    103105                prods[i] = new( &buffer, 100000 );
    104106        } // for
    105107
    106         for ( i = 0; i < Prods; i += 1 ) {                                      // wait for producers to finish
     108        for ( i; Prods ) {                                                                      // wait for producers to finish
    107109                delete( prods[i] );
    108110        } // for
    109         for ( i = 0; i < Cons; i += 1 ) {                                       // generate sentinal values to stop consumers
     111        for ( i; Cons ) {                                                                       // generate sentinal values to stop consumers
    110112                insert( buffer, Sentinel );
    111113        } // for
    112114        int sum = 0;
    113         for ( i = 0; i < Cons; i += 1 ) {                                       // wait for consumers to finish
     115        for ( i; Cons ) {                                                                       // wait for consumers to finish
    114116                delete( cons[i] );
    115117                sum += sums[i];
    116118        } // for
    117         sout | "total:" | sum | endl;
     119        sout | "total:" | sum;
    118120}
    119121
    120122// Local Variables: //
    121123// tab-width: 4 //
    122 // compile-command: "cfa boundedBufferEXT.c" //
     124// compile-command: "cfa boundedBufferEXT.cfa" //
    123125// End: //
  • tests/concurrent/examples/boundedBufferINT.cfa

    r7951100 rb067d9b  
    11//
     2// Cforall Version 1.0.0 Copyright (C) 2017 University of Waterloo
     3//
    24// The contents of this file are covered under the licence agreement in the
    35// file "LICENCE" distributed with Cforall.
     
    810// Created On       : Mon Oct 30 12:45:13 2017
    911// Last Modified By : Peter A. Buhr
    10 // Last Modified On : Thu Apr 26 23:08:17 2018
    11 // Update Count     : 82
     12// Last Modified On : Fri Jun 21 08:20:46 2019
     13// Update Count     : 90
    1214//
    1315
    14 #include <stdlib>                                                                               // random
    15 #include <fstream>
    16 #include <kernel>
    17 #include <thread>
     16#include <stdlib.hfa>                                                                   // random
     17#include <fstream.hfa>
     18#include <kernel.hfa>
     19#include <thread.hfa>
    1820#include <unistd.h>                                                                             // getpid
    1921
     
    5153}
    5254
    53 const int Sentinel = -1;
     55enum { Sentinel = -1 };
    5456
    5557thread Producer {
     
    5860};
    5961void main( Producer & prod ) with( prod ) {
    60         for ( int i = 1; i <= N; i += 1 ) {
     62        for ( i; 1 ~= N ) {
    6163                yield( random( 5 ) );
    6264                insert( buffer, 1 );
     
    7476void main( Consumer & cons ) with( cons ) {
    7577        sum = 0;
    76         for ( ;; ) {
     78        for () {
    7779                yield( random( 5 ) );
    7880                int item = remove( buffer );
     
    98100        srandom( 1003 );
    99101
    100         for ( i = 0; i < Cons; i += 1 ) {                                       // create consumers
     102        for ( i; Cons ) {                                                                       // create consumers
    101103                cons[i] = new( &buffer, sums[i] );
    102104        } // for
    103         for ( i = 0; i < Prods; i += 1 ) {                                      // create producers
     105        for ( i; Prods ) {                                                                      // create producers
    104106                prods[i] = new( &buffer, 100000 );
    105107        } // for
    106108
    107         for ( i = 0; i < Prods; i += 1 ) {                                      // wait for producers to finish
     109        for ( i; Prods ) {                                                                      // wait for producers to finish
    108110                delete( prods[i] );
    109111        } // for
    110         for ( i = 0; i < Cons; i += 1 ) {                                       // generate sentinal values to stop consumers
     112        for ( i; Cons ) {                                                                       // generate sentinal values to stop consumers
    111113                insert( buffer, Sentinel );
    112114        } // for
    113115        int sum = 0;
    114         for ( i = 0; i < Cons; i += 1 ) {                                       // wait for consumers to finish
     116        for ( i; Cons ) {                                                                       // wait for consumers to finish
    115117                delete( cons[i] );
    116118                sum += sums[i];
    117119        } // for
    118         sout | "total:" | sum | endl;
     120        sout | "total:" | sum;
    119121}
    120122
    121123// Local Variables: //
    122124// tab-width: 4 //
    123 // compile-command: "cfa boundedBufferINT.c" //
     125// compile-command: "cfa boundedBufferINT.cfa" //
    124126// End: //
  • tests/concurrent/examples/datingService.cfa

    r7951100 rb067d9b  
    11//
     2// Cforall Version 1.0.0 Copyright (C) 2017 University of Waterloo
     3//
    24// The contents of this file are covered under the licence agreement in the
    35// file "LICENCE" distributed with Cforall.
     
    810// Created On       : Mon Oct 30 12:56:20 2017
    911// Last Modified By : Peter A. Buhr
    10 // Last Modified On : Sun May 27 09:05:18 2018
    11 // Update Count     : 26
     12// Last Modified On : Fri Jun 21 11:32:34 2019
     13// Update Count     : 38
    1214//
    1315
    14 #include <stdlib>                                                                               // random
    15 #include <fstream>
    16 #include <kernel>
    17 #include <thread>
     16#include <stdlib.hfa>                                                                   // random
     17#include <fstream.hfa>
     18#include <kernel.hfa>
     19#include <thread.hfa>
    1820#include <unistd.h>                                                                             // getpid
    1921
     
    3335                signal_block( Boys[ccode] );                                    // restart boy to set phone number
    3436        } // if
     37        sout | "Girl:" | PhoneNo | "is dating Boy at" | BoyPhoneNo | "with ccode" | ccode;
    3538        return BoyPhoneNo;
    3639} // DatingService girl
     
    4447                signal_block( Girls[ccode] );                                   // restart girl to set phone number
    4548        } // if
     49        sout | " Boy:" | PhoneNo | "is dating Girl" | GirlPhoneNo | "with ccode" | ccode;
    4650        return GirlPhoneNo;
    4751} // DatingService boy
     
    5862        yield( random( 100 ) );                                                         // don't all start at the same time
    5963        unsigned int partner = girl( TheExchange, id, ccode );
    60         sout | "Girl:" | id | "is dating Boy at" | partner | "with ccode" | ccode | endl;
    6164        girlck[id] = partner;
    6265} // Girl main
     
    6972
    7073thread Boy {
    71         DatingService &TheExchange;
     74        DatingService & TheExchange;
    7275        unsigned int id, ccode;
    7376}; // Boy
     
    7679        yield( random( 100 ) );                                                         // don't all start at the same time
    7780        unsigned int partner = boy( TheExchange, id, ccode );
    78         sout | " Boy:" | id | "is dating Girl" | partner | "with ccode" | ccode | endl;
    7981        boyck[id] = partner;
    8082} // Boy main
     
    9395        srandom( /*getpid()*/ 103 );
    9496
    95         for ( unsigned int i = 0; i < CompCodes; i += 1 ) {
    96                 girls[i] = new( &TheExchange, i, i );
     97        for ( i; (unsigned int)CompCodes ) {
     98                girls[i] = new( &TheExchange, i, i );                   // TheExchange constructor needs unsigned int
    9799                boys[i]  = new( &TheExchange, i, CompCodes - ( i + 1 ) );
    98100        } // for
    99101
    100         for ( unsigned int i = 0; i < CompCodes; i += 1 ) {
     102        for ( i; CompCodes ) {
    101103                delete( boys[i] );
    102104                delete( girls[i] );
    103105        } // for
    104106
    105         for ( unsigned int i = 0; i < CompCodes; i += 1 ) {
     107        for ( i; CompCodes ) {
    106108                if ( girlck[ boyck[i] ] != boyck[ girlck[i] ] ) abort();
    107109        } // for
     
    110112// Local Variables: //
    111113// tab-width: 4 //
    112 // compile-command: "cfa datingService.c" //
     114// compile-command: "cfa datingService.cfa" //
    113115// End: //
  • tests/concurrent/examples/matrixSum.cfa

    r7951100 rb067d9b  
    1 //                               -*- Mode: C -*-
    2 //
     1//
    32// Cforall Version 1.0.0 Copyright (C) 2017 University of Waterloo
    43//
    54// The contents of this file are covered under the licence agreement in the
    65// file "LICENCE" distributed with Cforall.
    7 // 
    8 // matrixSum.c --
    9 // 
     6//
     7// matrixSum.cfa --
     8//
    109// Author           : Peter A. Buhr
    1110// Created On       : Mon Oct  9 08:29:28 2017
    1211// Last Modified By : Peter A. Buhr
    13 // Last Modified On : Fri May 25 09:34:27 2018
    14 // Update Count     : 10
    15 // 
     12// Last Modified On : Wed Feb 20 08:37:53 2019
     13// Update Count     : 16
     14//
    1615
    17 #include <fstream>
    18 #include <kernel>
    19 #include <thread>
     16#include <fstream.hfa>
     17#include <kernel.hfa>
     18#include <thread.hfa>
    2019
    2120thread Adder {
     
    3029void main( Adder & adder ) with( adder ) {                              // thread starts here
    3130        subtotal = 0;
    32         for ( int c = 0; c < cols; c += 1 ) {
     31        for ( c; cols ) {
    3332                subtotal += row[c];
    3433        } // for
     
    3635
    3736int main() {
    38         const int rows = 10, cols = 1000;
     37        /* const */ int rows = 10, cols = 1000;
    3938        int matrix[rows][cols], subtotals[rows], total = 0;
    4039        processor p;                                                                            // add kernel thread
    4140
    42         for ( int r = 0; r < rows; r += 1 ) {
    43                 for ( int c = 0; c < cols; c += 1 ) {
     41        for ( r; rows ) {
     42                for ( c; cols ) {
    4443                        matrix[r][c] = 1;
    4544                } // for
    4645        } // for
    4746        Adder * adders[rows];
    48         for ( int r = 0; r < rows; r += 1 ) {                           // start threads to sum rows
     47        for ( r; rows ) {                                                                       // start threads to sum rows
    4948                adders[r] = &(*malloc()){ matrix[r], cols, subtotals[r] };
    5049//              adders[r] = new( matrix[r], cols, &subtotals[r] );
    5150        } // for
    52         for ( int r = 0; r < rows; r += 1 ) {                           // wait for threads to finish
     51        for ( r; rows ) {                                                                       // wait for threads to finish
    5352                delete( adders[r] );
    5453                total += subtotals[r];                                                  // total subtotals
    5554        } // for
    56         sout | total | endl;
     55        sout | total;
    5756}
    5857
    5958// Local Variables: //
    6059// tab-width: 4 //
    61 // compile-command: "cfa matrixSum.c" //
     60// compile-command: "cfa matrixSum.cfa" //
    6261// End: //
  • tests/concurrent/examples/quickSort.cfa

    r7951100 rb067d9b  
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2017 University of Waterloo
    13//
    24// The contents of this file are covered under the licence agreement in the
     
    911// Created On       : Wed Dec  6 12:15:52 2017
    1012// Last Modified By : Peter A. Buhr
    11 // Last Modified On : Tue Jan 30 15:58:58 2018
    12 // Update Count     : 162
     13// Last Modified On : Thu Oct 10 13:58:18 2019
     14// Update Count     : 176
    1315//
    1416
    15 #include <fstream>
    16 #include <stdlib>
    17 #include <kernel>
    18 #include <thread>
     17#include <fstream.hfa>
     18#include <stdlib.hfa>
     19#include <kernel.hfa>
     20#include <thread.hfa>
    1921#include <string.h>                                                                             // strcmp
    2022
     
    6466                        if ( depth > 0 ) {
    6567                                depth -= 1;
    66                                 Quicksort rqs = { values, low, right, depth }; // concurrently sort upper half
    67                                 //Quicksort lqs( values, left, high, depth ); // concurrently sort lower half
    68                                 sort( values, left, high, depth );              // concurrently sort lower half
     68                                Quicksort lqs = { values, low, right, depth }; // concurrently sort lower half
     69                                Quicksort rqs = { values, left, high, depth }; // concurrently sort upper half
     70                                // Quicksort lqs = { values, low, right, depth }; // concurrently sort lower half
     71                                // sort( values, left, high, depth );           // concurrently sort upper half
    6972                        } else {
    7073                                sort( values, low, right, 0 );                  // sequentially sort lower half
     
    8891
    8992void usage( char * argv[] ) {
    90         sout | "Usage:" | argv[0] | "( -s unsorted-file [ sorted-file ] | -t size (>= 0) [ depth (>= 0) ] )" | endl;
     93        sout | "Usage:" | argv[0] | "( -s unsorted-file [ sorted-file ] | -t size (>= 0) [ depth (>= 0) ] )";
    9194        exit( EXIT_FAILURE );                                                           // TERMINATE!
    9295} // usage
     
    114117                                &sortedfile = new( (const char *)argv[2] ); // open the output file
    115118                                if ( fail( sortedfile ) ) {
    116                                         serr | "Error! Could not open sorted output file \"" | argv[2] | "\"" | endl;
     119                                        serr | "Error! Could not open sorted output file \"" | argv[2] | "\"";
    117120                                        usage( argv );
    118121                                } // if
     
    121124                                &unsortedfile = new( (const char *)argv[1] ); // open the input file
    122125                                if ( fail( unsortedfile ) ) {
    123                                         serr | "Error! Could not open unsorted input file \"" | argv[1] | "\"" | endl;
     126                                        serr | "Error! Could not open unsorted input file \"" | argv[1] | "\"";
    124127                                        usage( argv );
    125128                                } // if
     
    127130                } // if
    128131        } // if
     132        sortedfile | nlOff;                                                                     // turn off auto newline
    129133
    130134        enum { ValuesPerLine = 22 };                                            // number of values printed per line
    131135
    132136        if ( &unsortedfile ) {                                                          // generate output ?
    133                 for ( ;; ) {
     137                for () {
    134138                        unsortedfile | size;                                            // read number of elements in the list
    135139                  if ( eof( unsortedfile ) ) break;
    136140                        int * values = alloc( size );                           // values to be sorted, too large to put on stack
    137                         for ( int counter = 0; counter < size; counter += 1 ) { // read unsorted numbers
     141                        for ( counter; size ) {                                         // read unsorted numbers
    138142                                unsortedfile | values[counter];
    139                                 if ( counter != 0 && counter % ValuesPerLine == 0 ) sortedfile | endl | "  ";
     143                                if ( counter != 0 && counter % ValuesPerLine == 0 ) sortedfile | nl | "  ";
    140144                                sortedfile | values[counter];
    141145                                if ( counter < size - 1 && (counter + 1) % ValuesPerLine != 0 ) sortedfile | ' ';
    142146                        } // for
    143                         sortedfile | endl;
     147                        sortedfile | nl;
    144148                        if ( size > 0 ) {                                                       // values to sort ?
    145149                                Quicksort QS = { values, size - 1, 0 }; // sort values
    146150                        } // wait until sort tasks terminate
    147                         for ( int counter = 0; counter < size; counter += 1 ) { // print sorted list
    148                                 if ( counter != 0 && counter % ValuesPerLine == 0 ) sortedfile | endl | "  ";
     151                        for ( counter; size ) {                                         // print sorted list
     152                                if ( counter != 0 && counter % ValuesPerLine == 0 ) sortedfile | nl | "  ";
    149153                                sortedfile | values[counter];
    150154                                if ( counter < size - 1 && (counter + 1) % ValuesPerLine != 0 ) sortedfile | ' ';
    151155                        } // for
    152                         sortedfile | endl | endl;
     156                        sortedfile | nl | nl;
    153157
    154158                        delete( values );
     
    159163                processor processors[ (1 << depth) - 1 ] __attribute__(( unused )); // create 2^depth-1 kernel threads
    160164
    161                 int * values = alloc( size );                           // values to be sorted, too large to put on stack
    162                 for ( int counter = 0; counter < size; counter += 1 ) { // generate unsorted numbers
     165                int * values = alloc( size );                                   // values to be sorted, too large to put on stack
     166                for ( counter; size ) {                                                 // generate unsorted numbers
    163167                        values[counter] = size - counter;                       // descending values
     168                } // for
     169                for ( int i = 0; i < 200; i +=1 ) {                             // random shuffle a few values
     170                        swap( values[rand() % size], values[rand() % size] );
    164171                } // for
    165172                {
     
    167174                } // wait until sort tasks terminate
    168175
    169                 // for ( int counter = 0; counter < size - 1; counter += 1 ) { // check sorting
     176                // for ( counter; size - 1 ) {                          // check sorting
    170177                //      if ( values[counter] > values[counter + 1] ) abort();
    171178                // } // for
     
    175182} // main
    176183
     184// for depth in 0 1 2 3 4 5 ; do echo "sort 500000000 values with ${depth} depth" ; time -f "%Uu %Ss %E %Mkb" a.out -t 500000000 ${depth} ; done
     185
    177186// Local Variables: //
    178187// tab-width: 4 //
    179 // compile-command: "cfa quickSort.c" //
     188// compile-command: "cfa quickSort.cfa" //
    180189// End: //
Note: See TracChangeset for help on using the changeset viewer.