Hi, my goal is to within one script define a module only once in my local scope, and then read it to all my workers. However, I cannot figure out what to do. This is my MWE:
using Distributed
module myModule
export f
function f(x_in)
return x_in^2.0
end
end
using .myModule
f(1.0) # This works as expected
addprocs(1)
@everywhere using .myModule # This throws error "myModule not defined"
@everywhere f(1.0)
If I put myModule in a separate myModule.jl, then the following works:
using Distributed
include("myModule.jl"); using .myModule
f(1.0)
addprocs(1)
@everywhere begin include("myModule.jl"); using .myModule end
@everywhere f(1.0)
This solution is OK, but I prefer to have everything in one script for reasons.
(The actual goal is to conveniently load the function f(x_in)
without having to use the solution in Easy way to send custom function to distributed workers? - #2 by greg_plowman)