Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / openmp / libomptarget / test / offloading / target_critical_region.cpp
blob9a741bef6c591598782e0e896a18c506d0753e76
1 // RUN: %libomptarget-compilexx-run-and-check-generic
3 // UNSUPPORTED: aarch64-unknown-linux-gnu
4 // UNSUPPORTED: aarch64-unknown-linux-gnu-LTO
5 // UNSUPPORTED: nvptx64-nvidia-cuda
6 // UNSUPPORTED: nvptx64-nvidia-cuda-LTO
7 // UNSUPPORTED: x86_64-pc-linux-gnu
8 // UNSUPPORTED: x86_64-pc-linux-gnu-LTO
9 // UNSUPPORTED: amdgcn-amd-amdhsa
11 #include <omp.h>
12 #include <stdio.h>
14 #define N 1000000
16 int A[N];
17 int main() {
18 for (int i = 0; i < N; i++)
19 A[i] = 1;
21 int sum[1];
22 sum[0] = 0;
24 #pragma omp target teams distribute parallel for num_teams(256) \
25 schedule(static, 1) map(to \
26 : A[:N]) map(tofrom \
27 : sum[:1])
29 for (int i = 0; i < N; i++) {
30 #pragma omp critical
31 { sum[0] += A[i]; }
35 // CHECK: SUM = 1000000
36 printf("SUM = %d\n", sum[0]);
38 return 0;