Skip to content

Commit 0e3ea6e

Browse files
committed
make TaskLocal the default RNG
1 parent edea2de commit 0e3ea6e

File tree

19 files changed

+97
-95
lines changed

19 files changed

+97
-95
lines changed

NEWS.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ Language changes
2626
* Destructuring will no longer mutate values on the left hand side while iterating through values on the right hand side. In the example
2727
of an array `x`, `x[2], x[1] = x` will now swap the first and second entry of `x`, whereas it used to fill both entries with `x[1]`
2828
because `x[2]` was mutated during the iteration of `x`. ([#40737])
29+
* The default random number generator has changed, so all random numbers will be different (even with the
30+
same seed) unless an explicit RNG object is used. See the section on the `Random` standard library below.
2931

3032
Compiler/Runtime improvements
3133
-----------------------------
@@ -39,7 +41,12 @@ Command-line option changes
3941

4042
Multi-threading changes
4143
-----------------------
44+
4245
* If the `JULIA_NUM_THREADS` environment variable is set to `auto`, then the number of threads will be set to the number of CPU threads ([#38952])
46+
* Every `Task` object has a local random number generator state, providing reproducible (schedule-independent) execution
47+
of parallel simulation code by default. The default generator is also significantly faster in parallel than in
48+
previous versions.
49+
4350

4451
Build system changes
4552
--------------------
@@ -130,6 +137,9 @@ Standard library changes
130137

131138
#### Random
132139

140+
* The default random number generator has been changed from Mersenne Twister to [Xoshiro256++](https://prng.di.unimi.it/).
141+
The new generator has smaller state, better performance, and superior statistical properties.
142+
This generator is the one used for reproducible Task-local randomness.
133143

134144
#### REPL
135145

doc/src/devdocs/subarrays.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ julia> A = rand(2,3,4);
1919
2020
julia> S1 = view(A, :, 1, 2:3)
2121
2×2 view(::Array{Float64, 3}, :, 1, 2:3) with eltype Float64:
22-
0.200586 0.066423
23-
0.298614 0.956753
22+
0.98627 0.991588
23+
0.523355 0.105192
2424
2525
julia> S2 = view(A, 1, :, 2:3)
2626
3×2 view(::Array{Float64, 3}, 1, :, 2:3) with eltype Float64:
27-
0.200586 0.066423
28-
0.246837 0.646691
29-
0.648882 0.276021
27+
0.98627 0.991588
28+
0.0890391 0.904316
29+
0.134982 0.299203
3030
```
3131
```@meta
3232
DocTestSetup = nothing

doc/src/manual/performance-tips.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,12 @@ julia> function sum_global()
7777
end;
7878
7979
julia> @time sum_global()
80-
0.009639 seconds (7.36 k allocations: 300.310 KiB, 98.32% compilation time)
81-
496.84883432553846
80+
0.026328 seconds (9.30 k allocations: 416.747 KiB, 36.50% gc time, 99.48% compilation time)
81+
508.39048990953665
8282
8383
julia> @time sum_global()
84-
0.000140 seconds (3.49 k allocations: 70.313 KiB)
85-
496.84883432553846
84+
0.000075 seconds (3.49 k allocations: 70.156 KiB)
85+
508.39048990953665
8686
```
8787

8888
On the first call (`@time sum_global()`) the function gets compiled. (If you've not yet used [`@time`](@ref)
@@ -113,12 +113,12 @@ julia> function sum_arg(x)
113113
end;
114114
115115
julia> @time sum_arg(x)
116-
0.006202 seconds (4.18 k allocations: 217.860 KiB, 99.72% compilation time)
117-
496.84883432553846
116+
0.010298 seconds (4.23 k allocations: 226.021 KiB, 99.81% compilation time)
117+
508.39048990953665
118118
119119
julia> @time sum_arg(x)
120120
0.000005 seconds (1 allocation: 16 bytes)
121-
496.84883432553846
121+
508.39048990953665
122122
```
123123

124124
The 1 allocation seen is from running the `@time` macro itself in global scope. If we instead run
@@ -129,7 +129,7 @@ julia> time_sum(x) = @time sum_arg(x);
129129
130130
julia> time_sum(x)
131131
0.000001 seconds
132-
496.84883432553846
132+
508.39048990953665
133133
```
134134

135135
In some situations, your function may need to allocate memory as part of its operation, and this

stdlib/LinearAlgebra/test/bunchkaufman.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ n = 10
1212
n1 = div(n, 2)
1313
n2 = 2*n1
1414

15-
Random.seed!(12343210)
15+
Random.seed!(12343212)
1616

1717
areal = randn(n,n)/2
1818
aimg = randn(n,n)/2

stdlib/LinearAlgebra/test/cholesky.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ end
3939
n1 = div(n, 2)
4040
n2 = 2*n1
4141

42-
Random.seed!(12343)
42+
Random.seed!(12344)
4343

4444
areal = randn(n,n)/2
4545
aimg = randn(n,n)/2

stdlib/LinearAlgebra/test/dense.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@ n = 10
1515
n1 = div(n, 2)
1616
n2 = 2*n1
1717

18-
Random.seed!(1234321)
18+
Random.seed!(1234323)
1919

2020
@testset "Matrix condition number" begin
2121
ainit = rand(n,n)
2222
@testset "for $elty" for elty in (Float32, Float64, ComplexF32, ComplexF64)
2323
ainit = convert(Matrix{elty}, ainit)
2424
for a in (copy(ainit), view(ainit, 1:n, 1:n))
25-
@test cond(a,1) 4.837320054554436e+02 atol=0.01
26-
@test cond(a,2) 1.960057871514615e+02 atol=0.01
27-
@test cond(a,Inf) 3.757017682707787e+02 atol=0.01
28-
@test cond(a[:,1:5]) 10.233059337453463 atol=0.01
25+
@test cond(a,1) 162.93076496229205 atol=0.5
26+
@test cond(a,2) 97.7362909028399 atol=0.5
27+
@test cond(a,Inf) 196.00888526411242 atol=0.4
28+
@test cond(a[:,1:5]) 10.466183798451308 atol=0.01
2929
@test_throws ArgumentError cond(a,3)
3030
end
3131
end

stdlib/LinearAlgebra/test/eigen.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ n = 10
1111
n1 = div(n, 2)
1212
n2 = 2*n1
1313

14-
Random.seed!(1234321)
14+
Random.seed!(12343215)
1515

1616
areal = randn(n,n)/2
1717
aimg = randn(n,n)/2

stdlib/LinearAlgebra/test/lu.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ n = 10
1111
n1 = div(n, 2)
1212
n2 = 2*n1
1313

14-
Random.seed!(1234321)
14+
Random.seed!(1234323)
1515

1616
areal = randn(n,n)/2
1717
aimg = randn(n,n)/2

stdlib/LinearAlgebra/test/qr.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ n = 10
1111
n1 = div(n, 2)
1212
n2 = 2*n1
1313

14-
Random.seed!(1234321)
14+
Random.seed!(1234325)
1515

1616
areal = randn(n,n)/2
1717
aimg = randn(n,n)/2

stdlib/LinearAlgebra/test/uniformscaling.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ using .Main.Quaternions
1010
isdefined(Main, :OffsetArrays) || @eval Main include(joinpath($(BASE_TEST_PATH), "testhelpers", "OffsetArrays.jl"))
1111
using .Main.OffsetArrays
1212

13-
Random.seed!(123)
13+
Random.seed!(1234543)
1414

1515
@testset "basic functions" begin
1616
@test I === I' # transpose

0 commit comments

Comments
 (0)