I have a list of length N, and I have M workers.  I want each of my workers to independently select a contiguous section of the list, with the property that every element of my list is selected by exactly one worker.Using the SQL notion of offset and limit, I have an approximation:offset = (worker_number / total_workers * list_length).to_ilimit = list_length / total_workers + 1The problem is that, for some values of N and M, this results in overlaps, where some elements are processed multiple times.Is there a general solution that ensures the one-to-one correspondence between elements and workers, yet allows each worker to independently compute their offset and limit?
Creating a one-to-one mapping between a N-length list and M workers?
algorithms
Sure.  Give the $i$th worker the range of items at indices from $\lfloor Ni/M \rfloor$ to $\lfloor N(i+1)/M \rfloor - 1$.Here I assume indices range from $0$ to $N-1$, and workers are indexed by $i$, where $i$ ranges from $0$ to $M-1$.  Also, the notation $\lfloor x \rfloor$ represents the result of rounding $x$ down to the nearest integer.This ensures that there are no overlaps, and the list is split evenly among the workers (as evenly as possible: each worker receives either $\lfloor N/M \rfloor$ items or $\lfloor N/M \rfloor + 1$ items).