How do you move data from one processor to another in julia?
Say I have an array
a = [1:10]
Or some other data structure. What is
To supplement @spencerlyon2 's answer here are some macros:
function sendtosimple(p::Int, nm, val)
ref = @spawnat(p, eval(Main, Expr(:(=), nm, val)))
end
macro sendto(p, nm, val)
return :( sendtosimple($p, $nm, $val) )
end
macro broadcast(nm, val)
quote
@sync for p in workers()
@async sendtosimple(p, $nm, $val)
end
end
end
The @spawnat macro binds a value to a symbol on a particular process
julia> @sendto 2 :bip pi/3
RemoteRef{Channel{Any}}(9,1,5340)
julia> @fetchfrom 2 bip
1.0471975511965976
The @broadcast macro binds a value to a symbol in all processes except 1 (as I found doing so made future expressions using the name copy the version from process 1)
julia> @broadcast :bozo 5
julia> @fetchfrom 2 bozo
5
julia> bozo
ERROR: UndefVarError: bozo not defined
julia> bozo = 3 #these three lines are why I exclude pid 1
3
julia> @fetchfrom 7 bozo
3
julia> @fetchfrom 7 Main.bozo
5