The following phenomenon gave me quite a headache and took me a while to track down. Take the following example (using Julia 1.11.1 or 1.10.6, probably older ones as well):
julia> using Distributed, Statistics
julia> addprocs(1)
1-element Vector{Int64}:
2
julia> remotecall_fetch(mean, 2, [1,2])
ERROR: On worker 2:
KeyError: key Base.PkgId(Base.UUID("10745b16-79ce-11e8-11f9-7d13ad32a3b2"), "Statistics") not found
...
This is fine and expected, the worker process hasn’t loaded the Statistics
module. And now consider a slightly modified example:
julia> using Distributed
julia> addprocs(1)
1-element Vector{Int64}:
2
julia> using Statistics
julia> remotecall_fetch(mean, 2, [1,2])
1.5
julia> remotecall_fetch(typeof, 2, Statistics)
Module
Notice that I deliberately haven’t used @everywhere using Statistics
. So how on earth does the worker process know about the Statistics
module in this case? What makes @everywhere
implicit? I tried to find anything at least hinting this kind of behavior in the manual, but failed.
Note that the same happens if I put the above lines in a source file and run Julia non-interactively. E.g., this throws an exception (as expected):
using Distributed, Statistics
addprocs(1)
println(remotecall_fetch(mean, 2, [1, 2]))
Whereas this prints 1.5:
using Distributed
addprocs(1)
using Statistics
println(remotecall_fetch(mean, 2, [1, 2]))