BoundsError with SharedArrays in remote node

I want to broadcast a matrix into some remote nodes to avoid communication.

My best guess is to use SharedArrays, but, when I try to copy the data on remote node, I got a error. Here an example:

args = (exeflags=`--threads 2`, topology=:master_worker, enable_threaded_blas=true)
using Distributed; addprocs(4; args...)
machine2 = [("pc2",2)]; addprocs(machine2; dir="/home/pc2", args...)
machine3 = [("pc3",4)]; addprocs(machine3; dir="/home/pc3", args...)
@everywhere using SharedArrays

N = 5
AA = rand(Int64,N,N)

arr_local = SharedArray{Int64, 2}((N,N), pids=[2,3,4,5])
arr_pc2 = SharedArray{Int64, 2}((N,N), pids=[6,7])
arr_pc3 = SharedArray{Int64, 2}((N,N), pids=[8,9,10,11])

arr_local .= AA ## ok
arr_pc2 .= AA ## problems

The error message:

julia> arr_pc2 .= AA
ERROR: BoundsError
 [1] _copyto_impl! at ./array.jl:333 [inlined]
 [2] copyto! at ./array.jl:326 [inlined]
 [3] copyto! at ./array.jl:350 [inlined]
 [4] copyto! at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.5/SharedArrays/src/SharedArrays.jl:587 [inlined]
 [5] copyto! at ./broadcast.jl:927 [inlined]
 [6] copyto! at ./broadcast.jl:886 [inlined]
 [7] materialize! at ./broadcast.jl:848 [inlined]
 [8] materialize!(::SharedArray{Int64,2}, ::Base.Broadcast.Broadcasted{Base.Broadcast.DefaultArrayStyle{2},Nothing,typeof(identity),Tuple{Array{Int64,2}}}) at ./broadcast.jl:845
 [9] top-level scope at REPL[17]:1

For sure I’m missing some basic concept of SharedArrays, because I cannot not even set a single value on remote node:

arr_local[1] # works 
arr_pc2[1] # more bound error
julia> arr_pc2[1]
ERROR: BoundsError: attempt to access 0×0 Array{Int64,2} at index [1]
 [1] getindex at ./array.jl:809 [inlined]
 [2] getindex(::SharedArray{Int64,2}, ::Int64) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.5/SharedArrays/src/SharedArrays.jl:508
 [3] top-level scope at REPL[24]:1

Any help ?

I figure out after some free time + Google. The answer is here.

I had to access the array id inside the remote machine with remotecall_fetch. Here’s the solution

arr_local .= AA ## ok
arr_pc2 .= AA ## problems

for i = 1:N^2
    remotecall_fetch(sharr->sharr.s[i] = AA[i], arr_pc2.pids[1], arr_pc2)

Note about arr_pc2.pids[1]: To setup the process that will write the SharedArray, I just decided that it would be the first in the list, because I hope that at least one process exists.