Do you have a minimal example?
I typically use this approach:
- Put everything you need distributed to workers into a Module.
- Save Module to filesystem
- Ensure path to Module is in
LOAD_PATH
addprocs()
using Module
Notes:
- It is important to
addprocs
beforeusing Module
- You shouldn’t need
@everywhere
- You shouldn’t get warnings about replacing module.
Here’s an example:
module ModuleA
export testA
function testA(x)
println(x, " -> ", x*x)
return x*x
end
end
Save this to file ModuleA.jl
(or ModuleA/src/ModuleA.jl
)
Now run this:
addprocs()
# ensure module is in LOAD_PATH
# in this example, module A was saved to working directory (but can be any directory)
thisDir = dirname(@__FILE__())
any(path -> path == thisDir, LOAD_PATH) || push!(LOAD_PATH, thisDir)
using ModuleA
pmap(testA, 1:10)
And here’s the output:
Julia-0.5.2> include("loading_pmap.jl")
From worker 2: 1 -> 1
From worker 3: 4 -> 16
From worker 5: 2 -> 4
From worker 4: 3 -> 9
From worker 2: 5 -> 25
From worker 5: 6 -> 36
From worker 4: 7 -> 49
From worker 3: 8 -> 64
From worker 2: 9 -> 81
From worker 4: 10 -> 100
10-element Array{Any,1}:
1
4
9
16
25
36
49
64
81
100