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