Hi,
I get an error that x is not defined on worker 2/others when I run this.
using Distributed
addprocs(4)
@everywhere using SharedArrays
x = zero( SharedArray{Float64}( 10 ) );
@everywhere println( x[2] )
What is wrong here?
Thanks
Hi,
I get an error that x is not defined on worker 2/others when I run this.
using Distributed
addprocs(4)
@everywhere using SharedArrays
x = zero( SharedArray{Float64}( 10 ) );
@everywhere println( x[2] )
What is wrong here?
Thanks
It seems, from the docs, that you have to interpolate x to all procs before using it:
julia> using SharedArrays, Distributed
julia> addprocs(4)
4-element Array{Int64,1}:
2
3
4
5
julia> x = zero( SharedArray{Float64}( 10 ) );
julia> @everywhere x = $x
julia> @everywhere println( x[5] )
0.0
From worker 3: 0.0
From worker 4: 0.0
From worker 5: 0.0
From worker 2: 0.0
https://docs.julialang.org/en/v1/stdlib/Distributed/#Distributed.@everywhere
ps. Welcome, and use the ticks
indicate the code, it is much better (The </>
on the top bar add the correct ticks).
Nice, thanks.
However, would that not make extra local copies of x for all workers? If yes, that would be not-so-good use of the memory.
I don’t think so. Interpolations are not copies, they mean that an expression is passed instead of the value of the variable. But I am not completely sure of how they work, and the references where not clear. Possibly someone else can improve on this explanation.