Debian Codegraph @

gcc/testsuite/c-c++-common/goacc/kernels-parallel-loop-data-enter-exit.c

raw
1 /* { dg-additional-options "-O2" } */
2 /* { dg-additional-options "-fdump-tree-parloops1-all" } */
3 /* { dg-additional-options "-fdump-tree-optimized" } */
4 /* { dg-skip-if "requires hosted libstdc++ for stdlib malloc" { ! hostedlib } } */
5
6 #include <stdlib.h>
7
8 #define N (1024 * 512)
9 #define COUNTERTYPE unsigned int
10
11 int
12 main (void)
13 {
14 unsigned int *__restrict a;
15 unsigned int *__restrict b;
16 unsigned int *__restrict c;
17
18 a = (unsigned int *)malloc (N * sizeof (unsigned int));
19 b = (unsigned int *)malloc (N * sizeof (unsigned int));
20 c = (unsigned int *)malloc (N * sizeof (unsigned int));
21
22 #pragma acc enter data create (a[0:N], b[0:N], c[0:N])
23
24 #pragma acc kernels present (a[0:N])
25 {
26 for (COUNTERTYPE i = 0; i < N; i++)
27 a[i] = i * 2;
28 }
29
30 #pragma acc parallel present (b[0:N])
31 {
32 #pragma acc loop
33 for (COUNTERTYPE i = 0; i < N; i++)
34 b[i] = i * 4;
35 }
36
37 #pragma acc kernels present (a[0:N], b[0:N], c[0:N])
38 {
39 for (COUNTERTYPE ii = 0; ii < N; ii++)
40 c[ii] = a[ii] + b[ii];
41 }
42
43 #pragma acc exit data copyout (a[0:N], b[0:N], c[0:N])
44
45 for (COUNTERTYPE i = 0; i < N; i++)
46 if (c[i] != a[i] + b[i])
47 abort ();
48
49 free (a);
50 free (b);
51 free (c);
52
53 return 0;
54 }
55
56 /* Check that only two loops are analyzed, and that both can be
57 parallelized. */
58 // FIXME: OpenACC kernels stopped working with the firstprivate subarray
59 // changes.
60 /* { dg-final { scan-tree-dump-times "SUCCESS: may be parallelized" 2 "parloops1" { xfail *-*-* } } } */
61 /* { dg-final { scan-tree-dump-times "(?n)__attribute__\\(\\(oacc kernels parallelized, oacc function \\(, , \\), oacc kernels, omp target entrypoint, noclone\\)\\)" 2 "parloops1" { xfail *-*-* } } } */
62 /* { dg-final { scan-tree-dump-not "FAILED:" "parloops1" { xfail *-*-* } } } */
63
64 /* Check that the loop has been split off into a function. */
65 /* { dg-final { scan-tree-dump-times "(?n);; Function .*main._omp_fn.0" 1 "optimized" } } */
66 /* { dg-final { scan-tree-dump-times "(?n);; Function .*main._omp_fn.1" 1 "optimized" } } */
67 /* { dg-final { scan-tree-dump-times "(?n);; Function .*main._omp_fn.2" 1 "optimized" } } */