与"#pragma omp single"相比,“#pragma omp master"有什么好处? [英] What is the benefit of '#pragma omp master' as opposed to '#pragma omp single'?
问题描述
在OpenMP中,#pragma omp master
指令内的任何代码均由单个线程(主线程)执行,在该区域的末尾没有隐含的屏障. (请参阅有关LLNL OpenMP教程中MASTER指令的部分.)
In OpenMP any code inside a #pragma omp master
directive is executed by a single thread (the master), without an implied barrier at end of the region. (See section on MASTER directive in the LLNL OpenMP tutorial).
这似乎与#pragma omp single nowait
等效(除了不是"master",任何线程都可以执行单个区域).
This seems equivalent to #pragma omp single nowait
(with the exception that rather than the 'master', any thread may execute the single region).
在什么情况下(如果有)使用#pragma omp master
是否有益?
Under what circumstances, if any, is it beneficial to use #pragma omp master
?
推荐答案
尽管single nowait
构造在大多数情况下都等效于master
构造:
Though a single nowait
construct is most of the time equivalent to a master
construct:
-
如果需要,可以在工作共享结构中使用
master
结构.single nowait
构造不是这种情况,因为两个工作共享构造不能嵌套在同一平行区域内
The
master
construct can be used inside a work-sharing construct, should any need arise. This is not the case for asingle nowait
construct, as two work-sharing constructs can't be nested within the same parallel region
某些库希望主线程执行某些操作.例如,MPI库在初始化时具有等于
Some libraries want the main thread to perform certain operations. For instance the MPI library, when initialized with a level of thread support equal to MPI_THREAD_FUNNELED
, allows only the main threads to make MPI calls
这篇关于与"#pragma omp single"相比,“#pragma omp master"有什么好处?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!