Retro68/gcc/libgomp/testsuite/libgomp.oacc-fortran/declare-1.f90

233 lines
3.8 KiB
Fortran
Raw Normal View History

2018-12-28 15:30:48 +00:00
! { dg-do run }
! { dg-skip-if "" { *-*-* } { "-DACC_MEM_SHARED=1" } }
2017-04-10 11:32:00 +00:00
! Tests to exercise the declare directive along with
! the clauses: copy
! copyin
! copyout
! create
! present
! present_or_copy
! present_or_copyin
! present_or_copyout
! present_or_create
module vars
implicit none
integer z
!$acc declare create (z)
end module vars
subroutine subr5 (a, b, c, d)
implicit none
integer, parameter :: N = 8
integer :: i
integer :: a(N)
!$acc declare present_or_copyin (a)
integer :: b(N)
!$acc declare present_or_create (b)
integer :: c(N)
!$acc declare present_or_copyout (c)
integer :: d(N)
!$acc declare present_or_copy (d)
i = 0
!$acc parallel
do i = 1, N
b(i) = a(i)
c(i) = b(i)
d(i) = d(i) + b(i)
end do
!$acc end parallel
end subroutine
subroutine subr4 (a, b)
implicit none
integer, parameter :: N = 8
integer :: i
integer :: a(N)
!$acc declare present (a)
integer :: b(N)
!$acc declare copyout (b)
i = 0
!$acc parallel
do i = 1, N
b(i) = a(i)
end do
!$acc end parallel
end subroutine
subroutine subr3 (a, c)
implicit none
integer, parameter :: N = 8
integer :: i
integer :: a(N)
!$acc declare present (a)
integer :: c(N)
!$acc declare copyin (c)
i = 0
!$acc parallel
do i = 1, N
a(i) = c(i)
c(i) = 0
end do
!$acc end parallel
end subroutine
subroutine subr2 (a, b, c)
implicit none
integer, parameter :: N = 8
integer :: i
integer :: a(N)
!$acc declare present (a)
integer :: b(N)
!$acc declare create (b)
integer :: c(N)
!$acc declare copy (c)
i = 0
!$acc parallel
do i = 1, N
b(i) = a(i)
c(i) = b(i) + c(i) + 1
end do
!$acc end parallel
end subroutine
subroutine subr1 (a)
implicit none
integer, parameter :: N = 8
integer :: i
integer :: a(N)
!$acc declare present (a)
i = 0
!$acc parallel
do i = 1, N
a(i) = a(i) + 1
end do
!$acc end parallel
end subroutine
subroutine test (a, e)
use openacc
implicit none
logical :: e
integer, parameter :: N = 8
integer :: a(N)
2018-12-28 15:30:48 +00:00
if (acc_is_present (a) .neqv. e) STOP 1
2017-04-10 11:32:00 +00:00
end subroutine
subroutine subr0 (a, b, c, d)
implicit none
integer, parameter :: N = 8
integer :: a(N)
!$acc declare copy (a)
integer :: b(N)
integer :: c(N)
integer :: d(N)
integer :: i
call test (a, .true.)
call test (b, .false.)
call test (c, .false.)
call subr1 (a)
call test (a, .true.)
call test (b, .false.)
call test (c, .false.)
call subr2 (a, b, c)
call test (a, .true.)
call test (b, .false.)
call test (c, .false.)
do i = 1, N
2018-12-28 15:30:48 +00:00
if (c(i) .ne. 8) STOP 2
2017-04-10 11:32:00 +00:00
end do
call subr3 (a, c)
call test (a, .true.)
call test (b, .false.)
call test (c, .false.)
do i = 1, N
2018-12-28 15:30:48 +00:00
if (a(i) .ne. 2) STOP 3
if (c(i) .ne. 8) STOP 4
2017-04-10 11:32:00 +00:00
end do
call subr4 (a, b)
call test (a, .true.)
call test (b, .false.)
call test (c, .false.)
do i = 1, N
2018-12-28 15:30:48 +00:00
if (b(i) .ne. 8) STOP 5
2017-04-10 11:32:00 +00:00
end do
call subr5 (a, b, c, d)
call test (a, .true.)
call test (b, .false.)
call test (c, .false.)
call test (d, .false.)
do i = 1, N
2018-12-28 15:30:48 +00:00
if (c(i) .ne. 8) STOP 6
if (d(i) .ne. 13) STOP 7
2017-04-10 11:32:00 +00:00
end do
end subroutine
program main
use vars
use openacc
implicit none
integer, parameter :: N = 8
integer :: a(N)
integer :: b(N)
integer :: c(N)
integer :: d(N)
integer :: i
a(:) = 2
b(:) = 3
c(:) = 4
d(:) = 5
2018-12-28 15:30:48 +00:00
if (acc_is_present (z) .neqv. .true.) STOP 8
2017-04-10 11:32:00 +00:00
call subr0 (a, b, c, d)
call test (a, .false.)
call test (b, .false.)
call test (c, .false.)
call test (d, .false.)
do i = 1, N
2018-12-28 15:30:48 +00:00
if (a(i) .ne. 8) STOP 9
if (b(i) .ne. 8) STOP 10
if (c(i) .ne. 8) STOP 11
if (d(i) .ne. 13) STOP 12
2017-04-10 11:32:00 +00:00
end do
end program