Skip to content

Check that eltype from each shard is consistent #170

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions src/darray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,23 +78,31 @@ Base.hash(d::DArray, h::UInt) = Base.hash(d.id, h)
## core constructors ##

function DArray(id, init, dims, pids, idxs, cuts)
r=Channel(1)
localtypes = Vector{DataType}(undef,length(pids))

@sync begin
for i = 1:length(pids)
@async begin
local typA
if isa(init, Function)
typA=remotecall_fetch(construct_localparts, pids[i], init, id, dims, pids, idxs, cuts)
typA = remotecall_fetch(construct_localparts, pids[i], init, id, dims, pids, idxs, cuts)
else
# constructing from an array of remote refs.
typA=remotecall_fetch(construct_localparts, pids[i], init[i], id, dims, pids, idxs, cuts)
typA = remotecall_fetch(construct_localparts, pids[i], init[i], id, dims, pids, idxs, cuts)
end
!isready(r) && put!(r, typA)
localtypes[i] = typA
end
end
end

A = take!(r)
if length(unique(localtypes)) != 1
@sync for p in pids
@async remotecall_fetch(release_localpart, p, id)
end
throw(ErrorException("Constructed localparts have different `eltype`: $(localtypes)"))
end
A = first(localtypes)

if myid() in pids
d = registry[id]
d = isa(d, WeakRef) ? d.value : d
Expand Down
12 changes: 11 additions & 1 deletion test/darray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,17 @@ using Random
@test DistributedArrays.defaultdist(50,4) == [1,14,27,39,51]
end


@testset "Inhomogenous typeof(localpart)" begin
block = 10
Y = nworkers() * block
X = nworkers() * block

@assert nworkers() > 1
@test_throws ErrorException DArray((X, Y)) do I
eltype = first(CartesianIndices(I)) == CartesianIndex(1, 1) ? Int64 : Float64
zeros(eltype, map(length, I))
end
end
end

check_leaks()
Expand Down