Debian Codegraph @

libgomp/testsuite/libgomp.c-c++-common/map-arrayofstruct-3.c

raw
1 #include <stdlib.h>
2 #include <assert.h>
3
4 struct st {
5 int *p;
6 };
7
8 struct tt {
9 struct st a[10];
10 };
11
12 struct ut {
13 struct tt *t;
14 };
15
16 int main (void)
17 {
18 struct tt *t = (struct tt *) malloc (sizeof *t);
19 struct ut *u = (struct ut *) malloc (sizeof *u);
20
21 for (int i = 0; i < 10; i++)
22 t->a[i].p = (int *) calloc (5, sizeof (int));
23
24 u->t = t;
25
26 for (int i = 0; i < 10; i++)
27 for (int j = 0; j < 10; j++)
28 for (int k = 0; k < 10; k++)
29 {
30 if (i == j || j == k || i == k)
31 continue;
32
33 /* This one can use "firstprivate" for T... */
34 #pragma omp target map(t->a[i].p, t->a[j].p, t->a[k].p, \
35 t->a[i].p[0:2], t->a[j].p[1:3], t->a[k].p[2])
36 {
37 t->a[i].p[0]++;
38 t->a[j].p[1]++;
39 t->a[k].p[2]++;
40 }
41
42 /* ...but this one must use attach/detach for T. */
43 #pragma omp target map(u->t, u->t->a[i].p, u->t->a[j].p, u->t->a[k].p, \
44 u->t->a[i].p[0:2], u->t->a[j].p[1:3], u->t->a[k].p[2])
45 {
46 u->t->a[i].p[0]++;
47 u->t->a[j].p[1]++;
48 u->t->a[k].p[2]++;
49 }
50 }
51
52 for (int i = 0; i < 10; i++)
53 {
54 assert (t->a[i].p[0] == 144);
55 assert (t->a[i].p[1] == 144);
56 assert (t->a[i].p[2] == 144);
57 free (t->a[i].p);
58 }
59
60 free (u);
61 free (t);
62
63 return 0;
64 }
65
66 /* { dg-output "(\n|\r|\r\n)" { target offload_device_nonshared_as } } */
67 /* { dg-output "libgomp: Mapped array elements must be the same .*(\n|\r|\r\n)+" { target offload_device_nonshared_as } } */
68 /* { dg-shouldfail "" { offload_device_nonshared_as } } */