From 966748807cb3074ad82c9214f8072a3ce23acccf Mon Sep 17 00:00:00 2001 From: tan Date: Wed, 16 Apr 2014 09:57:38 +0530 Subject: [PATCH 1/2] reshape for sharedarray --- base/sharedarray.jl | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/base/sharedarray.jl b/base/sharedarray.jl index 755348aca1dc7..af91a0c925b6c 100644 --- a/base/sharedarray.jl +++ b/base/sharedarray.jl @@ -108,6 +108,21 @@ SharedArray(T, I::Int...; kwargs...) = SharedArray(T, I; kwargs...) length(S::SharedArray) = prod(S.dims) size(S::SharedArray) = S.dims +function reshape{T,N}(a::SharedArray{T}, dims::NTuple{N,Int}) + refs = Array(RemoteRef, length(a.pids)) + for (i, p) in enumerate(a.pids) + refs[i] = remotecall(p, (r,d)->reshape(fetch(r),d), a.refs[i], dims) + end + + A = SharedArray{T,N}(dims, a.pids, refs, a.segname) + A.pidx = a.pidx + if A.pidx > 0 + A.s = reshape(a.s, dims) + A.loc_subarr_1d = sub_1dim(A, A.pidx) + end + A +end + procs(S::SharedArray) = S.pids indexpids(S::SharedArray) = S.pidx From a7a5597ef3178da33a8f39f030b51208accb975e Mon Sep 17 00:00:00 2001 From: tan Date: Wed, 16 Apr 2014 14:36:51 +0530 Subject: [PATCH 2/2] - validate dims - set A.s correctly - fix assert_same_host for case when myid() not in pids --- base/sharedarray.jl | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/base/sharedarray.jl b/base/sharedarray.jl index af91a0c925b6c..ccf0808de298b 100644 --- a/base/sharedarray.jl +++ b/base/sharedarray.jl @@ -109,17 +109,15 @@ length(S::SharedArray) = prod(S.dims) size(S::SharedArray) = S.dims function reshape{T,N}(a::SharedArray{T}, dims::NTuple{N,Int}) + (length(a) != prod(dims)) && error("dimensions must be consistent with array size") refs = Array(RemoteRef, length(a.pids)) for (i, p) in enumerate(a.pids) refs[i] = remotecall(p, (r,d)->reshape(fetch(r),d), a.refs[i], dims) end A = SharedArray{T,N}(dims, a.pids, refs, a.segname) - A.pidx = a.pidx - if A.pidx > 0 - A.s = reshape(a.s, dims) - A.loc_subarr_1d = sub_1dim(A, A.pidx) - end + init_loc_flds(A) + (a.pidx == 0) && isdefined(a, :s) && (A.s = reshape(a.s, dims)) A end @@ -350,13 +348,13 @@ end @unix_only shm_open(shm_seg_name, oflags, permissions) = ccall(:shm_open, Int, (Ptr{Uint8}, Int, Int), shm_seg_name, oflags, permissions) -function assert_same_host(procs) - first_privip = getprivipaddr(procs[1]) - if !all(x -> getprivipaddr(x) == first_privip, procs) +function assert_same_host(pids) + first_privip = getprivipaddr(pids[1]) + if !all(x -> getprivipaddr(x) == first_privip, pids) error("SharedArray requires all requested processes to be on the same machine.") end - return myid() in procs + return myid() in procs(pids[1]) end