c – 在两个连续的pragma omp的情况下隐式屏障vs nowait

c – 在两个连续的pragma omp的情况下隐式屏障vs nowait,第1张

概述查看文档 here,以下结构已明确定义: #pragma omp parallel //Line 1{#pragma omp for nowait //Line 3 for (i=0; i<N; i++) a[i] = // some expression#pragma omp for //Line 6 for (i 查看文档 here,以下结构已明确定义:
#pragma omp parallel          //line 1{#pragma omp for Nowait        //line 3  for (i=0; i<N; i++)    a[i] = // some Expression#pragma omp for               //line 6  for (i=0; i<N; i++)    b[i] = ...... a[i] ......}

以来

Here the Nowait clause implIEs that threads can start on the second loop while other threads are still working on the first. Since the two loops use the same schedule here,an iteration that uses a[i] can indeed rely on it that that value has been computed.

我很难理解为什么会这样.假设第3行是:

#pragma omp for

然后,由于在第6行之前存在隐式屏障,因此下一个for循环将在完全计算的所有索引处具有值.但是,在第3行没有等待的情况下,它会如何运作?

假设,第1行触发4个线程,t1,t2,t3和t4.假设N为8,则第一个for循环中的索引分区为:

t1: 0,4t2: 1,5t3: 2,6t4: 3,7

假设t1首先完成索引0和4并在第6行登陆现在究竟发生了什么?如何保证它现在可以在相同的索引0和4上运行,在上一次迭代中a值是否正确计算?如果第二个for循环访问[i 1]怎么办?

解决方法 你引用的材料是错误的.如果向两个循环添加调度(静态),它就变得正确了 – 这保证了连续循环的线程之间的索引分布相同.默认计划是实现定义的,您不能认为它是静态的.引用标准:

Different loop regions with the same schedule and iteration count,
even if they occur in the same parallel region,can distribute
iterations among threads differently. The only exception is for the
static schedule as specifIEd in table 2.5. Programs that depend on
which thread executes a particular iteration under any other
circumstances are non-conforming.

如果第二个for循环访问[i 1],你必须绝对离开障碍.

总结

以上是内存溢出为你收集整理的c – 在两个连续的pragma omp的情况下隐式屏障vs nowait全部内容,希望文章能够帮你解决c – 在两个连续的pragma omp的情况下隐式屏障vs nowait所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1257840.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-07
下一篇 2022-06-07

发表评论

登录后才能评论

评论列表(0条)

保存