并行快速排序不比顺序快速排序快
Parallel quick sort not running faster than sequential quick sort
我的QuickSort工作正常,它可以正确输出,但是并行版本的执行速度不超过非并行版本。我还能做什么使其运行速度更快?
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);
}
}
}
可能是将数据分配到多个并行处理单元中的开销并再次将结果组合起来超过了由于代码并行而导致的性能增益。我建议您增加输入大小,以查看可观的性能增长。
在您的情况下,创建线程的时间,将内存和时间切成o/s分配给每个线程的时间比简短数据所花费的时间更多。
仅在处理大量数据时才可以看到并行处理的性能。此外,在多处理或并行处理中还需要考虑许多其他因素,例如处理器的系统内存数量等。您可以在此主题上获得大量的在线文档。
相关文章:
- 如何修复我的快速排序实现?
- C++运行时错误与快速排序算法抛出堆栈转储错误
- 在 MIPS 中快速排序
- 不正确的比较和交换计数器输出用于快速排序功能
- 使用 std::vector C++快速排序,EXC_BAD_ACCESS代码 2
- 使用快速排序对 C++ 中的可视化工具错误进行排序
- 快速排序 - 三个中位数枢轴选择 - 某些元素顺序不正确
- 并行快速排序分区中的隔离错误
- 实现 3 路分区以实现快速排序
- 为什么这个快速排序实现给出了一个奇怪的输出
- 我的快速排序在对预排序的项目进行排序时失败,如何改进?
- 快速排序不适用于大型数组
- 快速排序;分段错误,但找不到位置?
- 快速排序函数在快速排序算法中如何工作?
- 3路随机快速排序分区功能
- 在最坏的情况下试验快速排序.它运行良好,但在最坏的情况下发生未知错误.我想
- 并行快速排序不比顺序快速排序快
- 一种按排序顺序保持元素的数据结构,支持快速插入和计算连续元素之间的最大差异
- 按字母顺序快速排序字符串矢量
- 用于按排序顺序存储元素并允许快速索引的数据结构