我为OpenAcc提供了对名为"lang_force“的子例程的访问权限,并在该子例程中调用了Fortran90内部函数RANDOM_NUMBER()。
subroutine lang_force(damp, temp, noise)
!$acc routine(lang_force)
implicit none
double precision, intent(in) :: damp, temp
double precision, dimension(1:3), intent(out) :: noise
double precision :: kb, a1, theta, phi, mag1, pi,r,s
integer :: i,j,k
double precision :: x,y,z
kb = 1.3806E-23
!kb = 1.0
pi=4.D0*DATAN(1.D0)
call random_number(a1)
call random_number(r)
call random_number(s)
mag1 = sqrt(-2.0*log(a1))
theta = r*pi
phi = 2.0*s*pi
x = mag1*cos(phi)*sin(theta)
y = mag1*sin(theta)*sin(phi)
z = mag1*cos(theta)
noise(1) = sqrt(2.0*kb*temp*damp)*x
noise(2) = sqrt(2.0*kb*temp*damp)*y
noise(3) = sqrt(2.0*kb*temp*damp)*z
end subroutine lang_force当用最新版本的pdf90编译时,它告诉我它需要访问RANDOM_NUMBER()。如何向这样的fortran90内部子例程声明例程指令?
发布于 2020-09-24 03:08:55
并不是所有的Fortran内部函数都在设备代码中得到支持,包括RANDOM_NUMBER。
特别是RANDOM_NUMBER不是线程安全的,因为所有的线程都会共享相同的状态。相反,您需要使用"2020/examples/CUDA-Libraries/cuRAND/test_rand_oacc_ftn“目录下的编译器附带的示例所使用的cuRand。
虽然这是用C语言编写的,但我在NVIDIA用户论坛上写了更详细的内容:
https://forums.developer.nvidia.com/t/random-numbers-on-device-generation/135748/2
https://stackoverflow.com/questions/64030199
复制相似问题