Skip to content

Commit

Permalink
Fixes Edge Cases with #167 (#169)
Browse files Browse the repository at this point in the history
* Fixes Edge Cases with #167
  • Loading branch information
JosephTomlinson authored and vchuravy committed Nov 16, 2018
1 parent 24b0b0b commit 17b77d7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/darray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,18 @@ end
# get array of start indices for dividing sz into nc chunks
function defaultdist(sz::Int, nc::Int)
if sz >= nc
return ceil.(Int, range(1, stop=sz+1, length=nc+1))
chunk_size = div(sz,nc)
remainder = rem(sz,nc)
grid = zeros(Int64, nc+1)
for i = 1:(nc+1)
grid[i] += (i-1)*chunk_size + 1
if i<= remainder
grid[i] += i-1
else
grid[i] += remainder
end
end
return grid
else
return [[1:(sz+1);]; zeros(Int, nc-sz)]
end
Expand Down
3 changes: 3 additions & 0 deletions test/darray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ using Random
@test fetch(@spawnat MYID length(localpart(DA)) == 2)
@test fetch(@spawnat OTHERIDS length(localpart(DA)) == 1)
close(DA)
@test DistributedArrays.defaultdist(50,4) == [1,14,27,39,51]
end


end

check_leaks()
Expand Down

0 comments on commit 17b77d7

Please sign in to comment.