1 // RUN: %libomptarget-compile-run-and-check-aarch64-unknown-linux-gnu 2 // RUN: %libomptarget-compile-run-and-check-powerpc64-ibm-linux-gnu 3 // RUN: %libomptarget-compile-run-and-check-powerpc64le-ibm-linux-gnu 4 // RUN: %libomptarget-compile-run-and-check-x86_64-pc-linux-gnu 5 // RUN: %libomptarget-compile-run-and-check-nvptx64-nvidia-cuda 6 7 #include <cstdio> 8 #include <cstdlib> 9 10 #define NUM 1024 11 12 class C { 13 public: 14 int *a; 15 }; 16 17 #pragma omp declare mapper(id: C s) map(s.a[0:NUM]) 18 main()19int main() { 20 C c; 21 int sum = 0; 22 c.a = (int*) malloc(sizeof(int)*NUM); 23 for (int i = 0; i < NUM; i++) { 24 c.a[i] = 1; 25 } 26 #pragma omp target enter data map(mapper(id),alloc: c) 27 #pragma omp target teams distribute parallel for 28 for (int i = 0; i < NUM; i++) { 29 c.a[i] = 0; 30 } 31 #pragma omp target update from(mapper(id): c) 32 for (int i = 0; i < NUM; i++) { 33 sum += c.a[i]; 34 } 35 // CHECK: Sum (after first update from) = 0 36 printf("Sum (after first update from) = %d\n", sum); 37 for (int i = 0; i < NUM; i++) { 38 c.a[i] = 1; 39 } 40 #pragma omp target update to(mapper(id): c) 41 #pragma omp target teams distribute parallel for 42 for (int i = 0; i < NUM; i++) { 43 ++c.a[i]; 44 } 45 sum = 0; 46 for (int i = 0; i < NUM; i++) { 47 sum += c.a[i]; 48 } 49 // CHECK: Sum (after update to) = 1024 50 printf("Sum (after update to) = %d\n", sum); 51 #pragma omp target update from(mapper(id): c) 52 sum = 0; 53 for (int i = 0; i < NUM; i++) { 54 sum += c.a[i]; 55 } 56 // CHECK: Sum (after second update from) = 2048 57 printf("Sum (after second update from) = %d\n", sum); 58 #pragma omp target exit data map(mapper(id),delete: c) 59 return 0; 60 } 61 62