在Fortran90内部函数上使用例程指令

问题描述

我已授予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内在子例程声明例程指令?

解决方法

设备代码(包括RANDOM_NUMBER)中不支持所有Fortran内部函数。

尤其是RANDOM_NUMBER并不是线程安全的,因为所有线程将共享同一状态。取而代之的是,您需要使用cuRand,我们将其随附的示例与编译器一起运送到“ 2020 / examples / CUDA-Libraries / cuRAND / test_rand_oacc_ftn”目录下。

虽然这是C语言,但我在NVIDIA用户论坛上写的更详细:

https://forums.developer.nvidia.com/t/random-numbers-on-device-generation/135748/2

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...