versioninfo()
Julia Version 1.6.0-rc1 Commit a58bdd9010 (2021-02-06 15:49 UTC) Platform Info: OS: Windows (x86_64-w64-mingw32) CPU: AMD Ryzen 5 3500 6-Core Processor WORD_SIZE: 64 LIBM: libopenlibm LLVM: libLLVM-11.0.1 (ORCJIT, znver2)
using Distributed
addprocs()
@show nprocs()
@show nworkers()
nprocs() = 7 nworkers() = 6
6
@everywhere using Random
@everywhere function ntoone(rng=Random.default_rng())
s = rand(rng)
for n in Base.Iterators.countfrom(2)
s += rand(rng)
s < 1 || return n
end
end
function estimate_e(N=10^6; rngfunc=Random.default_rng)
S = @distributed (+) for _ in 1:N
ntoone(rngfunc())
end
S / N
end
estimate_e(10)
3.1
@time estimate_e(10^8)
0.288376 seconds (572 allocations: 24.297 KiB)
2.71821524
@time estimate_e(10^9)
2.866110 seconds (630 allocations: 25.516 KiB)
2.718281449
@time estimate_e(10^10)
28.454274 seconds (1.29 k allocations: 47.047 KiB)
2.7182888143