Hi.
I can’t work out what I’ve done wrong here. I have simply followed the recipe for generating random numbers from the pginsider Monte Carlo example. In my code below, all I am trying to do is generate 4096 ranom numbers and write them to a file to check they look OK. The results I get depend on the number I use for the seed. With the value of 777 from the example, I don’t get any numbers above 0.25. Can anyone spot a stupid mistake?
Also, the CUDA Fortran Programming Guide and Reference seems to suggest that the random_seed and random_number F90 intrinsics are available for device subprograms…
Rob.
pgfortran -c mersenne.cuf
nvcc -O3 -c -Iinc MersenneTwister_kernel.cu
pgfortran -fast -Mcuda mersenne.o MersenneTwister_kernel.o
program random
use cudafor
interface
! C function to load the Mersenne Twister input data set
subroutine loadMTGPU(dat_path) bind(c,name='loadMTGPU')
use iso_c_binding
character(len=80) :: dat_path
end subroutine loadMTGPU
! C function to initialize the random seed on the GPU
subroutine seedMTGPU(seed) bind(c,name='seedMTGPU')
use iso_c_binding
integer(c_int), value :: seed ! Pass by value
end subroutine seedMTGPU
! CUDA C Mersenne Twister algorithm to generate an array of random
! numbers in parallel. Note that nvcc has added '__entry' to the
! end of the function name.
subroutine RandomGPU(d_Rand, n_per_rng) bind(c,name='randomgpu__entry')
use iso_c_binding
real(c_float), dimension(:), device :: d_Rand
integer, value :: n_per_rng ! pass by value
end subroutine RandomGPU
end interface
character(len=80) :: dpath
real, dimension(32*128*1),device :: dXD
real, dimension(32*128*1) :: dXH
integer :: iflag
iflag = cudaSetDevice(0)
dXH = 0.0
dXD = 0.0
write(dpath,'(a)') 'MersenneTwister.dat'//char(0)
call loadMTGPU(dpath)
call seedmtgpu(777)
call randomgpu<<<32,128>>>(dXD,1)
dXH = dXD
open(5,file='test.txt')
write(5,*) dXH
close(5)
end