xref: /llvm-project/offload/test/offloading/bug64959_compile_only.c (revision 330d8983d25d08580fc1642fea48b2473f47a9da)
1 // RUN: %libomptarget-compile-generic
2 // RUN: %libomptarget-compileopt-generic
3 
4 #include <stdio.h>
5 #define N 10
6 
main(void)7 int main(void) {
8   long int aa = 0;
9   int res = 0;
10 
11   int ng = 12;
12   int cmom = 14;
13   int nxyz = 5000;
14 
15 #pragma omp target teams distribute num_teams(nxyz)                            \
16     thread_limit(ng *(cmom - 1)) map(tofrom : aa)
17   for (int gid = 0; gid < nxyz; gid++) {
18 #pragma omp parallel for collapse(2)
19     for (unsigned int g = 0; g < ng; g++) {
20       for (unsigned int l = 0; l < cmom - 1; l++) {
21         int a = 0;
22 #pragma omp parallel for reduction(+ : a)
23         for (int i = 0; i < N; i++) {
24           a += i;
25         }
26 #pragma omp atomic
27         aa += a;
28       }
29     }
30   }
31   long exp = (long)ng * (cmom - 1) * nxyz * (N * (N - 1) / 2);
32   printf("The result is = %ld exp:%ld!\n", aa, exp);
33   if (aa != exp) {
34     printf("Failed %ld\n", aa);
35     return 1;
36   }
37   // CHECK: Success
38   printf("Success\n");
39   return 0;
40 }
41