Skip to content

[flang][runtime] random_init collision rate is high (>1%) on some platforms and time dependent #106221

@jeanPerier

Description

@jeanPerier

Two calls to random_init close to one another may init random to the same seed with a high probability (>20%) on certain platform at a given time (the collision probability seems to cycle with the time in periods of about 1 minute). This likely shows a lack or randomness in f18 random_init implementation.

This was initially caught by gfortran random_init_2.f90 test in LLVM test suite that sporadically failed: https://github.com/llvm/llvm-test-suite/blob/f6d8e5692b65387703a687a556c2f77111cbfaed/Fortran/gfortran/regression/random_init_2.f90

I went on and made a sampling program
sampling.f90
to check random_init collisions between two random_init calls next to one another.

Attached is a graph that shows the collision rate (in %) in function of the runtime (in seconds).

f18_random_init

f18 random_init clearly has a cyclic behavior with spikes where the collision rate goes above 20% for 20 seconds every 2 minutes or so, while it can be zero (no collisions out of 100000 runs) for periods of 20 seconds too. Attached is gnuplot graph and the program to sample it.

The same graph produced by a gfortran compiled exec on the same is mostly flat and never goes above 0.005% collision rate (most samples are 0., with sporadic 4.99999989E-03% samples). Interestingly enough, gfortran is 40x slower in executing random intrinsic calls.

gfortran_random_init

Metadata

Metadata

Assignees

Labels

enhancementImproving things as opposed to bug fixing, e.g. new or missing featureflang:runtime

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions