diff --git a/src/darray.jl b/src/darray.jl index 76ffc50..9150381 100644 --- a/src/darray.jl +++ b/src/darray.jl @@ -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 diff --git a/test/darray.jl b/test/darray.jl index 19d3214..d365b36 100644 --- a/test/darray.jl +++ b/test/darray.jl @@ -62,7 +62,10 @@ using SparseArrays: nnz @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()