aboutsummaryrefslogtreecommitdiff
path: root/libgomp/testsuite/libgomp.c-c++-common/map-arrayofstruct-1.c
blob: 655f6ef41585c45a98674e5cf75ed513cd473498 (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
#include <stdlib.h>
#include <assert.h>

struct st {
  int *p;
};

int main (void)
{
  struct st s[2];
  s[0].p = (int *) calloc (5, sizeof (int));
  s[1].p = (int *) calloc (5, sizeof (int));

  /* These mappings not supported by the OpenMP spec, and are currently
     implemented as an extension by GCC for legacy compatibility only.  See
     e.g. OpenMP 5.2, "5.8.3 map Clause":

    "If multiple list items are explicitly mapped on the same construct and
     have the same containing array or have base pointers that share original
     storage, and if any of the list items do not have corresponding list
     items that are present in the device data environment prior to a task
     encountering the construct, then the list items must refer to the same
     array elements of either the containing array or the implicit array of
     the base pointers."
  */

#pragma omp target map(s[0].p, s[1].p, s[0].p[0:2], s[1].p[1:3])
  {
    s[0].p[0] = 5;
    s[1].p[1] = 7;
  }

#pragma omp target map(s, s[0].p[0:2], s[1].p[1:3])
  {
    s[0].p[0]++;
    s[1].p[1]++;
  }

#pragma omp target map(s[0:2], s[0].p[0:2], s[1].p[1:3])
  {
    s[0].p[0]++;
    s[1].p[1]++;
  }

  assert (s[0].p[0] == 7);
  assert (s[1].p[1] == 9);

  free (s[0].p);
  free (s[1].p);
  return 0;
}