Skip to content

Commit

Permalink
Make copy(DArray) copy
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasnoack committed Jan 13, 2015
1 parent 5c6aa0d commit 10a45eb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ Library improvements

* Added `recvfrom` to get source address of UDP packets ([#9418])

* copy(DArray) will now make a copy of the DArray ([#9745])

Deprecated or removed
---------------------

Expand Down
8 changes: 7 additions & 1 deletion base/darray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,13 @@ end
getindex(d::DArray) = d[1]
getindex(d::DArray, I::Union(Int,UnitRange{Int})...) = sub(d,I...)

copy(d::SubOrDArray) = d
function copy!(dest::SubOrDArray, src::SubOrDArray)
dest.dims == src.dims && dest.pmap == src.pmap && dest.indexes == src.indexes && dest.cuts == src.cuts || throw(ArgumentError("destination array doesn't fit to source array"))
for p in dest.pmap
@spawnat p copy!(localpart(dest), localpart(src))
end
dest
end

# local copies are obtained by convert(Array, ) or assigning from
# a SubDArray to a local Array.
Expand Down
6 changes: 6 additions & 0 deletions test/parallel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ id_other = filter(x -> x != id_me, procs())[rand(1:(nprocs()-1))]
@fetch begin myid() end

d = drand((200,200), [id_me, id_other])
dc = copy(d)

@test d == dc # Should be identical
@spawnat workers()[1] localpart(dc)[1] = 0
@test fetch(@spawnat workers()[1] localpart(d)[1] != 0) # but not point to the same memory

s = convert(Matrix{Float64}, d[1:150, 1:150])
a = convert(Matrix{Float64}, d)
@test a[1:150,1:150] == s
Expand Down

0 comments on commit 10a45eb

Please sign in to comment.