I am using the great package DrWatson and I am trying to work with pmap.
My project is also a package, and I am trying to use @everywhere to let the workers know about the function I am trying to run.
The problem is that the function is not recognized. This is the error I get
ERROR: LoadError: UndefVarError: my_func not defined
The way I start the script is
using Distributed
@everywhere using DrWatson
@everywhere import Pkg
@everywhere Pkg.activate("path_to_project")
@everywhere using MyProject
addprocs(4)
Then by running
A = pmap(MyProject.my_func(), 1:10)
I get the error above.
How should I set up this script to work with pmap properly?
Thanks for the suggestion.
I moved it, but it doesn’t help. I get the same error.
The code is
using Distributed
addprocs(4)
@everywhere using DrWatson
@everywhere import Pkg
@everywhere Pkg.activate("path_to_project")
@everywhere using MyProject
I would not expect my_func to work with map, unless you have other methods defined. The problem is that you appear to be passing elements from 1:N to my_func, but there is no such argument to accept those elements. What I am finding is a method error:
julia> my_func(;a, b) = a + b
my_func (generic function with 1 method)
julia> map(my_func(a=1,b=2), 1:10)
ERROR: MethodError: objects of type Int64 are not callable
Stacktrace:
[1] iterate
@ ./generator.jl:47 [inlined]
[2] _collect
@ ./array.jl:691 [inlined]
[3] collect_similar
@ ./array.jl:606 [inlined]
[4] map(f::Int64, A::UnitRange{Int64})
@ Base ./abstractarray.jl:2294
[5] top-level scope
@ REPL[2]:1