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

Regression: 2023.0.0 vs. 2022.2.1: random_init not working

scivision
New Contributor I
1,120 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
1 Solution
scivision
New Contributor I
626 Views
0 Kudos
8 Replies
Steve_Lionel
Black Belt
931 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
0 Kudos
hakostra1
New Contributor II
905 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

0 Kudos
scivision
New Contributor I
870 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.

0 Kudos
Steve_Lionel
Black Belt
855 Views

I submitted this as issue 05692694.

0 Kudos
TobiasK
Moderator
814 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


0 Kudos
scivision
New Contributor I
627 Views

Intel oneAPI 2023.1 fixed this issue.

0 Kudos
Steve_Lionel
Black Belt
609 Views

So it is - my support ticket never got updated with this.

0 Kudos
TobiasK
Moderator
541 Views

Hi,

good that you already tried the new release. As you noticed the fix is included in the 2023.1 release. Thanks again for reporting this issue.


Best

Tobias


This issue has been resolved and we will no longer respond to this thread. If you require additional assistance from Intel, please start a new thread. Any further interaction in this thread will be considered community only


0 Kudos
Reply