| 1 |
#include <stdio.h> |
| 2 |
|
| 3 |
#define N 100 |
| 4 |
|
| 5 |
int main (void) |
| 6 |
{ |
| 7 |
int a[N], b[N], c[N]; |
| 8 |
|
| 9 |
for (int i = 0; i < N; i++) { |
| 10 |
a[i] = i * 2; |
| 11 |
b[i] = i * 3 + 1; |
| 12 |
} |
| 13 |
|
| 14 |
#pragma omp target enter data map (alloc: a, c) |
| 15 |
|
| 16 |
/* This should work as a has already been allocated. */ |
| 17 |
#pragma omp target update to (present: a) |
| 18 |
|
| 19 |
#pragma omp target map(present,alloc: a, c) |
| 20 |
for (int i = 0; i < N; i++) { |
| 21 |
if (a[i] != i * 2) |
| 22 |
__builtin_abort (); |
| 23 |
c[i] = 23*i; |
| 24 |
} |
| 25 |
|
| 26 |
#pragma omp target update from(present : c) |
| 27 |
for (int i = 0; i < N; i++) { |
| 28 |
if (c[i] != 23*i) |
| 29 |
__builtin_abort (); |
| 30 |
} |
| 31 |
|
| 32 |
fprintf (stderr, "CheCKpOInT\n"); |
| 33 |
/* { dg-output "CheCKpOInT(\n|\r\n|\r).*" } */ |
| 34 |
|
| 35 |
/* This should fail as b has not been allocated. */ |
| 36 |
/* { dg-output "libgomp: present clause: not present on the device \\(addr: 0x\[0-9a-f\]+, size: \[0-9\]+ \\(0x\[0-9a-f\]+\\), dev: \[0-9\]+\\\)" { target offload_device_nonshared_as } } */ |
| 37 |
/* { dg-shouldfail "present error triggered" { offload_device_nonshared_as } } */ |
| 38 |
#pragma omp target update to (present: b) |
| 39 |
|
| 40 |
#pragma omp target exit data map (from: c) |
| 41 |
} |