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
There were an issue on multithreaded code that would have crashed when the number of interactive threads
would have been set >1 (from command line).
This commit correctly account for whatever the number of interactive threads is.
masterSeed =rand(rng,100:Int(floor(typemax(Int64)/10000))) # Some RNG have problems with very small seed. Also, the master seed has to be computed _before_ generate_parallel_rngs
options(m).verbosity == FULL &&println("Testing candidate $candidate")
1233
1233
mc =deepcopy(m)
@@ -1285,12 +1285,12 @@ function tune!(m,method::SuccessiveHalvingSearch,data)
1285
1285
options(m).verbosity >= STD &&println("(e $e / $epochs) N data / n candidates / n candidates to retain : $(n_orig * res_share)\t$ncandidates_thisepoch$ncandidates_tokeep")
Copy file name to clipboardExpand all lines: src/Utils/Stochasticity.jl
+3-3Lines changed: 3 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -15,14 +15,14 @@ For multi-threaded models, return n independent random number generators (one pe
15
15
16
16
Note that each ring is a _copy_ of the original random ring. This means that code that _use_ these RNGs will not change the original RNG state.
17
17
18
-
Use it with `rngs = generate_parallel_rngs(rng,Threads.nthreads()+1)` to have a separate rng per thread.
19
-
**Attention**: the `+1` is necessary from Julia 1.12 onwards, because the main thread is counted differently.
18
+
Use it with `rngs = generate_parallel_rngs(rng,Threads.nthreads()` to have a separate rng per thread.
19
+
**Attention**: `Threads.threadid()` of working threads is between `Threads.nthreads(:interactive)` and `Threads.nthreads(:interactive)+Threads.nthreads(:default)`
20
20
By default the function doesn't re-seed the RNG, as you may want to have a loop index based re-seeding strategy rather than a threadid-based one (to guarantee the same result independently of the number of threads).
21
21
If you prefer, you can instead re-seed the RNG here (using the parameter `reSeed=true`), such that each thread has a different seed. Be aware however that the stream of number generated will depend from the number of threads at run time.
Copy file name to clipboardExpand all lines: test/Utils_tests.jl
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -729,10 +729,10 @@ function innerFunction(bootstrappedx; rng=Random.GLOBAL_RNG)
729
729
end
730
730
functionouterFunction(x;rng = Random.GLOBAL_RNG)
731
731
masterSeed =rand(rng,100:Int(floor(typemax(Int64)/10000))) # important: with some RNG it is important to do this before the generate_parallel_rngs to guarantee independance from number of threads
732
-
rngs =generate_parallel_rngs(rng,Threads.nthreads()+1) # make new copy instances
732
+
rngs =generate_parallel_rngs(rng,Threads.nthreads()) # make new copy instances
733
733
results =Array{Float64,1}(undef,30)
734
734
Threads.@threadsfor i in1:30
735
-
tsrng = rngs[Threads.threadid()] # Thread safe random number generator: one RNG per thread
735
+
tsrng = rngs[Threads.threadid()-Threads.nthreads(:interactive)] # Thread safe random number generator: one RNG per thread
736
736
Random.seed!(tsrng,masterSeed+i*10) # But the seeding depends on the i of the loop not the thread: we get same results indipendently of the number of threads
0 commit comments