Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make copy(DArray) copy #9745

Merged
merged 1 commit into from
Jan 13, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be @spawnat id_other localpart(dc)[1] = 0 and @test fetch(@spawnat id_other localpart(d)[1] != 0) ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is probably true. I'll change it.


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