嗨,我正在阅读这个网站 http://www.viva64.com/en/a/0054/对于第 17 点,它表示下面没有障碍的代码是错误的。为什么 ?我在 http://bisqwit.iki.fi/story/howto/openmp/#BarrierDirectiveAndTheNowaitClause 阅读除非使用 nowait 指令,否则在每个并行 block 的末尾以及每个部分的末尾都有一个隐式屏障,用于和单个语句。
struct MyType
{
~MyType();
};
MyType threaded_var;
#pragma omp threadprivate(threaded_var)
int main()
{
#pragma omp parallel
{
...
#pragma omp barrier // code is wrong without barrier.
}
}
请有人给我解释一下。谢谢
最佳答案
链接的网页在这一点上是错误的。并行部分的末尾实际上有一个隐含的障碍。
由于该网站似乎以 Windows 为重点,而 MS 仅支持 OpenMP 标准 2.0,因此可能值得注意的是,这种隐含的障碍不仅存在于当前标准 4.5 中,而且存在于 2.0 版中:
Upon completion of the parallel construct, the threads in the team synchronize at an implicit barrier, [...]
关于c++ - OpenMP 隐式屏障,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36105245/