I'm trying to convert a quicksort to a parallel quicksort with openMp and I'm not sure if I'm on the right track. The regular quicksort I have works fine its the parallel version I'm not sure about. I want to have the parallel version use around 4 threads so it will execute faster than the non parallel version. Any advice on where to implement the threads?
void quickSort(int arr[], int low, int high)
{
int pi;
if (low < high)
{
//pi is partitioning index, arr[p] is now at right place
pi = partition(arr, low, high);
// Separately sort elements before partition and after partition
quickSort(arr, low, pi - 1);
quickSort(arr, pi + 1, high);
}
}
void quickSort_parallel_omp(int arr[], int low, int high)
{
int pi;
if (low < high)
{
pi = partition(arr, low, high);
omp_set_nested(1);
#pragma omp parallel sections num_threads(Nthreads)
{ //Nthreads is declared in the main as int Nthreads = 4
#pragma omp section
quickSort_parallel_omp(arr, low, pi - 1);
#pragma omp section
quickSort_parallel_omp(arr, pi + 1, high);
}
}
}
EDIT: My question is not a duplicate, the question mine is being compared to asks for help in fixing its incorrect output. My output is fine, I am asking what else I should implement into my parallel sort to get it to execute in a faster time than the non parallel quick sort