| 1 |
#include <omp.h> |
| 2 |
#include <stdlib.h> |
| 3 |
#include <stdio.h> |
| 4 |
|
| 5 |
/* PR112779 item (B) */ |
| 6 |
|
| 7 |
/* Check that the target_device selector correctly matches device numbers |
| 8 |
and handles kind=host|nohost|any. */ |
| 9 |
|
| 10 |
static int |
| 11 |
check_explicit_device (int d, int expect_host) |
| 12 |
{ |
| 13 |
int ok = 0; |
| 14 |
if (expect_host) |
| 15 |
{ |
| 16 |
#pragma omp metadirective \ |
| 17 |
when (target_device={device_num(d), kind("host")} : nothing) \ |
| 18 |
otherwise (error at(execution) message("check_explicit_device host")) |
| 19 |
ok = 1; |
| 20 |
} |
| 21 |
else |
| 22 |
{ |
| 23 |
#pragma omp metadirective \ |
| 24 |
when (target_device={device_num(d), kind("nohost")} : nothing) \ |
| 25 |
otherwise (error at(execution) message("check_explicit_device nohost")) |
| 26 |
ok = 1; |
| 27 |
} |
| 28 |
|
| 29 |
return ok; |
| 30 |
} |
| 31 |
|
| 32 |
static int |
| 33 |
check_implicit_device (int d, int expect_host) |
| 34 |
{ |
| 35 |
int ok = 0; |
| 36 |
omp_set_default_device (d); |
| 37 |
|
| 38 |
if (expect_host) |
| 39 |
{ |
| 40 |
#pragma omp metadirective \ |
| 41 |
when (target_device={kind("host")} : nothing) \ |
| 42 |
otherwise (error at(execution) message("check_implicit_device host")) |
| 43 |
ok = 1; |
| 44 |
} |
| 45 |
else |
| 46 |
{ |
| 47 |
#pragma omp metadirective \ |
| 48 |
when (target_device={kind("nohost")} : nothing) \ |
| 49 |
otherwise (error at(execution) message("check_implicit_device nohost")) |
| 50 |
ok = 1; |
| 51 |
} |
| 52 |
#pragma omp metadirective \ |
| 53 |
when (target_device={kind("any")} : nothing) \ |
| 54 |
otherwise (error at(execution) message("check_implicit_device any")) |
| 55 |
ok = 1; |
| 56 |
omp_set_default_device (omp_initial_device); |
| 57 |
|
| 58 |
return ok; |
| 59 |
} |
| 60 |
|
| 61 |
int |
| 62 |
main (void) |
| 63 |
{ |
| 64 |
printf ("Checking omp_initial_device\n"); |
| 65 |
check_explicit_device (omp_initial_device, 1); |
| 66 |
check_implicit_device (omp_initial_device, 1); |
| 67 |
int n = omp_get_num_devices (); |
| 68 |
printf ("There are %d devices\n", n); |
| 69 |
for (int i = 0; i < n; i++) |
| 70 |
{ |
| 71 |
printf ("Checking device %d\n", i); |
| 72 |
check_explicit_device (i, 0); |
| 73 |
check_implicit_device (i, 0); |
| 74 |
} |
| 75 |
return 0; |
| 76 |
} |