Следующий код просто генерирует простую тройку случайных чисел:
program testrand
integer, parameter :: nz = 160, nf = 160, nlt = 90
real :: tmpidx(3)
integer :: idxarr(3), idx1, idx2, idx3, seed_size, ticks
integer, allocatable :: seed(:)
call random_seed(size=seed_size)
allocate(seed(seed_size))
call system_clock(count=ticks)
seed = ticks+37*(/(i-1, i=1,seed_size)/)
call random_seed(put=seed)
deallocate(seed)
call random_number(tmpidx)
idxarr = tmpidx * (/nz, nf, nlt/)
idx1 = max(1,idxarr(1))
idx2 = max(1,idxarr(2))
idx3 = max(1,idxarr(3))
print *,idx1, idx2, idx3
end program
Я компилирую это с помощью gfortran, запускаю несколько раз и получаю:
> gfortran testrand.f90
> ./a.out
74 98 86
> ./a.out
113 3 10
> ./a.out
44 104 27
Выглядит довольно случайно. Теперь компилирую с PGI Fortran и запускаю несколько раз:
> pgf90 testrand.f90
> ./a.out
1 1 1
> ./a.out
1 1 1
> ./a.out
1 1 1
Конечно, нельзя быть полностью уверенным, но я подозреваю, что это не случайно. :) Кто-нибудь знает, что здесь происходит? Кто-нибудь знает правильный способ получения случайных чисел с помощью PGI Fortran?