123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- ! { dg-do run }
- ! real reductions
- program reduction_2
- implicit none
- integer, parameter :: n = 10, vl = 2
- integer :: i
- real, parameter :: e = .001
- real :: vresult, result
- logical :: lresult, lvresult
- real, dimension (n) :: array
- do i = 1, n
- array(i) = i
- end do
- result = 0
- vresult = 0
- ! '+' reductions
- !$acc parallel vector_length(vl) num_gangs(1)
- !$acc loop reduction(+:result)
- do i = 1, n
- result = result + array(i)
- end do
- !$acc end parallel
- ! Verify the results
- do i = 1, n
- vresult = vresult + array(i)
- end do
- if (abs (result - vresult) .ge. e) call abort
- result = 1
- vresult = 1
- ! '*' reductions
- !$acc parallel vector_length(vl) num_gangs(1)
- !$acc loop reduction(*:result)
- do i = 1, n
- result = result * array(i)
- end do
- !$acc end parallel
- ! Verify the results
- do i = 1, n
- vresult = vresult * array(i)
- end do
- if (result.ne.vresult) call abort
- result = 0
- vresult = 0
- ! 'max' reductions
- !$acc parallel vector_length(vl) num_gangs(1)
- !$acc loop reduction(max:result)
- do i = 1, n
- result = max (result, array(i))
- end do
- !$acc end parallel
- ! Verify the results
- do i = 1, n
- vresult = max (vresult, array(i))
- end do
- if (result.ne.vresult) call abort
- result = 1
- vresult = 1
- ! 'min' reductions
- !$acc parallel vector_length(vl) num_gangs(1)
- !$acc loop reduction(min:result)
- do i = 1, n
- result = min (result, array(i))
- end do
- !$acc end parallel
- ! Verify the results
- do i = 1, n
- vresult = min (vresult, array(i))
- end do
- if (result.ne.vresult) call abort
- result = 1
- vresult = 1
- ! '.and.' reductions
- !$acc parallel vector_length(vl) num_gangs(1)
- !$acc loop reduction(.and.:lresult)
- do i = 1, n
- lresult = lresult .and. (array(i) .ge. 5)
- end do
- !$acc end parallel
- ! Verify the results
- do i = 1, n
- lvresult = lvresult .and. (array(i) .ge. 5)
- end do
- if (result.ne.vresult) call abort
- lresult = .false.
- lvresult = .false.
- ! '.or.' reductions
- !$acc parallel vector_length(vl) num_gangs(1)
- !$acc loop reduction(.or.:lresult)
- do i = 1, n
- lresult = lresult .or. (array(i) .ge. 5)
- end do
- !$acc end parallel
- ! Verify the results
- do i = 1, n
- lvresult = lvresult .or. (array(i) .ge. 5)
- end do
- if (result.ne.vresult) call abort
- lresult = .false.
- lvresult = .false.
- ! '.eqv.' reductions
- !$acc parallel vector_length(vl) num_gangs(1)
- !$acc loop reduction(.eqv.:lresult)
- do i = 1, n
- lresult = lresult .eqv. (array(i) .ge. 5)
- end do
- !$acc end parallel
- ! Verify the results
- do i = 1, n
- lvresult = lvresult .eqv. (array(i) .ge. 5)
- end do
- if (result.ne.vresult) call abort
- lresult = .false.
- lvresult = .false.
- ! '.neqv.' reductions
- !$acc parallel vector_length(vl) num_gangs(1)
- !$acc loop reduction(.neqv.:lresult)
- do i = 1, n
- lresult = lresult .neqv. (array(i) .ge. 5)
- end do
- !$acc end parallel
- ! Verify the results
- do i = 1, n
- lvresult = lvresult .neqv. (array(i) .ge. 5)
- end do
- if (result.ne.vresult) call abort
- end program reduction_2
|