aboutsummaryrefslogtreecommitdiff
path: root/libgomp/testsuite/libgomp.c-c++-common/get-mapped-ptr-1.c
blob: 4708ae86bfe45bf58c06677a1dd6c7383a3bd86f (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
#include <omp.h>
#include <stdlib.h>

int
main ()
{
  int d = omp_get_default_device ();
  int id = omp_get_initial_device ();
  int x;
  void *p, *q;

  q = (void *) &x;

  if (d < 0 || d >= omp_get_num_devices ())
    d = id;

  p = omp_target_alloc (sizeof (int), d);
  if (p == NULL)
    return 0;

  if (omp_target_associate_ptr (q, p, sizeof (int), 0, d) != 0)
    return 0;

  if (omp_get_mapped_ptr (q, -5) != NULL)
    abort ();

  if (omp_get_mapped_ptr (q, omp_get_num_devices () + 1) != NULL)
    abort ();

  if (omp_get_mapped_ptr (q, id) != q)
    abort ();

  if (omp_get_mapped_ptr (q, omp_initial_device) != q)
    abort ();

  if (omp_get_mapped_ptr (q, d) != p)
    abort ();

  if (omp_target_disassociate_ptr (q, d) != 0)
    abort ();

  if (omp_get_mapped_ptr (q, d) != NULL)
    abort ();

  omp_target_free (p, d);
  return 0;
}