| 1 | // RUN: %libomptarget-compilexx-run-and-check-generic |
| 2 | |
| 3 | // REQUIRES: gpu |
| 4 | // UNSUPPORTED: nvptx64-nvidia-cuda |
| 5 | // UNSUPPORTED: nvptx64-nvidia-cuda-LTO |
| 6 | // UNSUPPORTED: amdgcn-amd-amdhsa |
| 7 | |
| 8 | #include <omp.h> |
| 9 | #include <stdio.h> |
| 10 | |
| 11 | #define N 1000000 |
| 12 | |
| 13 | int A[N]; |
| 14 | int main() { |
| 15 | for (int i = 0; i < N; i++) |
| 16 | A[i] = 1; |
| 17 | |
| 18 | int sum[1]; |
| 19 | sum[0] = 0; |
| 20 | |
| 21 | #pragma omp target teams distribute parallel for num_teams(256) \ |
| 22 | schedule(static, 1) map(to \ |
| 23 | : A[:N]) map(tofrom \ |
| 24 | : sum[:1]) |
| 25 | { |
| 26 | for (int i = 0; i < N; i++) { |
| 27 | #pragma omp critical |
| 28 | { sum[0] += A[i]; } |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | // CHECK: SUM = 1000000 |
| 33 | printf(format: "SUM = %d\n" , sum[0]); |
| 34 | |
| 35 | return 0; |
| 36 | } |
| 37 | |