You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The random numbers returned after setting the seed in the primary thread vary with the number of threads/tasks in use.
Desired Solution
Ideally, there would be no such dependence.
More realistically, this behavior should be readily apparent in the documentation.
Example
using Random
Random.seed!(739587835)
functionworker()
sleep(0.2)
end# launch workers
tasks = [Threads.@spawnworker() for i in1:Threads.nthreads()]
println(Random.randn(10))
Results
-t varies the number of threads, and as they vary the random numbers produced change. Setting the seed does not assure reproducibility.
Varying the number of threads without spawning any tasks does not give this behavior. The random numbers are the same regardless of the number of threads when there are no tasks.
Comment
I guess this is the result of the interaction of tasks and the RNG. In particular, TaskLocalRNG says "task creation is an event that changes the parent's RNG state". Note that the test program makes no explicit reference to TaskLocalRNG.
If this behavior is documented at https://docs.julialang.org/en/v1/stdlib/Random, I don't see it. That documentation refers to GLOBAL_RNG as a default argument without defining it. It does say the generator has task specific state; it is unclear how the main thread figures into that.
Environment
julia> versioninfo()
Julia Version 1.8.5
Commit 17cfb8e (2023-01-08 06:45 UTC)
Platform Info:
OS: Windows (x86_64-w64-mingw32)
CPU: 20 × Intel(R) Xeon(R) CPU E5-2690 v4 @ 2.60GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-13.0.1 (ORCJIT, broadwell)
Threads: 16 on 20 virtual cores
Environment:
JULIA_EDITOR = code
JULIA_NUM_THREADS =
Installed by download from julialang.org.
The text was updated successfully, but these errors were encountered:
Summary
The random numbers returned after setting the seed in the primary thread vary with the number of threads/tasks in use.
Desired Solution
Ideally, there would be no such dependence.
More realistically, this behavior should be readily apparent in the documentation.
Example
Results
-t
varies the number of threads, and as they vary the random numbers produced change. Setting the seed does not assure reproducibility.Varying the number of threads without spawning any tasks does not give this behavior. The random numbers are the same regardless of the number of threads when there are no tasks.
Comment
I guess this is the result of the interaction of tasks and the RNG. In particular,
TaskLocalRNG
says "task creation is an event that changes the parent's RNG state". Note that the test program makes no explicit reference toTaskLocalRNG
.If this behavior is documented at https://docs.julialang.org/en/v1/stdlib/Random, I don't see it. That documentation refers to
GLOBAL_RNG
as a default argument without defining it. It does say the generator has task specific state; it is unclear how the main thread figures into that.Environment
julia> versioninfo()
Julia Version 1.8.5
Commit 17cfb8e (2023-01-08 06:45 UTC)
Platform Info:
OS: Windows (x86_64-w64-mingw32)
CPU: 20 × Intel(R) Xeon(R) CPU E5-2690 v4 @ 2.60GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-13.0.1 (ORCJIT, broadwell)
Threads: 16 on 20 virtual cores
Environment:
JULIA_EDITOR = code
JULIA_NUM_THREADS =
Installed by download from julialang.org.
The text was updated successfully, but these errors were encountered: