這是迄今爲止我所知道的常規合併排序完美工作,但我不確定我爲openMP並行合併排序所做的操作是否正確。目標是通過將openMP併入並使用從一類應用程序中獲取的數據來優化合並排序。對於我所認爲的數據,我認爲它是線程,因爲使用多線程應該優化它。有關我應該在哪裏實施線索或提示的任何建議?如何將合併排序轉換爲並行合併排序
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);
}
}
[Parallel Merge-Sort in OpenMP]的可能重複(https://stackoverflow.com/questions/13811114/parallel- merge-sort-in-openmp) – Zulan