Debian Codegraph @

libgomp/testsuite/libgomp.oacc-c++/ref-1.C

raw
1 /* { dg-do run } */
2
3 #include <stdio.h>
4
5 #pragma acc routine vector
6 void __attribute__((noinline, noclone))
7 Vector (int *ptr, int n, const int &inc)
8 {
9 #pragma acc loop vector
10 for (unsigned ix = 0; ix < n; ix++)
11 ptr[ix] += inc;
12 }
13
14 #pragma acc routine worker
15 void __attribute__((noinline, noclone))
16 Worker (int *ptr, int m, int n, const int &inc)
17 {
18 #pragma acc loop worker
19 for (unsigned ix = 0; ix < m; ix++)
20 Vector(ptr + ix * n, n, inc);
21 }
22
23 int
24 main (void)
25 {
26 const int n = 32, m = 32;
27
28 int ary[m][n];
29 unsigned ix, iy;
30
31 for (ix = m; ix--;)
32 for (iy = n; iy--;)
33 ary[ix][iy] = (ix << 8) + iy;
34
35 #pragma acc parallel copy(ary)
36 {
37 Worker (&ary[0][0], m, n, 1 << 16);
38 }
39
40 int err = 0;
41
42 for (ix = m; ix--;)
43 for (iy = n; iy--;)
44 if (ary[ix][iy] != ((1 << 16) + (ix << 8) + iy))
45 {
46 printf ("ary[%u][%u] = %x expected %x\n",
47 ix, iy, ary[ix][iy], ((1 << 16) + (ix << 8) + iy));
48 err++;
49 }
50
51 if (err)
52 {
53 printf ("%d failed\n", err);
54 return 1;
55 }
56
57 #pragma acc parallel copy(ary)
58 {
59 Vector (&ary[0][0], m * n, (1 << 24) - (1 << 16));
60 }
61
62 for (ix = m; ix--;)
63 for (iy = n; iy--;)
64 if (ary[ix][iy] != ((1 << 24) + (ix << 8) + iy))
65 {
66 printf ("ary[%u][%u] = %x expected %x\n",
67 ix, iy, ary[ix][iy], ((1 << 24) + (ix << 8) + iy));
68 err++;
69 }
70
71 if (err)
72 {
73 printf ("%d failed\n", err);
74 return 1;
75 }
76
77 return 0;
78 }