Skip to content

Commit 3097509

Browse files
authored
Merge pull request #103 from JuliaParallel/anj/copy
Allow different chunk sizes in the two arrays in copy!
2 parents 23131e2 + 892dd7b commit 3097509

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

src/core.jl

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -551,14 +551,10 @@ Base.getindex(d::DArray) = d[1]
551551
Base.getindex(d::DArray, I::Union{Int,UnitRange{Int},Colon,Vector{Int},StepRange{Int,Int}}...) = view(d, I...)
552552

553553
Base.copy!(dest::SubOrDArray, src::SubOrDArray) = begin
554-
if !(size(dest) == size(src) &&
555-
procs(dest) == procs(src) &&
556-
dest.indexes == src.indexes &&
557-
dest.cuts == src.cuts)
558-
throw(DimensionMismatch("destination array doesn't fit to source array"))
559-
end
560-
@sync for p in procs(dest)
561-
@async remotecall_fetch((dest,src)->(copy!(localpart(dest), localpart(src)); nothing), p, dest, src)
554+
asyncmap(procs(dest)) do p
555+
remotecall_fetch(p) do
556+
localpart(dest)[:] = src[localindexes(dest)...]
557+
end
562558
end
563559
return dest
564560
end

test/darray.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,19 @@ end
154154

155155
check_leaks()
156156

157+
@testset "copy!" begin
158+
D1 = dzeros((10,10))
159+
r1 = remotecall_wait(() -> randn(3,10), workers()[1])
160+
r2 = remotecall_wait(() -> randn(7,10), workers()[2])
161+
D2 = DArray(reshape([r1; r2], 2, 1))
162+
copy!(D2, D1)
163+
@test D1 == D2
164+
close(D1)
165+
close(D2)
166+
end
167+
168+
check_leaks()
169+
157170
@testset "test DArray reduce" begin
158171
D = DArray(id->fill(myid(), map(length,id)), (10,10), [MYID, OTHERIDS])
159172

0 commit comments

Comments
 (0)