multithreading - OpenMP 5.1 规范是否允许使用非矩形循环的折叠子句?

标签 multithreading loops parallel-processing openmp

考虑以下 OpenMP 代码:

#pragma omp target teams distribute parallel for collapse(4) map(tofrom: a) private(i,j,k,l)
for (i = 0; i < SIZE_N; i++) {
  for (j = 0; j < SIZE_M; j++) {
    for (k = i; k < SIZE_N; k++) {
       for (l = 0; l < SIZE_M; l++) {
         a[i][j][k][l] += i+2*j+3*k+4*l;
       }
    }
  }
}

此代码符合 OpenMP Spec 5.1 标准吗?我在规范中找不到任何不允许此类代码的措辞,但我不确定我错过了什么。

谢谢!

最佳答案

Is this OpenMP Spec 5.1 compliant?

Support for non-rectangular collapsed loops是的,它是合规的。

Before OpenMP 5.0, all OpenMP looping constructs (worksharing loops, simd, distribute, taskloop, and combined or composite constructs based on those) were required to be rectangular. This means that all of the lower bound, upper bound, and increment expressions of all the associated loops in the loop nest were required to be invariant against the outermost loop. OpenMP 5.0 still requires all the increment expressions to be loop-invariant, but allows some cases where the lower and upper bound expressions of the inner loops can be based on a single outer-loop iterator.

I cannot find in the spec any wording that does not allowed this kind of code, but I am not sure I am missing something.

OpenMP 5.0 specification第 625 页,版本 4.5 到 5.0 的差异,可以阅读以下内容:

The collapse of associated loops that are imperfectly nested loops was defined for the worksharing-loop (see Section 2.9.2 on page 101), simd (see Section 2.9.3.1 on page 110), taskloop (see Section 2.10.2 on page 140) and distribute (see Section 2.9.4.2 on page 123) constructs.

关于multithreading - OpenMP 5.1 规范是否允许使用非矩形循环的折叠子句?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68382400/

相关文章:

c - 为什么我的全局分配结构没有正确更新值?

ruby - 异步运行 Sinatra 服务器和子进程

c++ - 如何使用户输入多行

java - 使用 Enum 的单例与使用双重检查锁定的单例

java - synchronized(this) 是否意味着当前线程对象获得了自己的锁?

linux - 在具有多个(物理)CPU 的系统上的多线程进程中,如何处理线程调度?

c# - 在 Parallel.For 循环内使用 Span

python-3.x - 如何在不使用光线模式的情况下以平行光线运行函数?

java - Runnable 中的无限循环消失了?

python - 循环遍历python中的特定文件