@@ -22,7 +22,9 @@ type SharedArray{T,N} <: DenseArray{T,N}
22
22
# a subset of workers.
23
23
loc_subarr_1d:: SubArray{T,1,Array{T,1},Tuple{UnitRange{Int}},true}
24
24
25
- SharedArray (d,p,r,sn) = new (d,p,r,sn)
25
+ function SharedArray (d,p,r,sn,s)
26
+ new (d,p,r,sn,s,0 ,view (Array {T} (ntuple (d-> 0 ,N)), 1 : 0 ))
27
+ end
26
28
end
27
29
28
30
(:: Type{SharedArray{T}} ){T,N}(d:: NTuple{N,Int} ; kwargs... ) =
@@ -58,7 +60,7 @@ function SharedArray(T::Type, dims::NTuple; init=false, pids=Int[])
58
60
pids, onlocalhost = shared_pids (pids)
59
61
60
62
local shm_seg_name = " "
61
- local s
63
+ local s = Array {T} ( ntuple (d -> 0 ,N))
62
64
local S = nothing
63
65
local shmmem_create_pid
64
66
try
@@ -97,8 +99,8 @@ function SharedArray(T::Type, dims::NTuple; init=false, pids=Int[])
97
99
end
98
100
systemerror (" Error unlinking shmem segment " * shm_seg_name, rc != 0 )
99
101
end
100
- S = SharedArray {T,N} (dims, pids, refs, shm_seg_name)
101
- initialize_shared_array (S, s, onlocalhost, init, pids)
102
+ S = SharedArray {T,N} (dims, pids, refs, shm_seg_name, s )
103
+ initialize_shared_array (S, onlocalhost, init, pids)
102
104
shm_seg_name = " "
103
105
104
106
finally
@@ -167,7 +169,7 @@ function SharedArray{T,N}(filename::AbstractString, ::Type{T}, dims::NTuple{N,In
167
169
func_mmap = mode -> open (filename, mode) do io
168
170
Mmap. mmap (io, Array{T,N}, dims, offset; shared= true )
169
171
end
170
- local s
172
+ s = Array {T} ( ntuple (d -> 0 ,N))
171
173
if onlocalhost
172
174
s = func_mmap (mode)
173
175
refs[1 ] = remotecall (pids[1 ]) do
@@ -191,17 +193,14 @@ function SharedArray{T,N}(filename::AbstractString, ::Type{T}, dims::NTuple{N,In
191
193
wait (ref)
192
194
end
193
195
194
- S = SharedArray {T,N} (dims, pids, refs, filename)
195
- initialize_shared_array (S, s, onlocalhost, init, pids)
196
+ S = SharedArray {T,N} (dims, pids, refs, filename, s )
197
+ initialize_shared_array (S, onlocalhost, init, pids)
196
198
S
197
199
end
198
200
199
- function initialize_shared_array (S, s, onlocalhost, init, pids)
201
+ function initialize_shared_array (S, onlocalhost, init, pids)
200
202
if onlocalhost
201
203
init_loc_flds (S)
202
- # In the event that myid() is not part of pids, s will not be set
203
- # in the init function above, hence setting it here if available.
204
- S. s = s
205
204
else
206
205
S. pidx = 0
207
206
end
@@ -248,9 +247,8 @@ function reshape{T,N}(a::SharedArray{T}, dims::NTuple{N,Int})
248
247
end
249
248
end
250
249
251
- A = SharedArray {T,N} (dims, a. pids, refs, a. segname)
250
+ A = SharedArray {T,N} (dims, a. pids, refs, a. segname, reshape (a . s, dims) )
252
251
init_loc_flds (A)
253
- (a. pidx == 0 ) && isdefined (a, :s ) && (A. s = reshape (a. s, dims))
254
252
A
255
253
end
256
254
0 commit comments