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 enter data create (a[0:N])
22 #pragma acc kernels present (a[0:N])
23   {
24     for (COUNTERTYPE i = 0; i < N; i++)
25       a[i] = i * 2;
26   }
27 #pragma acc exit data copyout (a[0:N])
28 
29 #pragma acc enter data create (b[0:N])
30 #pragma acc kernels present (b[0:N])
31   {
32     for (COUNTERTYPE i = 0; i < N; i++)
33       b[i] = i * 4;
34   }
35 #pragma acc exit data copyout (b[0:N])
36 
37 
38 #pragma acc enter data copyin (a[0:N], b[0:N]) create (c[0:N])
39 #pragma acc kernels present (a[0:N], b[0:N], c[0:N])
40   {
41     for (COUNTERTYPE ii = 0; ii < N; ii++)
42       c[ii] = a[ii] + b[ii];
43   }
44 #pragma acc exit data copyout (c[0:N])
45 
46   for (COUNTERTYPE i = 0; i < N; i++)
47     if (c[i] != a[i] + b[i])
48       abort ();
49 
50   free (a);
51   free (b);
52   free (c);
53 
54   return 0;
55 }
56 
57 /* Check that only three loops are analyzed, and that all can be
58    parallelized.  */
59 /* { dg-final { scan-tree-dump-times "SUCCESS: may be parallelized" 3 "parloops1" } } */
60 /* { dg-final { scan-tree-dump-times "(?n)__attribute__\\(\\(oacc kernels parallelized, oacc function \\(, , \\), oacc kernels, omp target entrypoint\\)\\)" 3 "parloops1" } } */
61 /* { dg-final { scan-tree-dump-not "FAILED:" "parloops1" } } */
62 
63 /* Check that the loop has been split off into a function.  */
64 /* { dg-final { scan-tree-dump-times "(?n);; Function .*main._omp_fn.0" 1 "optimized" } } */
65 /* { dg-final { scan-tree-dump-times "(?n);; Function .*main._omp_fn.1" 1 "optimized" } } */
66 /* { dg-final { scan-tree-dump-times "(?n);; Function .*main._omp_fn.2" 1 "optimized" } } */
67