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

source code of offload/test/offloading/target_critical_region.cpp