cuda fortran and random number

Hello,

a) is there any way to invoke a simple random number function from inside a cuda fortran kernel. Until now I use a simple random number generator which I adapted as a device subroutine which, however, is not so easy to use because I have to manually manage the parallelism of calls to avoid that the different threads extract the same random sequence (i.e., I use an array of seeds and of saved variable).

b) Moreover, the subroutine can be called only with a predefined thread grid, and not in different loops. Any suggestion on how to avoid that?

c) Finally, I would like to call it from an automatically generated cuf directive kernel. Is it possibile?

d) curand seems quite complicated to use, is there any prepared fortran interface to call it in cuda fortran?

I do not need an optimal random number generator, ran2.f of numerical recipes could be perfect for me.

thank you
Francesco

Hi Francesco,

Unfortunately random_number can not yet be called from within a device kernel. We do still wish to add this as some point, but currently there are technical challenges that prevent it’s implementation.

For now, you will need to pre-compute a set of random numbers generated via CURAND or other random number generator.

  • Mat