1// RUN: %libomp-compile-and-run
2
3// Support for collapse of non-rectangular loop nests was added in GCC 11
4// UNSUPPORTED: gcc-4, gcc-5, gcc-6, gcc-7, gcc-8, gcc-9, gcc-10
5
6#define N 10
7int arr[N][N][N];
8
9int collapsed(int mp) {
10 int Cnt = 0;
11#pragma omp for collapse(3)
12 for (int j = 0; j < mp; ++j) {
13 for (int i = j; i < mp; ++i) {
14 for (int i0 = 0; i0 < N; ++i0) {
15 arr[j][i][i0] = 1;
16 ++Cnt;
17 }
18 }
19 }
20 return Cnt;
21}
22
23int test(int mp) {
24 int Failed = 0;
25 for (int j = 0; j < mp; ++j) {
26 for (int i = 0; i < mp; ++i) {
27 for (int i0 = 0; i0 < N; ++i0) {
28 if ((i < j && arr[j][i][i0] == 0) || (i >= j && arr[j][i][i0] == 1))
29 continue;
30 ++Failed;
31 }
32 }
33 }
34 return Failed;
35}
36
37int main() {
38 int Res = collapsed(N);
39 return Res == N * (N + 1) && test(N) == 0;
40}
41

source code of openmp/runtime/test/worksharing/for/omp_for_non_rectangular.c