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