[clang] [llvm] [OpenMP] Diagnostic check for imperfect loop collapse (PR #96087)
Krzysztof Parzyszek via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 19 12:42:12 PDT 2024
kparzysz wrote:
> I think you're right for this particular test case, but I don't think that solution works in general. Consider something like:
>
> ```
> int arr1[N][N], arr2[N];
>
> #pragma omp parallel for collapse(2)
> {
> for (int i = 0; i < N; i++) {
> arr2[i] = i;
> for (int j = 0; j < N; j++) {
> arr1[i][j] += arr2[i];
> }
> }
> }
> ```
This already looks unsafe. Even if the collapsed nest has a form that preserves the correct order of execution, the reads and writes to arr1 and arr2 will be scattered over multiple iterations. The "parallel for" in itself doesn't have to respect any loop-carried dependencies.
https://github.com/llvm/llvm-project/pull/96087
More information about the cfe-commits
mailing list