Debian Codegraph @

gcc/testsuite/c-c++-common/goacc/kernels-counter-vars-function-scope.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 COUNTERTYPE i;
18 COUNTERTYPE ii;
19
20 a = (unsigned int *)malloc (N * sizeof (unsigned int));
21 b = (unsigned int *)malloc (N * sizeof (unsigned int));
22 c = (unsigned int *)malloc (N * sizeof (unsigned int));
23
24 for (i = 0; i < N; i++)
25 a[i] = i * 2;
26
27 for (i = 0; i < N; i++)
28 b[i] = i * 4;
29
30 #pragma acc kernels copyin (a[0:N], b[0:N]) copyout (c[0:N])
31 {
32 for (ii = 0; ii < N; ii++)
33 c[ii] = a[ii] + b[ii];
34 }
35
36 for (i = 0; i < N; i++)
37 if (c[i] != a[i] + b[i])
38 abort ();
39
40 free (a);
41 free (b);
42 free (c);
43
44 return 0;
45 }
46
47 /* Check that only one loop is analyzed, and that it can be parallelized. */
48 /* { dg-final { scan-tree-dump-times "SUCCESS: may be parallelized" 1 "parloops1" } } */
49 /* { dg-final { scan-tree-dump-times "(?n)__attribute__\\(\\(oacc kernels parallelized, oacc function \\(, , \\), oacc kernels, omp target entrypoint, noclone\\)\\)" 1 "parloops1" } } */
50 /* { dg-final { scan-tree-dump-not "FAILED:" "parloops1" } } */
51
52 /* Check that the loop has been split off into a function. */
53 /* { dg-final { scan-tree-dump-times "(?n);; Function .*main._omp_fn.0" 1 "optimized" } } */