I have been experimenting with the new ability to have pure functions in DO CONCURRENT loops. In my testing, I have found that it is necessary to have “!$acc routine (func) seq” in my pure functions for the code to compile. Does this mean “!$acc routine” is needed for a pure function in a DO CONCURRENT loop? I have included a code sample. The first code compiles correctly and runs, but once the “!$acc routine” is deleted (second code) the code will not compile. Both codes are compiled with -stdpar=gpu.
module addTwo_interface
!$acc routine(addTwo) seq
interface
pure function addTwo (num)
implicit none
real, intent(in) :: num
real, intent(out) :: addTwo
end function addTwo
end interface
end module
c
c-----------------------------------------------------------------------
c
program TEST
implicit none
real :: numbers(5,5)
integer :: i,j
integer, dimension(:,:), allocatable :: temp
allocate(temp(5,5))
c
call set_data(numbers)
c
do i=1,5
print*, numbers(i,1)
enddo
end program
c
c-----------------------------------------------------------------------
c
subroutine set_data(numbers)
use addTwo_interface
implicit none
real :: numbers(5,5)
integer :: i,j
do concurrent (i=1:5,j=1:5)
numbers(i,j) = addTwo(1.0)
enddo
end subroutine
c
c-----------------------------------------------------------------------
c
pure function addTwo(num)
!$acc routine(addTwo) seq
implicit none
real, intent(in) :: num
real, intent(out) :: addTwo
c
addTwo = num+2.0
c
end function
Second code :
module addTwo_interface
interface
pure function addTwo (num)
implicit none
real, intent(in) :: num
real, intent(out) :: addTwo
end function addTwo
end interface
end module
c
c-----------------------------------------------------------------------
c
program TEST
implicit none
real :: numbers(5,5)
integer :: i,j
integer, dimension(:,:), allocatable :: temp
allocate(temp(5,5))
c
call set_data(numbers)
c
do i=1,5
print*, numbers(i,1)
enddo
end program
c
c-----------------------------------------------------------------------
c
subroutine set_data(numbers)
use addTwo_interface
implicit none
real :: numbers(5,5)
integer :: i,j
do concurrent (i=1:5,j=1:5)
numbers(i,j) = addTwo(1.0)
enddo
end subroutine
c
c-----------------------------------------------------------------------
c
pure function addTwo(num)
implicit none
real, intent(in) :: num
real, intent(out) :: addTwo
c
addTwo = num+2.0
c
end function
- Miko