gcc/libgomp/testsuite/libgomp.oacc-fortran/reduction-7.f90
Chung-Lin Tang 2c71d454eb re PR middle-end/70895 (OpenACC: loop reduction does not work. Output is zero.)
2016-08-18  Chung-Lin Tang  <cltang@codesourcery.com>

	PR middle-end/70895
	gcc/
	* gimplify.c (omp_add_variable): Adjust/add variable mapping on
	enclosing parallel construct for reduction variables on OpenACC loop
	directives.

	gcc/testsuite/
	* gfortran.dg/goacc/loop-tree-1.f90: Add gimple scan-tree-dump test.
	* c-c++-common/goacc/reduction-1.c: Likewise.
	* c-c++-common/goacc/reduction-2.c: Likewise.
	* c-c++-common/goacc/reduction-3.c: Likewise.
	* c-c++-common/goacc/reduction-4.c: Likewise.

	libgomp/
	* testsuite/libgomp.oacc-fortran/reduction-7.f90: Add explicit
	firstprivate clauses.
	* testsuite/libgomp.oacc-fortran/reduction-6.f90: Remove explicit
	copy clauses.
	* testsuite/libgomp.oacc-c-c++-common/reduction-7.c: Likewise.
	* testsuite/libgomp.oacc-c-c++-common/reduction-cplx-flt.c: Likewise.
	* testsuite/libgomp.oacc-c-c++-common/reduction-flt.c: Likewise.
	* testsuite/libgomp.oacc-c-c++-common/collapse-2.c: Likewise.
	* testsuite/libgomp.oacc-c-c++-common/loop-red-wv-1.c: Likewise.
	* testsuite/libgomp.oacc-c-c++-common/collapse-4.c: Likewise.
	* testsuite/libgomp.oacc-c-c++-common/loop-red-v-1.c: Likewise.
	* testsuite/libgomp.oacc-c-c++-common/reduction-cplx-dbl.c: Likewise.
	* testsuite/libgomp.oacc-c-c++-common/loop-red-g-1.c: Likewise.
	* testsuite/libgomp.oacc-c-c++-common/loop-red-gwv-1.c: Likewise.
	* testsuite/libgomp.oacc-c-c++-common/loop-red-w-1.c: Likewise.
	* testsuite/libgomp.oacc-c-c++-common/reduction-dbl.c: Likewise.

From-SVN: r239576
2016-08-18 14:46:19 +00:00

89 lines
1.8 KiB
Fortran

! { dg-do run }
! { dg-additional-options "-w" }
! subroutine reduction with private and firstprivate variables
program reduction
integer, parameter :: n = 100
integer :: i, j, vsum, cs, arr(n)
call redsub_private (cs, n, arr)
call redsub_bogus (cs, n)
call redsub_combined (cs, n, arr)
vsum = 0
! Verify the results
do i = 1, n
vsum = i
do j = 1, n
vsum = vsum + 1;
end do
if (vsum .ne. arr(i)) call abort ()
end do
end program reduction
! This subroutine tests a reduction with an explicit private variable.
subroutine redsub_private(sum, n, arr)
integer :: sum, n, arr(n)
integer :: i, j, v
!$acc parallel copyout (arr)
!$acc loop gang private (v)
do j = 1, n
v = j
!$acc loop vector reduction (+:v)
do i = 1, 100
v = v + 1
end do
arr(j) = v
end do
!$acc end parallel
! verify the results
do i = 1, 10
if (arr(i) .ne. 100+i) call abort ()
end do
end subroutine redsub_private
! Bogus reduction on a firstprivate variable. The results do
! survive the parallel region. The goal here is to ensure that gfortran
! doesn't ICE.
subroutine redsub_bogus(sum, n)
integer :: sum, n, arr(n)
integer :: i
!$acc parallel firstprivate(sum)
!$acc loop gang worker vector reduction (+:sum)
do i = 1, n
sum = sum + 1
end do
!$acc end parallel
end subroutine redsub_bogus
! This reduction involving a firstprivate variable yields legitimate results.
subroutine redsub_combined(sum, n, arr)
integer :: sum, n, arr(n)
integer :: i, j
!$acc parallel copy (arr) firstprivate(sum)
!$acc loop gang
do i = 1, n
sum = i;
!$acc loop reduction(+:sum)
do j = 1, n
sum = sum + 1
end do
arr(i) = sum
end do
!$acc end parallel
end subroutine redsub_combined