Changeset b067d9b for tests/concurrent/examples
- Timestamp:
- Oct 29, 2019, 4:01:24 PM (6 years ago)
- 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. - Location:
- tests/concurrent/examples
- Files:
-
- 4 added
- 11 moved
Legend:
- Unmodified
- Added
- Removed
-
tests/concurrent/examples/boundedBufferEXT.cfa
r7951100 rb067d9b 1 1 // 2 // Cforall Version 1.0.0 Copyright (C) 2018 University of Waterloo 3 // 2 4 // The contents of this file are covered under the licence agreement in the 3 5 // file "LICENCE" distributed with Cforall. … … 8 10 // Created On : Wed Apr 18 22:52:12 2018 9 11 // Last Modified By : Peter A. Buhr 10 // Last Modified On : Wed May 2 16:12:58 201811 // Update Count : 712 // Last Modified On : Fri Jun 21 08:19:20 2019 13 // Update Count : 14 12 14 // 13 15 14 #include <stdlib >// random15 #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> 18 20 #include <unistd.h> // getpid 19 21 … … 50 52 } 51 53 52 const int Sentinel = -1;54 enum { Sentinel = -1 }; 53 55 54 56 thread Producer { … … 57 59 }; 58 60 void main( Producer & prod ) with( prod ) { 59 for ( i nt i = 1; i <= N; i += 1) {61 for ( i; 1 ~= N ) { 60 62 yield( random( 5 ) ); 61 63 insert( buffer, 1 ); … … 73 75 void main( Consumer & cons ) with( cons ) { 74 76 sum = 0; 75 for ( ;;) {77 for () { 76 78 yield( random( 5 ) ); 77 79 int item = remove( buffer ); … … 97 99 srandom( 1003 ); 98 100 99 for ( i = 0; i < Cons; i += 1 ) {// create consumers101 for ( i; Cons ) { // create consumers 100 102 cons[i] = new( &buffer, sums[i] ); 101 103 } // for 102 for ( i = 0; i < Prods; i += 1 ) {// create producers104 for ( i; Prods ) { // create producers 103 105 prods[i] = new( &buffer, 100000 ); 104 106 } // for 105 107 106 for ( i = 0; i < Prods; i += 1 ) {// wait for producers to finish108 for ( i; Prods ) { // wait for producers to finish 107 109 delete( prods[i] ); 108 110 } // for 109 for ( i = 0; i < Cons; i += 1 ) {// generate sentinal values to stop consumers111 for ( i; Cons ) { // generate sentinal values to stop consumers 110 112 insert( buffer, Sentinel ); 111 113 } // for 112 114 int sum = 0; 113 for ( i = 0; i < Cons; i += 1 ) {// wait for consumers to finish115 for ( i; Cons ) { // wait for consumers to finish 114 116 delete( cons[i] ); 115 117 sum += sums[i]; 116 118 } // for 117 sout | "total:" | sum | endl;119 sout | "total:" | sum; 118 120 } 119 121 120 122 // Local Variables: // 121 123 // tab-width: 4 // 122 // compile-command: "cfa boundedBufferEXT.c " //124 // compile-command: "cfa boundedBufferEXT.cfa" // 123 125 // End: // -
tests/concurrent/examples/boundedBufferINT.cfa
r7951100 rb067d9b 1 1 // 2 // Cforall Version 1.0.0 Copyright (C) 2017 University of Waterloo 3 // 2 4 // The contents of this file are covered under the licence agreement in the 3 5 // file "LICENCE" distributed with Cforall. … … 8 10 // Created On : Mon Oct 30 12:45:13 2017 9 11 // Last Modified By : Peter A. Buhr 10 // Last Modified On : Thu Apr 26 23:08:17 201811 // Update Count : 8212 // Last Modified On : Fri Jun 21 08:20:46 2019 13 // Update Count : 90 12 14 // 13 15 14 #include <stdlib >// random15 #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> 18 20 #include <unistd.h> // getpid 19 21 … … 51 53 } 52 54 53 const int Sentinel = -1;55 enum { Sentinel = -1 }; 54 56 55 57 thread Producer { … … 58 60 }; 59 61 void main( Producer & prod ) with( prod ) { 60 for ( i nt i = 1; i <= N; i += 1) {62 for ( i; 1 ~= N ) { 61 63 yield( random( 5 ) ); 62 64 insert( buffer, 1 ); … … 74 76 void main( Consumer & cons ) with( cons ) { 75 77 sum = 0; 76 for ( ;;) {78 for () { 77 79 yield( random( 5 ) ); 78 80 int item = remove( buffer ); … … 98 100 srandom( 1003 ); 99 101 100 for ( i = 0; i < Cons; i += 1 ) {// create consumers102 for ( i; Cons ) { // create consumers 101 103 cons[i] = new( &buffer, sums[i] ); 102 104 } // for 103 for ( i = 0; i < Prods; i += 1 ) {// create producers105 for ( i; Prods ) { // create producers 104 106 prods[i] = new( &buffer, 100000 ); 105 107 } // for 106 108 107 for ( i = 0; i < Prods; i += 1 ) {// wait for producers to finish109 for ( i; Prods ) { // wait for producers to finish 108 110 delete( prods[i] ); 109 111 } // for 110 for ( i = 0; i < Cons; i += 1 ) {// generate sentinal values to stop consumers112 for ( i; Cons ) { // generate sentinal values to stop consumers 111 113 insert( buffer, Sentinel ); 112 114 } // for 113 115 int sum = 0; 114 for ( i = 0; i < Cons; i += 1 ) {// wait for consumers to finish116 for ( i; Cons ) { // wait for consumers to finish 115 117 delete( cons[i] ); 116 118 sum += sums[i]; 117 119 } // for 118 sout | "total:" | sum | endl;120 sout | "total:" | sum; 119 121 } 120 122 121 123 // Local Variables: // 122 124 // tab-width: 4 // 123 // compile-command: "cfa boundedBufferINT.c " //125 // compile-command: "cfa boundedBufferINT.cfa" // 124 126 // End: // -
tests/concurrent/examples/datingService.cfa
r7951100 rb067d9b 1 1 // 2 // Cforall Version 1.0.0 Copyright (C) 2017 University of Waterloo 3 // 2 4 // The contents of this file are covered under the licence agreement in the 3 5 // file "LICENCE" distributed with Cforall. … … 8 10 // Created On : Mon Oct 30 12:56:20 2017 9 11 // Last Modified By : Peter A. Buhr 10 // Last Modified On : Sun May 27 09:05:18 201811 // Update Count : 2612 // Last Modified On : Fri Jun 21 11:32:34 2019 13 // Update Count : 38 12 14 // 13 15 14 #include <stdlib >// random15 #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> 18 20 #include <unistd.h> // getpid 19 21 … … 33 35 signal_block( Boys[ccode] ); // restart boy to set phone number 34 36 } // if 37 sout | "Girl:" | PhoneNo | "is dating Boy at" | BoyPhoneNo | "with ccode" | ccode; 35 38 return BoyPhoneNo; 36 39 } // DatingService girl … … 44 47 signal_block( Girls[ccode] ); // restart girl to set phone number 45 48 } // if 49 sout | " Boy:" | PhoneNo | "is dating Girl" | GirlPhoneNo | "with ccode" | ccode; 46 50 return GirlPhoneNo; 47 51 } // DatingService boy … … 58 62 yield( random( 100 ) ); // don't all start at the same time 59 63 unsigned int partner = girl( TheExchange, id, ccode ); 60 sout | "Girl:" | id | "is dating Boy at" | partner | "with ccode" | ccode | endl;61 64 girlck[id] = partner; 62 65 } // Girl main … … 69 72 70 73 thread Boy { 71 DatingService & TheExchange;74 DatingService & TheExchange; 72 75 unsigned int id, ccode; 73 76 }; // Boy … … 76 79 yield( random( 100 ) ); // don't all start at the same time 77 80 unsigned int partner = boy( TheExchange, id, ccode ); 78 sout | " Boy:" | id | "is dating Girl" | partner | "with ccode" | ccode | endl;79 81 boyck[id] = partner; 80 82 } // Boy main … … 93 95 srandom( /*getpid()*/ 103 ); 94 96 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 97 99 boys[i] = new( &TheExchange, i, CompCodes - ( i + 1 ) ); 98 100 } // for 99 101 100 for ( unsigned int i = 0; i < CompCodes; i += 1) {102 for ( i; CompCodes ) { 101 103 delete( boys[i] ); 102 104 delete( girls[i] ); 103 105 } // for 104 106 105 for ( unsigned int i = 0; i < CompCodes; i += 1) {107 for ( i; CompCodes ) { 106 108 if ( girlck[ boyck[i] ] != boyck[ girlck[i] ] ) abort(); 107 109 } // for … … 110 112 // Local Variables: // 111 113 // tab-width: 4 // 112 // compile-command: "cfa datingService.c " //114 // compile-command: "cfa datingService.cfa" // 113 115 // End: // -
tests/concurrent/examples/matrixSum.cfa
r7951100 rb067d9b 1 // -*- Mode: C -*- 2 // 1 // 3 2 // Cforall Version 1.0.0 Copyright (C) 2017 University of Waterloo 4 3 // 5 4 // The contents of this file are covered under the licence agreement in the 6 5 // file "LICENCE" distributed with Cforall. 7 // 8 // matrixSum.c --9 // 6 // 7 // matrixSum.cfa -- 8 // 10 9 // Author : Peter A. Buhr 11 10 // Created On : Mon Oct 9 08:29:28 2017 12 11 // Last Modified By : Peter A. Buhr 13 // Last Modified On : Fri May 25 09:34:27 201814 // Update Count : 1 015 // 12 // Last Modified On : Wed Feb 20 08:37:53 2019 13 // Update Count : 16 14 // 16 15 17 #include <fstream >18 #include <kernel >19 #include <thread >16 #include <fstream.hfa> 17 #include <kernel.hfa> 18 #include <thread.hfa> 20 19 21 20 thread Adder { … … 30 29 void main( Adder & adder ) with( adder ) { // thread starts here 31 30 subtotal = 0; 32 for ( int c = 0; c < cols; c += 1) {31 for ( c; cols ) { 33 32 subtotal += row[c]; 34 33 } // for … … 36 35 37 36 int main() { 38 constint rows = 10, cols = 1000;37 /* const */ int rows = 10, cols = 1000; 39 38 int matrix[rows][cols], subtotals[rows], total = 0; 40 39 processor p; // add kernel thread 41 40 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 ) { 44 43 matrix[r][c] = 1; 45 44 } // for 46 45 } // for 47 46 Adder * adders[rows]; 48 for ( int r = 0; r < rows; r += 1 ) {// start threads to sum rows47 for ( r; rows ) { // start threads to sum rows 49 48 adders[r] = &(*malloc()){ matrix[r], cols, subtotals[r] }; 50 49 // adders[r] = new( matrix[r], cols, &subtotals[r] ); 51 50 } // for 52 for ( int r = 0; r < rows; r += 1 ) {// wait for threads to finish51 for ( r; rows ) { // wait for threads to finish 53 52 delete( adders[r] ); 54 53 total += subtotals[r]; // total subtotals 55 54 } // for 56 sout | total | endl;55 sout | total; 57 56 } 58 57 59 58 // Local Variables: // 60 59 // tab-width: 4 // 61 // compile-command: "cfa matrixSum.c " //60 // compile-command: "cfa matrixSum.cfa" // 62 61 // End: // -
tests/concurrent/examples/quickSort.cfa
r7951100 rb067d9b 1 // 2 // Cforall Version 1.0.0 Copyright (C) 2017 University of Waterloo 1 3 // 2 4 // The contents of this file are covered under the licence agreement in the … … 9 11 // Created On : Wed Dec 6 12:15:52 2017 10 12 // Last Modified By : Peter A. Buhr 11 // Last Modified On : T ue Jan 30 15:58:58 201812 // Update Count : 1 6213 // Last Modified On : Thu Oct 10 13:58:18 2019 14 // Update Count : 176 13 15 // 14 16 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> 19 21 #include <string.h> // strcmp 20 22 … … 64 66 if ( depth > 0 ) { 65 67 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 69 72 } else { 70 73 sort( values, low, right, 0 ); // sequentially sort lower half … … 88 91 89 92 void 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) ] )"; 91 94 exit( EXIT_FAILURE ); // TERMINATE! 92 95 } // usage … … 114 117 &sortedfile = new( (const char *)argv[2] ); // open the output file 115 118 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] | "\""; 117 120 usage( argv ); 118 121 } // if … … 121 124 &unsortedfile = new( (const char *)argv[1] ); // open the input file 122 125 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] | "\""; 124 127 usage( argv ); 125 128 } // if … … 127 130 } // if 128 131 } // if 132 sortedfile | nlOff; // turn off auto newline 129 133 130 134 enum { ValuesPerLine = 22 }; // number of values printed per line 131 135 132 136 if ( &unsortedfile ) { // generate output ? 133 for ( ;;) {137 for () { 134 138 unsortedfile | size; // read number of elements in the list 135 139 if ( eof( unsortedfile ) ) break; 136 140 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 numbers141 for ( counter; size ) { // read unsorted numbers 138 142 unsortedfile | values[counter]; 139 if ( counter != 0 && counter % ValuesPerLine == 0 ) sortedfile | endl | " ";143 if ( counter != 0 && counter % ValuesPerLine == 0 ) sortedfile | nl | " "; 140 144 sortedfile | values[counter]; 141 145 if ( counter < size - 1 && (counter + 1) % ValuesPerLine != 0 ) sortedfile | ' '; 142 146 } // for 143 sortedfile | endl;147 sortedfile | nl; 144 148 if ( size > 0 ) { // values to sort ? 145 149 Quicksort QS = { values, size - 1, 0 }; // sort values 146 150 } // wait until sort tasks terminate 147 for ( int counter = 0; counter < size; counter += 1 ) {// print sorted list148 if ( counter != 0 && counter % ValuesPerLine == 0 ) sortedfile | endl | " ";151 for ( counter; size ) { // print sorted list 152 if ( counter != 0 && counter % ValuesPerLine == 0 ) sortedfile | nl | " "; 149 153 sortedfile | values[counter]; 150 154 if ( counter < size - 1 && (counter + 1) % ValuesPerLine != 0 ) sortedfile | ' '; 151 155 } // for 152 sortedfile | endl | endl;156 sortedfile | nl | nl; 153 157 154 158 delete( values ); … … 159 163 processor processors[ (1 << depth) - 1 ] __attribute__(( unused )); // create 2^depth-1 kernel threads 160 164 161 int * values = alloc( size ); // values to be sorted, too large to put on stack162 for ( int counter = 0; counter < size; counter += 1 ) {// generate unsorted numbers165 int * values = alloc( size ); // values to be sorted, too large to put on stack 166 for ( counter; size ) { // generate unsorted numbers 163 167 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] ); 164 171 } // for 165 172 { … … 167 174 } // wait until sort tasks terminate 168 175 169 // for ( int counter = 0; counter < size - 1; counter += 1 ) {// check sorting176 // for ( counter; size - 1 ) { // check sorting 170 177 // if ( values[counter] > values[counter + 1] ) abort(); 171 178 // } // for … … 175 182 } // main 176 183 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 177 186 // Local Variables: // 178 187 // tab-width: 4 // 179 // compile-command: "cfa quickSort.c " //188 // compile-command: "cfa quickSort.cfa" // 180 189 // End: //
Note:
See TracChangeset
for help on using the changeset viewer.