This is what I have so far, the regular merge sort works perfectly but I'm not sure if what I've done for the parallel merge sort with the openMP is correct or not. The goal is to optimize the merge sort by incorporating openMP into it and using data taken from a class of applications. For the data taken I figured I'd make it be threads since the use of multiple threads should optimize it for the better. Any advice on where I should implement the threads here or tips?
void mergeSort(int arr[], int start, int end)
{
if(start < end)
{
int middle = (start + end) / 2;
/* sort left half */
mergeSort(arr, start, middle);
/* sort right half */
mergeSort(arr, middle + 1, end);
/* merge the two halves */
merge(arr, start, end);
}
}
void mergesort_parallel_omp(int a[], int start, int end)//parallelized version
{
int threads = 2;
if(start < end)
{
int middle = (start + end) / 2;
omp_set_nested(1); /////
omp_set_num_threads(threads);
#pragma omp parallel sections
{
#pragma omp section
mergesort_parallel_omp(a, start, middle);
#pragma omp section
mergesort_parallel_omp(a, middle + 1, end);
}
merge(a, start, end);
}
}