Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / openmp / libomptarget / test / offloading / bug64959.c
blob500911fa3f3163755ab8d17396dcc1a58ce4a905
1 // RUN: %libomptarget-compilexx-run-and-check-generic
2 // RUN: %libomptarget-compileoptxx-run-and-check-generic
4 // TODO: This requires malloc support for the threads states.
5 // UNSUPPORTED: amdgcn-amd-amdhsa
7 #include <omp.h>
8 #include <stdio.h>
9 #define N 10
11 int isCPU() { return 1; }
13 #pragma omp begin declare variant match(device = {kind(gpu)})
14 int isCPU() { return 0; }
15 #pragma omp end declare variant
17 int main(void) {
18 long int aa = 0;
19 int res = 0;
21 int ng = 12;
22 int cmom = 14;
23 int nxyz;
25 #pragma omp target map(from : nxyz, ng, cmom)
27 nxyz = isCPU() ? 2 : 5000;
28 ng = isCPU() ? 2 : 12;
29 cmom = isCPU() ? 2 : 14;
32 #pragma omp target teams distribute num_teams(nxyz) \
33 thread_limit(ng *(cmom - 1)) map(tofrom : aa)
34 for (int gid = 0; gid < nxyz; gid++) {
35 #pragma omp parallel for collapse(2)
36 for (unsigned int g = 0; g < ng; g++) {
37 for (unsigned int l = 0; l < cmom - 1; l++) {
38 int a = 0;
39 #pragma omp parallel for reduction(+ : a)
40 for (int i = 0; i < N; i++) {
41 a += i;
43 #pragma omp atomic
44 aa += a;
48 long exp = (long)ng * (cmom - 1) * nxyz * (N * (N - 1) / 2);
49 printf("The result is = %ld exp:%ld!\n", aa, exp);
50 if (aa != exp) {
51 printf("Failed %ld\n", aa);
52 return 1;
54 // CHECK: Success
55 printf("Success\n");
56 return 0;