# Unable to call a distributed array in a parallel subprocess

**URL:** <https://discourse.julialang.org/t/unable-to-call-a-distributed-array-in-a-parallel-subprocess/37131>\
**Category:** General Usage\
**Tags:** parallel, distributed\
**Created:** [April 6, 2020, 10:40pm UTC](https://discourse.julialang.org/t/unable-to-call-a-distributed-array-in-a-parallel-subprocess/37131 "2020-04-06T22:40:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Diego](https://avatars.discourse-cdn.com/v4/letter/d/f04885/32.png) [@Diego](https://discourse.julialang.org/u/Diego)\
**Post date:** [April 6, 2020, 10:40pm UTC](https://discourse.julialang.org/t/unable-to-call-a-distributed-array-in-a-parallel-subprocess/37131/1 "2020-04-06T22:40:13Z")

</div>

Dear Julia team,

I am trying to edit a distributed array from a function running in a separate process.

The problem is that from inside the function the distributed array is not defined (see below).

I have also tried adding “@everywhere” in the declaration of the distributed array, but this only makes Julia freeze and does nothing.

Any suggestion?

Thank you in advance,

* * *

using Distributed  
using DistributedArrays  
addprocs(4)  
@everywhere const listofworkers = fetch(@spawnat 1 workers())  
@everywhere using DistributedArrays

Iter = 10  
Numb = 40

Consider = dzeros((Iter,Numb), listofworkers, [1,size(listofworkers,1)])

@everywhere function Launch(n::Integer)  
for i = 1:100  
Consider.localpart[i,n] = rand()  
end  
end

@time fetch(@spawnat first(listofworkers) Launch(1) )

* * *

The last row returns:

On worker 2:  
**UndefVarError: Consider not defined**  
Launch at C:\Example.jl:14  
#15 at C:\Users\julia\AppData\Local\Julia-1.3.1\share\julia\stdlib\v1.3\Distributed\src\macros.jl:87  
#105 at C:\Users\julia\AppData\Local\Julia-1.3.1\share\julia\stdlib\v1.3\Distributed\src\process\_messages.jl:290  
run\_work\_thunk at C:\Users\julia\AppData\Local\Julia-1.3.1\share\julia\stdlib\v1.3\Distributed\src\process\_messages.jl:79  
run\_work\_thunk at C:\Users\julia\AppData\Local\Julia-1.3.1\share\julia\stdlib\v1.3\Distributed\src\process\_messages.jl:88  
#98 at .\task.jl:333  
#remotecall\_fetch#145 at remotecall.jl:390 [inlined]  
remotecall\_fetch(::Function, ::Distributed.Worker, ::Distributed.RRID) at remotecall.jl:382  
#remotecall\_fetch#148 at remotecall.jl:417 [inlined]  
remotecall\_fetch at remotecall.jl:417 [inlined]  
call\_on\_owner at remotecall.jl:490 [inlined]  
fetch(::Future) at remotecall.jl:529  
top-level scope at util.jl:155

---

<div class="post-metadata">

**Author:** ![jishnub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jishnub/32/33620_2.png) [@jishnub](https://discourse.julialang.org/u/jishnub)\
**Post date:** [April 7, 2020, 7:31am UTC](https://discourse.julialang.org/t/unable-to-call-a-distributed-array-in-a-parallel-subprocess/37131/2 "2020-04-07T07:31:33Z")

</div>

You could try something like this

```julia
julia> @everywhere function Launch(n::Integer,Consider)
       for i = 1:10 # must be in range
       Consider.localpart[i,n] = rand()
       end
       end

julia> @time fetch(@spawnat first(listofworkers) Launch(1,Consider) )
  0.114793 seconds (41.11 k allocations: 2.076 MiB)

```

The idea is that while the array exists in sections everywhere, the reference to it exists only on the master process and needs to be passed on to the workers. Make sure that you’re choosing indices in range. Also try to enclose code that you post in triple ``` quotes to make it easier to view.
