aboutsummaryrefslogtreecommitdiff
path: root/libgomp/testsuite/libgomp.c++/declare-mapper-7.C
blob: ba4792ace1816d10f11be1877ba36370965ceb32 (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
// { dg-do run }

#include <cassert>

struct S
{
  int *myarr;
};

struct T
{
  S *s;
};

#pragma omp declare mapper (s100: S x) map(to: x.myarr) \
				       map(tofrom: x.myarr[0:100])
// Define this because ...
#pragma omp declare mapper (default: S x) map(to: x.myarr) \
					  map(tofrom: x.myarr[0:100])


void
bump (T t)
{
  /* Here we have an implicit/default mapper invoking a named mapper.  We
     need to make sure that can be located properly at gimplification
     time.  */

// ... the following is invalid in OpenMP - albeit supported by GCC
// (after disabling:  error: in ‘declare mapper’ directives, parameter to ‘mapper’ modifier must be ‘default’ )

// #pragma omp declare mapper (T t) map(to:t.s) map(mapper(s100), tofrom: t.s[0])

// ... thus, we now use ...
#pragma omp declare mapper (T t) map(to:t.s) map(mapper(default), tofrom: t.s[0])

#pragma omp target
  for (int i = 0; i < 100; i++)
    t.s->myarr[i]++;
}

int main (int argc, char *argv[])
{
  S my_s;
  T my_t;

  my_s.myarr = new int[100];
  my_t.s = &my_s;

  for (int i = 0; i < 100; i++)
    my_s.myarr[i] = 0;

  bump (my_t);

  for (int i = 0; i < 100; i++)
    assert (my_s.myarr[i] == 1);

  return 0;
}