1// RUN: %libomptarget-compilexx-run-and-check-generic
2
3#include <omp.h>
4#include <stdio.h>
5
6#define N 1024
7
8int A[N];
9int B[N];
10int C[N];
11int main() {
12 for (int i = 0; i < N; i++)
13 A[i] = B[i] = i;
14
15#pragma omp parallel num_threads(2)
16 {
17 if (omp_get_thread_num() == 1) {
18// map data A & B and move to
19#pragma omp target enter data map(to : A, B) depend(out : A[0]) nowait
20
21// no data move since already mapped
22#pragma omp target map(A, B) depend(out : A[0]) nowait
23 {
24 for (int i = 0; i < N; i++)
25 ++A[i];
26 for (int i = 0; i < N; i++)
27 ++B[i];
28 }
29
30// no data move since already mapped
31#pragma omp target teams num_teams(1) map(A, B) depend(out : A[0]) nowait
32 {
33 for (int i = 0; i < N; i++)
34 ++A[i];
35 for (int i = 0; i < N; i++)
36 ++B[i];
37 }
38
39// A updated via update
40#pragma omp target update from(A) depend(out : A[0]) nowait
41
42// B updated via exit, A just released
43#pragma omp target exit data map(release : A) map(from : B) depend(out : A[0]) \
44 nowait
45 } // if
46 } // parallel
47
48 int Sum = 0;
49 for (int i = 0; i < N; i++)
50 Sum += A[i] + B[i];
51 // Sum is 2 * N * (2 + N - 1 + 2) / 2
52 // CHECK: Sum = 1051648.
53 printf(format: "Sum = %d.\n", Sum);
54
55 return Sum != 2 * N * (2 + N - 1 + 2) / 2;
56}
57

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