| 1 |
! { dg-do run } |
| 2 |
|
| 3 |
! { dg-additional-options -Wuninitialized } |
| 4 |
|
| 5 |
!TODO |
| 6 |
! { dg-xfail-run-if TODO { openacc_radeon_accel_selected && { ! __OPTIMIZE__ } } } |
| 7 |
|
| 8 |
! subroutine reduction with private and firstprivate variables |
| 9 |
|
| 10 |
program reduction |
| 11 |
integer, parameter :: n = 100 |
| 12 |
integer :: i, j, vsum, cs, arr(n) |
| 13 |
|
| 14 |
call redsub_private (cs, n, arr) |
| 15 |
call redsub_bogus (cs, n) |
| 16 |
call redsub_combined (cs, n, arr) |
| 17 |
|
| 18 |
vsum = 0 |
| 19 |
|
| 20 |
! Verify the results |
| 21 |
do i = 1, n |
| 22 |
vsum = i |
| 23 |
do j = 1, n |
| 24 |
vsum = vsum + 1; |
| 25 |
end do |
| 26 |
if (vsum .ne. arr(i)) STOP 1 |
| 27 |
end do |
| 28 |
end program reduction |
| 29 |
|
| 30 |
! This subroutine tests a reduction with an explicit private variable. |
| 31 |
|
| 32 |
subroutine redsub_private(sum, n, arr) |
| 33 |
integer :: sum, n, arr(n) |
| 34 |
integer :: i, j, v |
| 35 |
|
| 36 |
!$acc parallel copyout (arr) |
| 37 |
!$acc loop gang private (v) |
| 38 |
do j = 1, n |
| 39 |
v = j |
| 40 |
|
| 41 |
!$acc loop vector reduction (+:v) |
| 42 |
do i = 1, 100 |
| 43 |
v = v + 1 |
| 44 |
end do |
| 45 |
|
| 46 |
arr(j) = v |
| 47 |
end do |
| 48 |
!$acc end parallel |
| 49 |
|
| 50 |
! verify the results |
| 51 |
do i = 1, 10 |
| 52 |
if (arr(i) .ne. 100+i) STOP 2 |
| 53 |
end do |
| 54 |
end subroutine redsub_private |
| 55 |
|
| 56 |
|
| 57 |
! Bogus reduction on a firstprivate variable. The results do |
| 58 |
! survive the parallel region. The goal here is to ensure that gfortran |
| 59 |
! doesn't ICE. |
| 60 |
|
| 61 |
subroutine redsub_bogus(sum, n) |
| 62 |
integer :: sum, n, arr(n) |
| 63 |
integer :: i |
| 64 |
|
| 65 |
!$acc parallel firstprivate(sum) |
| 66 |
!$acc loop gang worker vector reduction (+:sum) |
| 67 |
! { dg-bogus {'sum\.[0-9]+' is used uninitialized} TODO { xfail *-*-* } .-1 } |
| 68 |
! { dg-note {'sum\.[0-9]+' was declared here} {} { target *-*-* } .-2 } |
| 69 |
do i = 1, n |
| 70 |
sum = sum + 1 |
| 71 |
end do |
| 72 |
!$acc end parallel |
| 73 |
end subroutine redsub_bogus |
| 74 |
|
| 75 |
! This reduction involving a firstprivate variable yields legitimate results. |
| 76 |
|
| 77 |
subroutine redsub_combined(sum, n, arr) |
| 78 |
integer :: sum, n, arr(n) |
| 79 |
integer :: i, j |
| 80 |
|
| 81 |
!$acc parallel copy (arr) firstprivate(sum) |
| 82 |
!$acc loop gang |
| 83 |
do i = 1, n |
| 84 |
sum = i; |
| 85 |
|
| 86 |
!$acc loop reduction(+:sum) |
| 87 |
! { dg-bogus {'sum\.[0-9]+' may be used uninitialized} TODO { xfail { ! __OPTIMIZE__ } } .-1 } |
| 88 |
! { dg-note {'sum\.[0-9]+' was declared here} {} { target { ! __OPTIMIZE__ } } .-2 } |
| 89 |
do j = 1, n |
| 90 |
sum = sum + 1 |
| 91 |
end do |
| 92 |
|
| 93 |
arr(i) = sum |
| 94 |
end do |
| 95 |
!$acc end parallel |
| 96 |
end subroutine redsub_combined |