Skip to content

Commit

Permalink
Fix deepcopy for SharedArray
Browse files Browse the repository at this point in the history
  • Loading branch information
timholy committed Apr 5, 2016
1 parent 10d0593 commit 8ccbfdf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
4 changes: 2 additions & 2 deletions base/sharedarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,8 @@ convert{TS,TA,N}(::Type{SharedArray{TS,N}}, A::Array{TA,N}) = (S = SharedArray(T

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)
R = SharedArray(eltype(S), size(S); pids = S.pids)
copy!(sdata(R), sdata(S))
stackdict[S] = R
return R
end
Expand Down
11 changes: 9 additions & 2 deletions test/parallel_exec.jl
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,15 @@ pids_d = procs(d)
remotecall_fetch(setindex!, pids_d[findfirst(id->(id != myid()), pids_d)], d, 1.0, 1:10)
@test ds != d
@test s != d

copy!(d, s)
@everywhere setid!(A) = A[localindexes(A)] = myid()
@sync for p in procs(ds)
@async remotecall_wait(setid!, p, ds)
end
@test d == s
@test ds != s
@test first(ds) == first(procs(ds))
@test last(ds) == last(procs(ds))

# SharedArray as an array
# Since the data in d will depend on the nprocs, just test that these operations work
Expand Down Expand Up @@ -841,4 +849,3 @@ end
v15406 = remotecall_wait(() -> 1, id_other)
fetch(v15406)
remotecall_wait(t -> fetch(t), id_other, v15406)

0 comments on commit 8ccbfdf

Please sign in to comment.