Skip to content

Commit 6bbdad1

Browse files
authored
Merge pull request #31 from GregPlowman/GregPlowman/distributed_fix
Fix for Distributed use of WrappedRNG
2 parents cd8c174 + 88c3567 commit 6bbdad1

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/RNGTest.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ module RNGTest
3333
rng::RNG
3434
cache::Vector{T}
3535
fillarray::Bool
36-
vals::Vector{UInt32}
36+
vals::Union{Vector{UInt32}, Base.ReinterpretArray{UInt32, 1, T, Vector{T}, false}}
3737
idx::Int
3838
end
3939

@@ -45,7 +45,7 @@ module RNGTest
4545
end
4646
cache = Vector{T}(undef, cache_size)
4747
fillcache(WrappedRNG{T, RNG}(rng, cache, fillarray,
48-
unsafe_wrap(Array, convert(Ptr{UInt32}, pointer(cache)), sizeof(cache)÷sizeof(UInt32)),
48+
reinterpret(UInt32, cache),
4949
0)) # 0 is a dummy value, which will be set correctly by fillcache
5050
end
5151

test/runtests.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Test
22
using RNGTest
33
using Random
4+
using Distributed
45

56
f = rand
67
pval = 0.001
@@ -167,3 +168,18 @@ end
167168
RNGTest.smallcrushTestU01(rng)
168169
@test all(t -> t > pval, mapreduce(s -> [s...], vcat, RNGTest.smallcrushJulia(rng)))
169170
end
171+
172+
@testset "Distributed smallcrushJulia" begin
173+
pids = addprocs()
174+
@everywhere using RNGTest
175+
for T in (UInt32, UInt64, Float64)
176+
if isdefined(Random, :Xoshiro)
177+
rng = RNGTest.wrap(Xoshiro(), T)
178+
else
179+
rng = RNGTest.wrap(MersenneTwister(), T)
180+
end
181+
results = RNGTest.smallcrushJulia(rng)
182+
@test all(ps -> all(>(pval), ps), results)
183+
end
184+
rmprocs(pids)
185+
end

0 commit comments

Comments
 (0)