Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
27523 Discussions

Regression: 2023.0.0 vs. 2022.2.1: random_init not working

scivision
New Contributor I
423 Views

For the following minimal example, there appears to be a regression in Intel Fortran LLVM 2023.0.0 20221201 and Classic 2021.8.0.20221119 that works in 2022.2.1 Build 20221101. The `random_init()` second call should use a new seed, but does not.

 

program demo_rand

use, intrinsic :: iso_fortran_env, only : stderr=>error_unit
implicit none

real :: r1, r2

call random_init(.false., .false.)
call random_number(r1)
call random_init(.false., .false.)
call random_number(r2)
if (r1==r2) then
  write(stderr,*) 'random_init fail: ', r1, ' == ', r2
  error stop 'these two random number should not match if random_init is working'
endif

print *, "OK: random_init: ", r1, " /= ", r2

end program

 



0 Kudos
5 Replies
Steve_Lionel
Black Belt Retired Employee
234 Views

You are correct that the second call to RANDOM_INIT should result in a different sequence. The standard says (emphasis mine), "CALL RANDOM_INIT(REPEATABLE=false, IMAGE_DISTINCT=false) is equivalent to invoking RANDOM_SEED with a processor-dependent value for PUT that is the same on every invoking image. Different values for PUT shall be used for subsequent invocations, and for each execution of the program.

I've reworked your test program to more precisely match what the standard says:

program demo_rand

use, intrinsic :: iso_fortran_env, only : stderr=>error_unit
implicit none

integer :: szize
integer, allocatable :: seed1(:),seed2(:)

call random_seed(size=szize)
allocate (seed1(szize),seed2(szize))
call random_init(.false., .false.)
call random_seed (get=seed1)
print *, seed1
call random_init(.false., .false.)
call random_seed(get=seed2)
print *, seed2

if (all(seed1==seed2)) then
  write(stderr,*) 'random_init fail'
  error stop 'these two seeds should not match if random_init is working'
endif

print *, "OK: random_init"

end program
hakostra1
Beginner
208 Views

In contrast to the first post that report a change in behavior in the last release, do not see any changes in behavior between 2022.1, 2022.2.1 and 2023.0 versions of ifx on Linux (I just tried these three versions as I all have them locally installed).

Here i s a link to the compiler explorer with Steve's slightly modified example in ifx 2022.2.1:

https://godbolt.org/z/4zrxh8hn3

scivision
New Contributor I
173 Views

Thanks @hakostra1 you are correct. I was checking between Windows 2022.2.1 that does NOT have this issue and Linux that has long had this issue. I also checked with ifort  Version 2021.1 Build 20201112 on Linux and saw the same issue. So yes, it's NOT actually a regression, it's just long broken behavior.

Steve_Lionel
Black Belt Retired Employee
158 Views

I submitted this as issue 05692694.

TobiasK
Employee
117 Views

Hi,

thanks for reporting. I opened an internal ticket and will let you know as soon as it is fixed. CMPLRLLVM-42927

 

Best

Tobias


Reply