与"#pragma omp single"相比,“#pragma omp master"有什么好处? [英] What is the benefit of '#pragma omp master' as opposed to '#pragma omp single'?

查看:1118
本文介绍了与"#pragma omp single"相比,“#pragma omp master"有什么好处?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在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:

  1. 如果需要,可以在工作共享结构中使用master结构. single nowait构造不是这种情况,因为两个工作共享构造不能嵌套在同一平行区域内

  1. The master construct can be used inside a work-sharing construct, should any need arise. This is not the case for a single nowait construct, as two work-sharing constructs can't be nested within the same parallel region

某些库希望主线程执行某些操作.例如,MPI库在初始化时具有等于 ,仅允许主线程进行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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆