Skip to content

Commit

Permalink
Fix #6362 (deepcopy broken for SharedArrays)
Browse files Browse the repository at this point in the history
  • Loading branch information
carlobaldassi committed Apr 1, 2014
1 parent 39f0120 commit beb4398
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
8 changes: 8 additions & 0 deletions base/sharedarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,14 @@ convert(::Type{SharedArray}, A::Array) = (S = SharedArray(eltype(A), size(A)); c
convert{T}(::Type{SharedArray{T}}, A::Array) = (S = SharedArray(T, size(A)); copy!(S, A))
convert{TS,TA,N}(::Type{SharedArray{TS,N}}, A::Array{TA,N}) = (S = SharedArray(TS, size(A)); copy!(S, A))

function deepcopy_internal(S::SharedArray, stackdict::ObjectIdDict)
haskey(stackdict, S) && return stackdict[S]
# Note: copy can be used here because SharedArrays are restricted to isbits types
R = copy(S)
stackdict[S] = R
return R
end

function range_1dim(S::SharedArray, pidx)
l = length(S)
nw = length(S.pids)
Expand Down
10 changes: 10 additions & 0 deletions test/parallel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,16 @@ for p in procs(d)
@test d[idxl] == p
end

# issue #6362
d = Base.shmem_rand(dims)
s = copy(sdata(d))
ds = deepcopy(d)
@test ds == d
remotecall_fetch(findfirst(id->(id != myid()), procs(ds)), setindex!, ds, 1.0, 1:10)
@test ds != d
@test s == d


# SharedArray as an array
# Since the data in d will depend on the nprocs, just test that these operations work
a = d[1:5]
Expand Down

0 comments on commit beb4398

Please sign in to comment.