Unable to call a distributed array in a parallel subprocess

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
@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()

@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

You could try something like this

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

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.