# All workers not have access to a sharedarray

**URL:** <https://discourse.julialang.org/t/all-workers-not-have-access-to-a-sharedarray/50834>\
**Category:** New to Julia\
**Tags:** question, parallel, sharedarrays\
**Created:** [November 26, 2020, 8:06pm UTC](https://discourse.julialang.org/t/all-workers-not-have-access-to-a-sharedarray/50834 "2020-11-26T20:06:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ankit13](https://avatars.discourse-cdn.com/v4/letter/a/67e7ee/32.png) [@ankit13](https://discourse.julialang.org/u/ankit13)\
**Post date:** [November 26, 2020, 8:06pm UTC](https://discourse.julialang.org/t/all-workers-not-have-access-to-a-sharedarray/50834/1 "2020-11-26T20:06:35Z")

</div>

Hi,  
I get an error that x is not defined on worker 2/others when I run this.

```julia
using Distributed
addprocs(4)

@everywhere using SharedArrays

x = zero( SharedArray{Float64}( 10 ) );

@everywhere println( x[2] )

```

What is wrong here?  
Thanks

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [November 26, 2020, 8:29pm UTC](https://discourse.julialang.org/t/all-workers-not-have-access-to-a-sharedarray/50834/2 "2020-11-26T20:29:59Z")

</div>

It seems, from the docs, that you have to interpolate x to all procs before using it:

```julia
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](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).

---

<div class="post-metadata">

**Author:** ![ankit13](https://avatars.discourse-cdn.com/v4/letter/a/67e7ee/32.png) [@ankit13](https://discourse.julialang.org/u/ankit13)\
**Post date:** [November 26, 2020, 8:45pm UTC](https://discourse.julialang.org/t/all-workers-not-have-access-to-a-sharedarray/50834/3 "2020-11-26T20:45:48Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [November 26, 2020, 10:24pm UTC](https://discourse.julialang.org/t/all-workers-not-have-access-to-a-sharedarray/50834/4 "2020-11-26T22:24:26Z")

</div>

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.
