calling random_number() in global subroutine

The PGI CUDA Fortran guide has a section “Fortran Intrinsics” which says, “This section lists the Fortran intrinsic functions allowed in device subprograms.” Below that, in Table 3.7, is listed “random_number” and “random_seed.”

However, in my code, I have a few lines in an attributes(global) subroutine:

real :: drps(128)
call random_number(drps)

and when I try to compile this, I get an error message: “Calls from device code to a host subroutine are allowed only in emulations mode - random_number” If I comment the call out, it compiles just fine.

Guess I’m confused. Can I call random_number somehow? If not, what did the manual mean? Thanks.

Hi cablesb,

There are still a few features left to implement in CUDA Fortran, and random number generation is one of the them. It turned out to be a very difficult to implement and most likely wont be available for some time if at all.

In the mean time, a list of random numbers need to be pre-computed, either on the host or device. An example of this can be found in my article Tuning a Monte Carlo Algorithm on GPUs. Besides the Mercenne Twister code I use, you could also use CURAND.

  • Mat