0

I am having a problem with writing a parallel quicksort using the boost threads library. I have narrowed it down to one snippet of code, this code works but is serial:

void local_quicksort(vector<int>& input)
{
    //Divide vector into equal sized chunks then quicksort the subsections
    for (int i = 0; i < NUM_THREADS; i++)
    {   
        quicksort(input, i * input.size()/NUM_THREADS, (i+1) * input.size()/NUM_THREADS);
    }   
    return;
}

I am trying to use this snippet to parallelize the same function:

void local_quicksort(vector<int>& input)
{
    boost::thread_group bthreads;

    //Divide vector into equal sized chunks for each thread then quicksort the subsections
    for (int i = 0; i < NUM_THREADS; i++)
    {   
        bthreads.create_thread(boost::bind(&quicksort, input, i * input.size()/NUM_THREADS, (i+1) * input.size()/NUM_THREADS));

    }   

    bthreads.join_all();
    return;
}

The part that I can't figure out is that the parallelized version does seem to be calling quicksort (I put a print statement in the quicksort function and it is definitely being called) but no sorting is actually being done (the output is completely unsorted). Can anybody tell me what's happening here?

Dan
  • 2,647
  • 2
  • 27
  • 37

0 Answers0