Bump version to 19.1.0-rc3
[llvm-project.git] / offload / test / offloading / target_depend_nowait.cpp
blobb0d5408770bcaa908704bdee5daf7a1b20442f75
1 // RUN: %libomptarget-compilexx-run-and-check-generic
3 #include <omp.h>
4 #include <stdio.h>
6 #define N 1024
8 int A[N];
9 int B[N];
10 int C[N];
11 int main() {
12 for (int i = 0; i < N; i++)
13 A[i] = B[i] = i;
15 #pragma omp parallel num_threads(2)
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
21 // no data move since already mapped
22 #pragma omp target map(A, B) depend(out : A[0]) nowait
24 for (int i = 0; i < N; i++)
25 ++A[i];
26 for (int i = 0; i < N; i++)
27 ++B[i];
30 // no data move since already mapped
31 #pragma omp target teams num_teams(1) map(A, B) depend(out : A[0]) nowait
33 for (int i = 0; i < N; i++)
34 ++A[i];
35 for (int i = 0; i < N; i++)
36 ++B[i];
39 // A updated via update
40 #pragma omp target update from(A) depend(out : A[0]) nowait
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
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("Sum = %d.\n", Sum);
55 return Sum != 2 * N * (2 + N - 1 + 2) / 2;