(root)/
gcc-13.2.0/
libgomp/
testsuite/
libgomp.c-c++-common/
get-mapped-ptr-2.c
       1  #include <omp.h>
       2  #include <stdlib.h>
       3  #include <stdint.h>
       4  
       5  int
       6  main ()
       7  {
       8    int d = omp_get_default_device ();
       9    int id = omp_get_initial_device ();
      10    int a = 42;
      11    int b[] = { 24, 42 };
      12    int c[] = { 47, 11 };
      13    int e[128];
      14    int *q = &a;
      15    void *p1 = NULL, *p2 = NULL, *p3 = NULL;
      16    void *devptrs[128];
      17  
      18    if (d < 0 || d >= omp_get_num_devices ())
      19      d = id;
      20  
      21    for (int i = 0; i < 128; i++)
      22      e[i] = i;
      23  
      24    #pragma omp target data map(alloc: a, b, c[1], e[32:64]) device(d)
      25    {
      26      #pragma omp target map(from: p1, p2, p3, devptrs) map(alloc: a, b, c[1], e[32:64]) device(d)
      27      {
      28        p1 = &a;
      29        p2 = &b;
      30        p3 = &c[1];
      31        for (int i = 32; i < 96; i++)
      32  	devptrs[i] = &e[i];
      33      }
      34  
      35      if (omp_get_mapped_ptr (&a, d) != (d == id ? &a : p1)
      36  	|| omp_get_mapped_ptr (q, d) != (d == id ? q : p1)
      37  	|| omp_get_mapped_ptr (b, d) != (d == id ? b : p2)
      38  	|| omp_get_mapped_ptr (&b[0], d) != (d == id ? &b[0] : p2)
      39  	|| omp_get_mapped_ptr (&c[1], d) != (d == id ? &c[1] : p3)
      40  	|| omp_get_mapped_ptr (&c[0], d) != (d == id ? &c[0] : NULL))
      41        abort ();
      42  
      43      for (int i = 0; i < 32; i++)
      44        if (omp_get_mapped_ptr (&e[i], d) != (d == id ? &e[i] : NULL))
      45  	abort ();
      46      for (int i = 32; i < 96; i++)
      47        if (omp_get_mapped_ptr (&e[i], d) != (d == id ? &e[i] : devptrs[i]))
      48  	abort ();
      49      for (int i = 96; i < 128; i++)
      50        if (omp_get_mapped_ptr (&e[i], d) != (d == id ? &e[i] : NULL))
      51  	abort ();
      52    }
      53  
      54    if (omp_get_mapped_ptr (&a, d) != (d == id ? &a : NULL)
      55        || omp_get_mapped_ptr (q, d) != (d == id ? q : NULL)
      56        || omp_get_mapped_ptr (b, d) != (d == id ? b : NULL)
      57        || omp_get_mapped_ptr (&b[0], d) != (d == id ? &b[0] : NULL)
      58        || omp_get_mapped_ptr (&c[1], d) != (d == id ? &c[1] : NULL)
      59        || omp_get_mapped_ptr (&c[0], d) != (d == id ? &c[0] : NULL))
      60      abort ();
      61    for (int i = 0; i < 128; i++)
      62      if (omp_get_mapped_ptr (&e[i], d) != (d == id ? &e[i] : NULL))
      63        abort ();
      64  
      65    #pragma omp target enter data map (alloc: a, b, c[1], e[32:64]) device (d)
      66    #pragma omp target map(from: p1, p2, p3, devptrs) map(alloc: a, b, c[1], e[32:64]) device(d)
      67    {
      68      p1 = &a;
      69      p2 = &b;
      70      p3 = &c[1];
      71      for (int i = 32; i < 96; i++)
      72        devptrs[i] = &e[i];
      73    }
      74  
      75    if (omp_get_mapped_ptr (&a, d) != (d == id ? &a : p1)
      76        || omp_get_mapped_ptr (q, d) != (d == id ? q : p1)
      77        || omp_get_mapped_ptr (b, d) != (d == id ? b : p2)
      78        || omp_get_mapped_ptr (&b[0], d) != (d == id ? &b[0] : p2)
      79        || omp_get_mapped_ptr (&c[1], d) != (d == id ? &c[1] : p3)
      80        || omp_get_mapped_ptr (&c[0], d) != (d == id ? &c[0] : NULL))
      81      abort ();
      82    for (int i = 0; i < 32; i++)
      83      if (omp_get_mapped_ptr (&e[i], d) != (d == id ? &e[i] : NULL))
      84        abort ();
      85    for (int i = 32; i < 96; i++)
      86      if (omp_get_mapped_ptr (&e[i], d) != (d == id ? &e[i] : devptrs[i]))
      87        abort ();
      88    for (int i = 96; i < 128; i++)
      89      if (omp_get_mapped_ptr (&e[i], d) != (d == id ? &e[i] : NULL))
      90        abort ();
      91  
      92    #pragma omp target exit data map (delete: a, b, c[1], e[32:64]) device (d)
      93  
      94    if (omp_get_mapped_ptr (&a, d) != (d == id ? &a : NULL)
      95        || omp_get_mapped_ptr (q, d) != (d == id ? q : NULL)
      96        || omp_get_mapped_ptr (b, d) != (d == id ? b : NULL)
      97        || omp_get_mapped_ptr (&b[0], d) != (d == id ? &b[0] : NULL)
      98        || omp_get_mapped_ptr (&c[1], d) != (d == id ? &c[1] : NULL)
      99        || omp_get_mapped_ptr (&c[0], d) != (d == id ? &c[0] : NULL))
     100      abort ();
     101    for (int i = 0; i < 128; i++)
     102      if (omp_get_mapped_ptr (&e[i], d) != (d == id ? &e[i] : NULL))
     103        abort ();
     104  
     105    return 0;
     106  }