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
In which cases is sampling thread-safe? It seems that (at least) sampling from Hypergeometric apparently isn't.
This might be due to this C-code in Rmath-julia. It should be documented if sampling from distributions is thread-safe.
Below example runs fine without the @threads macro. With the macro, it seemingly runs forever and prints warnings to the console (which seem to come from that C library Rmath-julia).
using Random, Distributions
Random.seed!(42)
functionsample_KkC(n; N, Q)
total_errors = Distributions.Binomial(N, Q)
K =rand(total_errors)
d_hyper =Hypergeometric(K, N - K, n)
k =rand(d_hyper)
return k
endfunctionmain()
functionf(Q)
objective(n) = [sample_KkC(n; N =819_200, Q) for _ =1:100]
vals = [10, 100]
objective.(vals)
end
Qs = [0.05, 0.055, 0.1, 0.2, 0.3]
Threads.@threadsfor i ineachindex(Qs)
f(Qs[i])
endendmain()
output
rhyper.c: afc(i), i=-15 < 0 -- SHOULD NOT HAPPEN!
rhyper(*, n1=-262145576, n2=100, k=10000): branch III: giving up after 1384304160 rejections
rhyper(*, n1=-287340072, n2=100, k=10000): branch III: giving up after 1384304160 rejections
System Info
julia> versioninfo()
Julia Version 1.10.0
Commit 3120989f39b (2023-12-25 18:01 UTC)
Build Info:
Official https://julialang.org/ release
Platform Info:
OS: Linux (x86_64-linux-gnu)
CPU: 8 × 11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-15.0.7 (ORCJIT, tigerlake)
Threads: 11 on 8 virtual cores
(jl_Lv9tPw) pkg> st
Status `/tmp/jl_Lv9tPw/Project.toml`
[31c24e10] Distributions v0.25.107
The text was updated successfully, but these errors were encountered:
In which cases is sampling thread-safe? It seems that (at least) sampling from
Hypergeometric
apparently isn't.This might be due to this C-code in Rmath-julia. It should be documented if sampling from distributions is thread-safe.
Below example runs fine without the
@threads
macro. With the macro, it seemingly runs forever and prints warnings to the console (which seem to come from that C library Rmath-julia).output
System Info
The text was updated successfully, but these errors were encountered: