Bump version to 19.1.0-rc3
[llvm-project.git] / offload / test / mapping / declare_mapper_target_update.cpp
blobfe4597b76908fa618c880d04ba4e226b2c0451da
1 // RUN: %libomptarget-compile-run-and-check-generic
3 #include <cstdio>
4 #include <cstdlib>
6 #define NUM 1024
8 class C {
9 public:
10 int *a;
13 #pragma omp declare mapper(id : C s) map(s.a[0 : NUM])
15 int main() {
16 C c;
17 int sum = 0;
18 c.a = (int *)malloc(sizeof(int) * NUM);
19 for (int i = 0; i < NUM; i++) {
20 c.a[i] = 1;
22 #pragma omp target enter data map(mapper(id), alloc : c)
23 #pragma omp target teams distribute parallel for
24 for (int i = 0; i < NUM; i++) {
25 c.a[i] = 0;
27 #pragma omp target update from(mapper(id) : c)
28 for (int i = 0; i < NUM; i++) {
29 sum += c.a[i];
31 // CHECK: Sum (after first update from) = 0
32 printf("Sum (after first update from) = %d\n", sum);
33 for (int i = 0; i < NUM; i++) {
34 c.a[i] = 1;
36 #pragma omp target update to(mapper(id) : c)
37 #pragma omp target teams distribute parallel for
38 for (int i = 0; i < NUM; i++) {
39 ++c.a[i];
41 sum = 0;
42 for (int i = 0; i < NUM; i++) {
43 sum += c.a[i];
45 // CHECK: Sum (after update to) = 1024
46 printf("Sum (after update to) = %d\n", sum);
47 #pragma omp target update from(mapper(id) : c)
48 sum = 0;
49 for (int i = 0; i < NUM; i++) {
50 sum += c.a[i];
52 // CHECK: Sum (after second update from) = 2048
53 printf("Sum (after second update from) = %d\n", sum);
54 #pragma omp target exit data map(mapper(id), delete : c)
55 return 0;