| 1 |
/* { dg-do run } */ |
| 2 |
|
| 3 |
#define N 100 |
| 4 |
|
| 5 |
#include <stdio.h> |
| 6 |
#include <omp.h> |
| 7 |
|
| 8 |
int |
| 9 |
f (int a[], int num) |
| 10 |
{ |
| 11 |
int on_device = 0; |
| 12 |
int i; |
| 13 |
|
| 14 |
#pragma omp metadirective \ |
| 15 |
when (target_device={device_num(num), kind("gpu")}: \ |
| 16 |
target parallel for map(to: a[0:N]), map(from: on_device)) \ |
| 17 |
default (parallel for private (on_device)) |
| 18 |
for (i = 0; i < N; i++) |
| 19 |
{ |
| 20 |
a[i] += i; |
| 21 |
on_device = 1; |
| 22 |
} |
| 23 |
|
| 24 |
return on_device; |
| 25 |
} |
| 26 |
|
| 27 |
int |
| 28 |
main (void) |
| 29 |
{ |
| 30 |
int a[N]; |
| 31 |
int on_device_count = 0; |
| 32 |
int i; |
| 33 |
|
| 34 |
for (i = 0; i < N; i++) |
| 35 |
a[i] = i; |
| 36 |
|
| 37 |
for (i = 0; i <= omp_get_num_devices (); i++) |
| 38 |
on_device_count += f (a, i); |
| 39 |
|
| 40 |
if (on_device_count != omp_get_num_devices ()) |
| 41 |
return 1; |
| 42 |
|
| 43 |
for (i = 0; i < N; i++) |
| 44 |
if (a[i] != 2 * i) |
| 45 |
return 2; |
| 46 |
|
| 47 |
return 0; |
| 48 |
} |