@@ -451,15 +451,15 @@ function fill!(S::SharedArray, v)
451
451
end
452
452
453
453
function 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)
455
455
@sync for p in procs (S)
456
456
@async remotecall_wait (f, p, S)
457
457
end
458
458
return S
459
459
end
460
460
461
461
function 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)
463
463
@sync for p in procs (S)
464
464
@async remotecall_wait (f, p, S)
465
465
end
@@ -475,9 +475,9 @@ shmem_fill(v, I::Int...; kwargs...) = shmem_fill(v, I; kwargs...)
475
475
# rand variant with range
476
476
function shmem_rand (TR:: Union{DataType, UnitRange} , dims; kwargs... )
477
477
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... )
479
479
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... )
481
481
end
482
482
end
483
483
shmem_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...)
487
487
shmem_rand (I:: Int... ; kwargs... ) = shmem_rand (I; kwargs... )
488
488
489
489
function 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... )
491
491
end
492
492
shmem_randn (I:: Int... ; kwargs... ) = shmem_randn (I; kwargs... )
493
493
@@ -501,11 +501,14 @@ reduce(f, S::SharedArray) =
501
501
Any[ @spawnat p reduce (f, S. loc_subarr_1d) for p in procs (S) ])
502
502
503
503
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
505
508
@sync for p in procs (S)
506
509
@spawnat p begin
507
510
for idx in localindexes (S)
508
- S. s[idx] = f (S . s[idx])
511
+ S. s[idx] = f (Q . s[idx])
509
512
end
510
513
end
511
514
end
0 commit comments