简体   繁体   English

并行递归Bitonic排序比串行(OpenMP)慢

[英]Parallel Recursive Bitonic Sort slower than Serial (OpenMP)

My OpenMP (C) parallel code is slower than the serial bitonic sort code and although I have done all the possible combinations I could think of, I can't find the problem. 我的OpenMP(C)并行代码比串行双音排序代码慢,尽管我已经完成了所有可能的组合,但是我找不到问题所在。

Here is part of the code: 这是代码的一部分:

void recBitonicSortOpenMP( int lo, int cnt, int dir ) {
   if (  cnt >  1 ) {
         int k = cnt / 2;
         #pragma omp parallel sections 
         {

         #pragma omp section 
         recBitonicSortOpenMP( lo,     k, ASCENDING );

         #pragma omp section    
         recBitonicSortOpenMP( lo + k, k, DESCENDING );

         }
         bitonicMergeOpenMP( lo, cnt, dir );

   }

}

It is an implementation of Bitonic Sort. 它是Bitonic Sort的实现。

For recursive problems like this use OpenMP tasks, not nested parallelism and sections. 对于此类递归问题,请使用OpenMP任务,而不是嵌套的并行性和节。 http://cs.umw.edu/~finlayson/class/fall16/cpsc425/notes/24-sorting.html gives you a good example to follow... http://cs.umw.edu/~finlayson/class/fall16/cpsc425/notes/24-sorting.html为您提供了一个很好的示例,可以遵循...

You should try to parallelize the imperative version of the algorithm. 您应该尝试并行化该命令式的命令式版本。 I think the recursive version is an inherently serial problem. 我认为递归版本是一个固有的串行问题。

There are many pragmas useful to parallelize "For" cycles. 有许多实用程序可用于并行化“ For”循环。

http://www.openmp.org/specifications/ http://www.openmp.org/specifications/

Two version of the algorithm: 算法的两个版本:

https://www.cs.duke.edu/courses/fall08/cps196.1/Pthreads/bitonic.c https://www.cs.duke.edu/courses/fall08/cps196.1/Pthreads/bitonic.c

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM