Hello,
I have a function called from within an accelerated section of the main program that in turn calls a subroutine. If the parameter passed in the subroutine is defined locally within the function, the loop with the main program that is accelerated gets parallelized just fine. However, if the parameter is defined globally, the loop does not get parallelized.
Could you please explain why this is?
For example:
program main
use accel_lib
EXTERNAL FUNC1
integer :: n=10 ! size of the vector
real :: elev=0.0, azim=0.0, SPRAD(n)
integer :: i
call acc_init( acc_device_nvidia )
!$acc region
do i = 1,n
SPRAD(i) = FUNC1(elev,azim)
enddo
!$acc end region
end program
REAL FUNCTION FUNC1(ELEV,AZIM)
USE HEADER
EXTERNAL SUB1
REAL, INTENT(IN) :: ELEV,AZIM
REAL :: EXTRA
LOGICAL :: FLEARTH
CALL SUB1(ELEV, AZIM, EXTRA, 0, FLEARTH) Works
!CALL SUB1(ELEV, AZIM, SOLAZ, 0, FLEARTH) Doesn’t work
ISIS_API = 5.0
RETURN
END FUNCTION FUNC1
SUBROUTINE SUB1(ELEV,AZIM,LAT0,IBODY,FLEARTH)
!**** Argument Declarations
INTEGER, INTENT(IN) :: IBODY
REAL , INTENT(IN) :: ELEV,AZIM,LAT0
LOGICAL, INTENT(OUT) :: FLEARTH
RETURN
END SUBROUTINE SUB1
MODULE HEADER
REAL :: SOLAZ
END MODULE HEADER
[/code]