JuliaLang / Distributed.jl

Create and control multiple Julia processes remotely for distributed computing. Ships as a Julia stdlib.
https://docs.julialang.org/en/v1/stdlib/Distributed/
MIT License
23 stars 9 forks source link

Showing SharedArray objects in a different host causes confusion. #55

Open usefulhyun opened 6 years ago

usefulhyun commented 6 years ago

First, see the code below.

julia> pid = addprocs(["different_hostaddress_from_current"])[1]
julia> sa1 = @fetchfrom pid SharedArray( rand(4, 4) )
4×4 SharedArray{Float64,2}:
sa[ 0.588949  0.0481939  0.266658  0.542195
 0.162783  0.771512   0.812162  0.981772
 0.704765  0.325396   0.656134  0.469057
 0.326197  0.727144   0.696665  0.653014
julia> show(sa1)
[0.588949 0.0481939 0.266658 0.542195; 0.162783 0.771512 0.812162 0.981772; 0.704765 0.325396 0.656134 0.469057; 0.326197 0.727144 0.696665 0.653014]
julia> sa1[1,1]
0.0  # this is a trash value.
julia> sdata(sa)
0×0 Array{Float64,2}
# in reverse
julia> sa2 = SharedArray( (rand(4, 4) )
4×4 SharedArray{Float64,2}:
 0.913975  0.65263   0.388948  0.695337
 0.942663  0.251198  0.233023  0.376158
 0.539025  0.743089  0.612239  0.329394
 0.783334  0.425041  0.67182   0.381703
julia> @fetchfrom pid show(sa2)
julia> @fetchfrom pid println()
From worker 2:  [0.913975 0.65263 0.388948 0.695337; 0.942663 0.251198 0.233023 0.376158; 0.539025 0.743089 0.612239 0.329394; 0.783334 0.425041 0.67182 0.381703]
julia> @fetchfrom pid show(sa2[1,1])
julia> @fetchfrom pid println()
From worker 2:  0.0

I understood the intention. show function is implemented as below
show(io, remotecall_fetch(sharr->sharr.s, S.pids[1], S)) This function actually shows the values in the different computer. But, users may make a mistake that the variable sa in the current node has the values.

I think this should be documented or modified in a different way to avoid mistakes. Because I suffered from this problem.