From 8ccbfdf1c732d26b49a132cf8c1f586bbcad0676 Mon Sep 17 00:00:00 2001 From: Tim Holy Date: Tue, 5 Apr 2016 13:43:51 -0500 Subject: [PATCH] Fix deepcopy for SharedArray --- base/sharedarray.jl | 4 ++-- test/parallel_exec.jl | 11 +++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/base/sharedarray.jl b/base/sharedarray.jl index 36b25ebe7092a4..e15fdc05473f22 100644 --- a/base/sharedarray.jl +++ b/base/sharedarray.jl @@ -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 diff --git a/test/parallel_exec.jl b/test/parallel_exec.jl index c72893cdf34e54..d3709bad251d13 100644 --- a/test/parallel_exec.jl +++ b/test/parallel_exec.jl @@ -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 @@ -841,4 +849,3 @@ end v15406 = remotecall_wait(() -> 1, id_other) fetch(v15406) remotecall_wait(t -> fetch(t), id_other, v15406) -