From 195c1fe36595615a9773d738a1f89dae6afdf39f Mon Sep 17 00:00:00 2001 From: GregPlowman Date: Thu, 16 Jan 2025 11:42:37 +1100 Subject: [PATCH 1/4] Use reinterpret instead of unsafe_wrap for WrappedRNG field vals Use reinterpret instead of unsafe_wrap for WrappedRNG field vals. Correctly provides reinterpreted view into WrappedRNG field cache on Distributed workers. --- src/RNGTest.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/RNGTest.jl b/src/RNGTest.jl index be9aa5f..c70acbb 100644 --- a/src/RNGTest.jl +++ b/src/RNGTest.jl @@ -33,7 +33,7 @@ module RNGTest rng::RNG cache::Vector{T} fillarray::Bool - vals::Vector{UInt32} + vals::Union{Vector{UInt32}, Base.ReinterpretArray{UInt32, 1, T, Vector{T}, false}} idx::Int end @@ -45,7 +45,7 @@ module RNGTest end cache = Vector{T}(undef, cache_size) fillcache(WrappedRNG{T, RNG}(rng, cache, fillarray, - unsafe_wrap(Array, convert(Ptr{UInt32}, pointer(cache)), sizeof(cache)÷sizeof(UInt32)), + reinterpret(UInt32, cache), 0)) # 0 is a dummy value, which will be set correctly by fillcache end From c4a224c6f4f266fbafd17fdee61a4fd5f17cc478 Mon Sep 17 00:00:00 2001 From: GregPlowman Date: Thu, 16 Jan 2025 11:44:03 +1100 Subject: [PATCH 2/4] Test Distributed smallcrushJulia Test Distributed smallcrushJulia which internally uses pmap --- test/runtests.jl | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/runtests.jl b/test/runtests.jl index 53b0b2f..0c45ab1 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -160,3 +160,14 @@ end RNGTest.smallcrushTestU01(rng) @test all(t -> t > pval, mapreduce(s -> [s...], vcat, RNGTest.smallcrushJulia(rng))) end + +@testset "Distributed smallcrushJulia" begin + pids = addprocs() + @everywhere using RNGTest + for T in (UInt32, UInt64, Float64) + rng = RNGTest.wrap(Xoshiro(), T) + results = RNGTest.smallcrushJulia(rng) + @test all(ps -> all(>(pval), ps), results) + end + rmprocs(pids) +end From b29b024e534faa65d5f617a71f583da376fa3a1b Mon Sep 17 00:00:00 2001 From: GregPlowman Date: Thu, 16 Jan 2025 12:52:30 +1100 Subject: [PATCH 3/4] using Distributed in runtests.jl --- test/runtests.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/test/runtests.jl b/test/runtests.jl index 0c45ab1..8ae4776 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,6 +1,7 @@ using Test using RNGTest using Random +using Distributed f = rand pval = 0.001 From 88c3567c47adf1532a8cb61b59ba9a21a0e0bd8e Mon Sep 17 00:00:00 2001 From: GregPlowman Date: Fri, 17 Jan 2025 10:52:41 +1100 Subject: [PATCH 4/4] Ensure Xoshiro is defined before use On Julia versions <= v1.6, Xoshiro is not defined. In this case, use MersenneTwister instead. --- test/runtests.jl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/runtests.jl b/test/runtests.jl index 8ae4776..8dad654 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -166,7 +166,11 @@ end pids = addprocs() @everywhere using RNGTest for T in (UInt32, UInt64, Float64) - rng = RNGTest.wrap(Xoshiro(), T) + if isdefined(Random, :Xoshiro) + rng = RNGTest.wrap(Xoshiro(), T) + else + rng = RNGTest.wrap(MersenneTwister(), T) + end results = RNGTest.smallcrushJulia(rng) @test all(ps -> all(>(pval), ps), results) end