aboutsummaryrefslogtreecommitdiff
path: root/libgomp/testsuite/libgomp.c-c++-common/metadirective-target-device.c
blob: 7c2f7e5ad52a8dfcf88c1f4f094355a94ba1819c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <omp.h>
#include <stdlib.h>
#include <stdio.h>

/* PR112779 item (B)  */

/* Check that the target_device selector correctly matches device numbers
   and handles kind=host|nohost|any.  */

static int
check_explicit_device (int d, int expect_host)
{
  int ok = 0;
  if (expect_host)
    {
      #pragma omp metadirective \
	when (target_device={device_num(d), kind("host")} : nothing)	\
	otherwise (error at(execution) message("check_explicit_device host"))
      ok = 1;
    }
  else
    {
      #pragma omp metadirective \
	when (target_device={device_num(d), kind("nohost")} : nothing)	\
	otherwise (error at(execution) message("check_explicit_device nohost"))
      ok = 1;
    }

  return ok;
}

static int
check_implicit_device (int d, int expect_host)
{
  int ok = 0;
  omp_set_default_device (d);

  if (expect_host)
    {
      #pragma omp metadirective \
	when (target_device={kind("host")} : nothing)	\
	otherwise (error at(execution) message("check_implicit_device host"))
      ok = 1;
    }
  else
    {
      #pragma omp metadirective \
	when (target_device={kind("nohost")} : nothing)	\
	otherwise (error at(execution) message("check_implicit_device nohost"))
      ok = 1;
    }
  #pragma omp metadirective						\
    when (target_device={kind("any")} : nothing)	\
    otherwise (error at(execution) message("check_implicit_device any"))
  ok = 1;
  omp_set_default_device (omp_initial_device);

  return ok;
}

int
main (void)
{
  printf ("Checking omp_initial_device\n");
  check_explicit_device (omp_initial_device, 1);
  check_implicit_device (omp_initial_device, 1);
  int n = omp_get_num_devices ();
  printf ("There are %d devices\n", n);
  for (int i = 0; i < n; i++)
    {
      printf ("Checking device %d\n", i);
      check_explicit_device (i, 0);
      check_implicit_device (i, 0);
    }
  return 0;
}