Iterating Over Partitions

Suppose we have \(t\) threads to use and \(i\) total items to process. We may want to partition our total items to be processed into \(i / t\) batches so each batch is handled individually by a single thread.

More concretely, suppose that we have 4 threads and need to process 1000 items. Each batch contains 250 items. With 1-indexing, we want our partitions to run from 1 to 250, 251 to 500, 501 to 750, and 751 to 1000.

threadcount = Threads.nthreads()
items = 10_000
batchsize = Int(items/threadcount)

for t in 1:threadcount
    from = batchsize*(t-1)+1
    to   = batchsize*(t)
    println(from, " ", to)
end

> 1-2500
> 2501-5000
> 5001-7500
> 7501-10000