-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Closed
Labels
multithreadingBase.Threads and related functionalityBase.Threads and related functionalityperformanceMust go fasterMust go fasterrandomnessRandom number generation and the Random stdlibRandom number generation and the Random stdlib
Description
I was surprised at how big a hit we suffer in looking up the THREAD_RNG — even when Julia is started with only 1 thread and without using @threads at all! Is there something we can do here?
julia> using Random, .Threads
julia> nthreads()
1
julia> function serialpi(n)
inside = 0
for i in 1:n
x, y = rand(), rand()
inside += (x^2 + y^2 <= 1)
end
return 4 * inside / n
end
serialpi (generic function with 1 method)
julia> serialpi(1); @time serialpi(100_000_000);
0.625890 seconds
julia> function serialpi2(n)
inside = 0
rng = Random.THREAD_RNGs[1]
for i in 1:n
x, y = rand(rng), rand(rng)
inside += (x^2 + y^2 <= 1)
end
return 4 * inside / n
end
serialpi2 (generic function with 1 method)
julia> serialpi2(1); @time serialpi2(100_000_000);
0.257850 secondsMetadata
Metadata
Assignees
Labels
multithreadingBase.Threads and related functionalityBase.Threads and related functionalityperformanceMust go fasterMust go fasterrandomnessRandom number generation and the Random stdlibRandom number generation and the Random stdlib