@@ -88,7 +88,7 @@ function DArray(id::Tuple{Int,Int}, init::I, dims, pids, idxs, cuts) where {I}
8888
8989 if ! allequal (localtypes)
9090 @sync for p in pids
91- @async remotecall_fetch (release_localpart, p, id)
91+ @async remotecall_wait (release_localpart, p, id)
9292 end
9393 throw (ErrorException (lazy " Constructed localparts have different `eltype`: $(localtypes)" ))
9494 end
@@ -136,8 +136,8 @@ function ddata(;T::Type=Any, init::Function=I->nothing, pids=workers(), data::Ve
136136 end
137137 end
138138
139- @sync for i = 1 : length ( pids)
140- @async remotecall_fetch (construct_localparts, pids[i] , init, id, (npids,), pids, idxs, cuts; T= T, A= T)
139+ @sync for p in pids
140+ @async remotecall_wait (construct_localparts, p , init, id, (npids,), pids, idxs, cuts; T= T, A= T)
141141 end
142142
143143 if myid () in pids
@@ -148,9 +148,10 @@ function ddata(;T::Type=Any, init::Function=I->nothing, pids=workers(), data::Ve
148148end
149149
150150function gather (d:: DArray{T,1,T} ) where T
151- a= Array {T} (undef, length (procs (d)))
152- @sync for (i,p) in enumerate (procs (d))
153- @async a[i] = remotecall_fetch (localpart, p, d)
151+ pids = procs (d)
152+ a = Vector {T} (undef, length (pids))
153+ asyncmap! (a, pids) do p
154+ remotecall_fetch (localpart, p, d)
154155 end
155156 a
156157end
@@ -182,12 +183,9 @@ function DArray(refs)
182183 dimdist = size (refs)
183184 id = next_did ()
184185
185- npids = [r. where for r in refs]
186186 nsizes = Array {Tuple} (undef, dimdist)
187- @sync for i in 1 : length (refs)
188- let i= i
189- @async nsizes[i] = remotecall_fetch (sz_localpart_ref, npids[i], refs[i], id)
190- end
187+ asyncmap! (nsizes, refs) do r
188+ remotecall_fetch (sz_localpart_ref, r. where, r, id)
191189 end
192190
193191 nindices = Array {NTuple{length(dimdist),UnitRange{Int}}} (undef, dimdist... )
@@ -210,7 +208,7 @@ function DArray(refs)
210208 ncuts = Array{Int,1 }[pushfirst! (sort (unique (lastidxs[x,:])), 1 ) for x in 1 : length (dimdist)]
211209 ndims = tuple ([sort (unique (lastidxs[x,:]))[end ]- 1 for x in 1 : length (dimdist)]. .. )
212210
213- DArray (id, refs, ndims, reshape (npids, dimdist ), nindices, ncuts)
211+ DArray (id, refs, ndims, map (r -> r . where, refs ), nindices, ncuts)
214212end
215213
216214macro DArray (ex0:: Expr )
@@ -660,8 +658,8 @@ Base.copy(d::SubDArray) = copyto!(similar(d), d)
660658Base. copy (d:: SubDArray{<:Any,2} ) = copyto! (similar (d), d)
661659
662660function Base. copyto! (dest:: SubOrDArray , src:: AbstractArray )
663- asyncmap ( procs (dest)) do p
664- remotecall_fetch (p) do
661+ @sync for p in procs (dest)
662+ @async remotecall_wait (p) do
665663 ldest = localpart (dest)
666664 copyto! (ldest, view (src, localindices (dest)... ))
667665 end
671669
672670function Base. deepcopy (src:: DArray )
673671 dest = similar (src)
674- asyncmap ( procs (src)) do p
675- remotecall_fetch (p) do
672+ @sync for p in procs (src)
673+ @async remotecall_wait (p) do
676674 dest[:L ] = deepcopy (src[:L ])
677675 end
678676 end
@@ -822,13 +820,14 @@ end
822820
823821function Base. fill! (A:: DArray , x)
824822 @sync for p in procs (A)
825- @async remotecall_fetch ((A,x)-> ( fill! (localpart (A), x); nothing ), p, A, x)
823+ @async remotecall_wait ((A,x)-> fill! (localpart (A), x), p, A, x)
826824 end
827825 return A
828826end
829827
830828function Random. rand! (A:: DArray , :: Type{T} ) where T
831- asyncmap ( procs (A)) do p
832- remotecall_wait ((A, T)-> rand! (localpart (A), T), p, A, T)
829+ @sync for p in procs (A)
830+ @async remotecall_wait ((A, T)-> rand! (localpart (A), T), p, A, T)
833831 end
832+ return A
834833end
0 commit comments