Skip to content

Commit

Permalink
Merge pull request #6535 from tanmaykm/sharedarray
Browse files Browse the repository at this point in the history
reshape for sharedarray
  • Loading branch information
tanmaykm committed Apr 17, 2014
2 parents 78aafbd + a7a5597 commit 53ac944
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions base/sharedarray.jl
Expand Up @@ -108,6 +108,19 @@ 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})
(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)
init_loc_flds(A)
(a.pidx == 0) && isdefined(a, :s) && (A.s = reshape(a.s, dims))
A
end

procs(S::SharedArray) = S.pids
indexpids(S::SharedArray) = S.pidx

Expand Down Expand Up @@ -335,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


0 comments on commit 53ac944

Please sign in to comment.