Distributed.jl icon indicating copy to clipboard operation
Distributed.jl copied to clipboard

global constant not automatically transferred along with function call

Open pmcvay opened this issue 5 years ago • 0 comments

After creating a shared array available to all processees, the array is unavailable unless a fetchfrom is called first. Here is a simple example demonstrating it. (Note, I run it with julia -p 4 test.jl which is why Distributed isn't loaded)

@everywhere using SharedArrays

const arr = SharedArray{Int64, 2}((5,5))

for i in 1:5
    arr[i, :] = fill(i, 5)
end

@everywhere function test()
    arr[myid(), myid()] = 10
    return arr[myid(), :]
end 

println(remotecall_fetch(test, 2)) # doesn't work, throws err arr is undefined
@fetchfrom 2 arr
println(remotecall_fetch(test, 2)) # works now
println(remotecall_fetch(test, 3)) # still doesn't work on this worker unless a fetchfrom is called for this processor too
println(arr)

The arrays I'm using are quite big and so running a fetchfrom for each running worker is not very efficient

pmcvay avatar Apr 04 '20 16:04 pmcvay