Skip to content

Commit

Permalink
Merge pull request JuliaParallel#103 from JuliaParallel/anj/copy
Browse files Browse the repository at this point in the history
Allow different chunk sizes in the two arrays in copy!
  • Loading branch information
vchuravy authored Aug 5, 2016
2 parents 23131e2 + 892dd7b commit 3097509
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
12 changes: 4 additions & 8 deletions src/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -551,14 +551,10 @@ Base.getindex(d::DArray) = d[1]
Base.getindex(d::DArray, I::Union{Int,UnitRange{Int},Colon,Vector{Int},StepRange{Int,Int}}...) = view(d, I...)

Base.copy!(dest::SubOrDArray, src::SubOrDArray) = begin
if !(size(dest) == size(src) &&
procs(dest) == procs(src) &&
dest.indexes == src.indexes &&
dest.cuts == src.cuts)
throw(DimensionMismatch("destination array doesn't fit to source array"))
end
@sync for p in procs(dest)
@async remotecall_fetch((dest,src)->(copy!(localpart(dest), localpart(src)); nothing), p, dest, src)
asyncmap(procs(dest)) do p
remotecall_fetch(p) do
localpart(dest)[:] = src[localindexes(dest)...]
end
end
return dest
end
Expand Down
13 changes: 13 additions & 0 deletions test/darray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,19 @@ end

check_leaks()

@testset "copy!" begin
D1 = dzeros((10,10))
r1 = remotecall_wait(() -> randn(3,10), workers()[1])
r2 = remotecall_wait(() -> randn(7,10), workers()[2])
D2 = DArray(reshape([r1; r2], 2, 1))
copy!(D2, D1)
@test D1 == D2
close(D1)
close(D2)
end

check_leaks()

@testset "test DArray reduce" begin
D = DArray(id->fill(myid(), map(length,id)), (10,10), [MYID, OTHERIDS])

Expand Down

0 comments on commit 3097509

Please sign in to comment.