Ignore:
Timestamp:
Dec 13, 2017, 6:24:17 PM (6 years ago)
Author:
Peter A. Buhr <pabuhr@…>
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
Message:

generic quicksort, not working

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/tests/concurrent/examples/quickSort.c

    r2db79e5 redb6f79  
    99// Created On       : Wed Dec  6 12:15:52 2017
    1010// Last Modified By : Peter A. Buhr
    11 // Last Modified On : Mon Dec 11 17:00:25 2017
    12 // Update Count     : 126
     11// Last Modified On : Wed Dec 13 18:20:18 2017
     12// Update Count     : 138
    1313//
    1414
     
    1919#include <string.h>                                                                             // strcmp
    2020
     21forall( otype T | { T ?<?( T, T ); } )
    2122thread Quicksort {
    22         int * values;                                                                           // communication variables
     23        T * values;                                                                                     // communication variables
    2324        int low, high, depth;
    2425};
    2526
    26 void ?{}( Quicksort & qs, int values[], int size, int depth ) {
     27forall( otype T | { T ?<?( T, T ); } )
     28void ?{}( Quicksort(T) & qs, T values[], int size, int depth ) {
    2729        qs.values = values;  qs.low = 0;  qs.high = size;  qs.depth = depth;
    2830} // Quicksort
    2931
    30 void main( Quicksort & qs ) {
     32forall( otype T | { T ?<?( T, T ); } )
     33void main( Quicksort(T) & qs ) {
    3134        // nested routines: information hiding
    3235
    33         void ?{}( Quicksort & qs, int values[], int low, int high, int depth ) {
     36        void ?{}( Quicksort(T) & qs, T values[], int low, int high, int depth ) {
    3437                qs.values = values;  qs.low = low;  qs.high = high;  qs.depth = depth;
    3538        } // Quicksort
    3639
    37         void sort( int values[], int low, int high, int depth ) {
     40        void sort( T values[], int low, int high, int depth ) {
    3841                int left, right;                                                                // index to left/right-hand side of the values
    39                 int pivot;                                                                              // pivot value of values
    40                 int swap;                                                                               // temporary
     42                T pivot;                                                                                // pivot value of values
     43                T swap;                                                                                 // temporary
    4144
    4245                //verify();                                                                             // check for stack overflow due to recursion
     
    6568                                depth -= 1;
    6669                                //sout << &uThisTask() << " " << depth << endl;
    67                                 Quicksort rqs = { values, low, right, depth }; // concurrently sort upper half
     70                                Quicksort(T) rqs = { values, low, right, depth }; // concurrently sort upper half
    6871                                //Quicksort lqs( values, left, high, depth ); // concurrently sort lower half
    6972                                sort( values, left, high, depth );              // concurrently sort lower half
     
    9295        exit( EXIT_FAILURE );                                                           // TERMINATE!
    9396} // usage
     97
     98
     99#define ELEMTYPE int
    94100
    95101int main( int argc, char * argv[] ) {
     
    134140                        unsortedfile | size;                                            // read number of elements in the list
    135141                  if ( eof( unsortedfile ) ) break;
    136                         int * values = anew( size );                            // values to be sorted, too large to put on stack
     142                        ELEMTYPE * values = anew( size );                       // values to be sorted, too large to put on stack
    137143                        for ( int counter = 0; counter < size; counter += 1 ) { // read unsorted numbers
    138144                                unsortedfile | values[counter];
     
    143149                        sortedfile | endl;
    144150                        if ( size > 0 ) {                                                       // values to sort ?
    145                                 Quicksort QS = { values, size - 1, 0 }; // sort values
     151                                Quicksort(ELEMTYPE) QS = { values, size - 1, 0 }; // sort values
    146152                        } // wait until sort tasks terminate
    147153                        for ( int counter = 0; counter < size; counter += 1 ) { // print sorted list
     
    159165                processor processors[ (1 << depth) - 1 ] __attribute__(( unused )); // create 2^depth-1 kernel threads
    160166
    161                 int * values = anew( size );                                    // values to be sorted, too large to put on stack
     167                ELEMTYPE * values = anew( size );                               // values to be sorted, too large to put on stack
    162168                for ( int counter = 0; counter < size; counter += 1 ) { // generate unsorted numbers
    163169                        values[counter] = size - counter;                       // descending values
    164170                } // for
    165171                {
    166                         Quicksort QS = { values, size - 1, depth }; // sort values
     172                        Quicksort(ELEMTYPE) QS = { values, size - 1, depth }; // sort values
    167173                } // wait until sort tasks terminate
    168174
Note: See TracChangeset for help on using the changeset viewer.