addprocs(10)
require("functions.jl")
biglist = @parallel (vcat) for k=1:procs
smalllist(args1, args2,...)
end
smalllist (defined in functions.jl) returns an Vector{Float64} and I'm just stacking them together to make biglist. My problem is that I can't seem to get args1 and args2 to the other processors. I would like something like put! but I don't have a RemoteRef to send it to. I've also thought about defining args1, args2 etc in functions.jl but (a) it's an unnatural place to put these definitions and (b) in the construction of args1, args2 I make calls to rand() and I'm worried args1, args2 will be different for each processor. I've tried @everywhere but there is a lot of code going into the construction of args1, args2 and I don't want 100 lines of code with @everywhere sending all the unnecessary temporary variables to each proc. I guess I'm looking for something like
@shareall args1, args2, ...
or
@sendall args1, args2, ...
Any help would me much appreciated. BTW: it would be especially nice if I didn't have to send args1, args2 at all, just make them visible with shared memory.
julia> addprocs(4)4-element Array{Any,1}: 2 3 4 5
julia> args1 = 11
julia> @parallel (+) for i=1:10 args1 end10
Sorry for the noise and thanks for the help (debugging as it were)!
julia> a=1
1
julia> addprocs(3)
3-element Array{Any,1}:
2
3
4
julia> x = @parallel (vcat) for k=1:3
sin(a)
end
3-element Array{Float64,1}:
0.841471
0.841471
0.841471
julia> foo(a) = sin(a)
foo (generic function with 1 method)
julia> x = @parallel (vcat) for k=1:3
foo(a)
end
exception on exception on exception on 324: : : ERROR: foo not defined
in anonymous at no file:2
in anonymous at multi.jl:1263
in anonymous at multi.jl:840
runparl = true
if runparl
addprocs(3)
a = rand(5)
x = @parallel (vcat) for k=1:3
sin(a)
end
end
@everywhere foo(a) = sin(a)
addprocs(1)
x=10
fetch(@spawnat 2 sin(x))
Why can't the same thing be done with a function?
foo(x) = sin(x)
fetch(@spawnat 2 foo(x)) #<--- gives an error
Of course, I could get this to work using @everywhere foo(x) = sin(x), but for my situation foo depends on a bunch of other functions, which are defined before I add the other workers and I don't want to redefine all these function with @everywhere once the workers are added.
Any help would be appreciated:)
addprocs(4) #<- do this first
@everywhere include("file_that_defines_all_your_functions.jl")
# now do work involving all processors here
That's basically the solution that I've got implemented now. Except I use require("functions.jl") which seems to make these function available to all workers. It feels a bit un-natural since my use of parallelism is a small part of my code, so I end up calling require("functions.jl") twice, first at the top of the script, then again just after addprocs(...).
I also tried looking at the source code for this stuff, in the hopes that I could figure out the finer points of passing/requesting variable from works and local worker namespaces but I just couldn't penetrate it. Maybe I need to wait till someone does a detailed blog post on a particular problem.
Cheers!
https://github.com/JuliaLang/julia/issues/6760
...hope I didn't mess it up.