Changeset edb6f79 for src/tests/concurrent/examples/quickSort.c
- Timestamp:
- Dec 13, 2017, 6:24:17 PM (7 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- a1ecdd1
- Parents:
- 2db79e5
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/tests/concurrent/examples/quickSort.c
r2db79e5 redb6f79 9 9 // Created On : Wed Dec 6 12:15:52 2017 10 10 // Last Modified By : Peter A. Buhr 11 // Last Modified On : Mon Dec 11 17:00:25201712 // Update Count : 1 2611 // Last Modified On : Wed Dec 13 18:20:18 2017 12 // Update Count : 138 13 13 // 14 14 … … 19 19 #include <string.h> // strcmp 20 20 21 forall( otype T | { T ?<?( T, T ); } ) 21 22 thread Quicksort { 22 int * values;// communication variables23 T * values; // communication variables 23 24 int low, high, depth; 24 25 }; 25 26 26 void ?{}( Quicksort & qs, int values[], int size, int depth ) { 27 forall( otype T | { T ?<?( T, T ); } ) 28 void ?{}( Quicksort(T) & qs, T values[], int size, int depth ) { 27 29 qs.values = values; qs.low = 0; qs.high = size; qs.depth = depth; 28 30 } // Quicksort 29 31 30 void main( Quicksort & qs ) { 32 forall( otype T | { T ?<?( T, T ); } ) 33 void main( Quicksort(T) & qs ) { 31 34 // nested routines: information hiding 32 35 33 void ?{}( Quicksort & qs, intvalues[], int low, int high, int depth ) {36 void ?{}( Quicksort(T) & qs, T values[], int low, int high, int depth ) { 34 37 qs.values = values; qs.low = low; qs.high = high; qs.depth = depth; 35 38 } // Quicksort 36 39 37 void sort( intvalues[], int low, int high, int depth ) {40 void sort( T values[], int low, int high, int depth ) { 38 41 int left, right; // index to left/right-hand side of the values 39 intpivot; // pivot value of values40 int swap;// temporary42 T pivot; // pivot value of values 43 T swap; // temporary 41 44 42 45 //verify(); // check for stack overflow due to recursion … … 65 68 depth -= 1; 66 69 //sout << &uThisTask() << " " << depth << endl; 67 Quicksort rqs = { values, low, right, depth }; // concurrently sort upper half70 Quicksort(T) rqs = { values, low, right, depth }; // concurrently sort upper half 68 71 //Quicksort lqs( values, left, high, depth ); // concurrently sort lower half 69 72 sort( values, left, high, depth ); // concurrently sort lower half … … 92 95 exit( EXIT_FAILURE ); // TERMINATE! 93 96 } // usage 97 98 99 #define ELEMTYPE int 94 100 95 101 int main( int argc, char * argv[] ) { … … 134 140 unsortedfile | size; // read number of elements in the list 135 141 if ( eof( unsortedfile ) ) break; 136 int * values = anew( size );// values to be sorted, too large to put on stack142 ELEMTYPE * values = anew( size ); // values to be sorted, too large to put on stack 137 143 for ( int counter = 0; counter < size; counter += 1 ) { // read unsorted numbers 138 144 unsortedfile | values[counter]; … … 143 149 sortedfile | endl; 144 150 if ( size > 0 ) { // values to sort ? 145 Quicksort QS = { values, size - 1, 0 }; // sort values151 Quicksort(ELEMTYPE) QS = { values, size - 1, 0 }; // sort values 146 152 } // wait until sort tasks terminate 147 153 for ( int counter = 0; counter < size; counter += 1 ) { // print sorted list … … 159 165 processor processors[ (1 << depth) - 1 ] __attribute__(( unused )); // create 2^depth-1 kernel threads 160 166 161 int * values = anew( size );// values to be sorted, too large to put on stack167 ELEMTYPE * values = anew( size ); // values to be sorted, too large to put on stack 162 168 for ( int counter = 0; counter < size; counter += 1 ) { // generate unsorted numbers 163 169 values[counter] = size - counter; // descending values 164 170 } // for 165 171 { 166 Quicksort QS = { values, size - 1, depth }; // sort values172 Quicksort(ELEMTYPE) QS = { values, size - 1, depth }; // sort values 167 173 } // wait until sort tasks terminate 168 174
Note: See TracChangeset
for help on using the changeset viewer.