@@ -451,15 +451,15 @@ function fill!(S::SharedArray, v)
451451end
452452
453453function rand! {T} (S:: SharedArray{T} )
454- f = S-> map! (x-> rand (T), S. loc_subarr_1d)
454+ f = S-> map! (x -> rand (T), S . loc_subarr_1d , S. loc_subarr_1d)
455455 @sync for p in procs (S)
456456 @async remotecall_wait (f, p, S)
457457 end
458458 return S
459459end
460460
461461function randn! (S:: SharedArray )
462- f = S-> map! (x-> randn (), S. loc_subarr_1d)
462+ f = S-> map! (x -> randn (), S . loc_subarr_1d , S. loc_subarr_1d)
463463 @sync for p in procs (S)
464464 @async remotecall_wait (f, p, S)
465465 end
@@ -475,9 +475,9 @@ shmem_fill(v, I::Int...; kwargs...) = shmem_fill(v, I; kwargs...)
475475# rand variant with range
476476function shmem_rand (TR:: Union{DataType, UnitRange} , dims; kwargs... )
477477 if isa (TR, UnitRange)
478- SharedArray (Int, dims; init = S -> map! ((x) -> rand (TR), S. loc_subarr_1d), kwargs... )
478+ SharedArray (Int, dims; init = S -> map! (x -> rand (TR), S . loc_subarr_1d , S. loc_subarr_1d), kwargs... )
479479 else
480- SharedArray (TR, dims; init = S -> map! ((x) -> rand (TR), S. loc_subarr_1d), kwargs... )
480+ SharedArray (TR, dims; init = S -> map! (x -> rand (TR), S . loc_subarr_1d , S. loc_subarr_1d), kwargs... )
481481 end
482482end
483483shmem_rand (TR:: Union{DataType, UnitRange} , i:: Int ; kwargs... ) = shmem_rand (TR, (i,); kwargs... )
@@ -487,7 +487,7 @@ shmem_rand(dims; kwargs...) = shmem_rand(Float64, dims; kwargs...)
487487shmem_rand (I:: Int... ; kwargs... ) = shmem_rand (I; kwargs... )
488488
489489function shmem_randn (dims; kwargs... )
490- SharedArray (Float64, dims; init = S-> map! ((x) -> randn (), S. loc_subarr_1d), kwargs... )
490+ SharedArray (Float64, dims; init = S-> map! (x -> randn (), S . loc_subarr_1d , S. loc_subarr_1d), kwargs... )
491491end
492492shmem_randn (I:: Int... ; kwargs... ) = shmem_randn (I; kwargs... )
493493
@@ -501,11 +501,14 @@ reduce(f, S::SharedArray) =
501501 Any[ @spawnat p reduce (f, S. loc_subarr_1d) for p in procs (S) ])
502502
503503
504- function map! (f, S:: SharedArray )
504+ function map! (f, S:: SharedArray , Q:: SharedArray )
505+ if ! (S === Q) && (procs (S) != procs (Q) || localindexes (S) != localindexes (Q))
506+ throw (ArgumentError (" incompatible source and destination arguments" ))
507+ end
505508 @sync for p in procs (S)
506509 @spawnat p begin
507510 for idx in localindexes (S)
508- S. s[idx] = f (S . s[idx])
511+ S. s[idx] = f (Q . s[idx])
509512 end
510513 end
511514 end
0 commit comments