Skip to content

Commit 17b77d7

Browse files
JosephTomlinsonvchuravy
authored andcommitted
Fixes Edge Cases with #167 (#169)
* Fixes Edge Cases with #167
1 parent 24b0b0b commit 17b77d7

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/darray.jl

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,18 @@ end
285285
# get array of start indices for dividing sz into nc chunks
286286
function defaultdist(sz::Int, nc::Int)
287287
if sz >= nc
288-
return ceil.(Int, range(1, stop=sz+1, length=nc+1))
288+
chunk_size = div(sz,nc)
289+
remainder = rem(sz,nc)
290+
grid = zeros(Int64, nc+1)
291+
for i = 1:(nc+1)
292+
grid[i] += (i-1)*chunk_size + 1
293+
if i<= remainder
294+
grid[i] += i-1
295+
else
296+
grid[i] += remainder
297+
end
298+
end
299+
return grid
289300
else
290301
return [[1:(sz+1);]; zeros(Int, nc-sz)]
291302
end

test/darray.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,10 @@ using Random
6363
@test fetch(@spawnat MYID length(localpart(DA)) == 2)
6464
@test fetch(@spawnat OTHERIDS length(localpart(DA)) == 1)
6565
close(DA)
66+
@test DistributedArrays.defaultdist(50,4) == [1,14,27,39,51]
6667
end
68+
69+
6770
end
6871

6972
check_leaks()

0 commit comments

Comments
 (0)