+ indices[(max_nb_per_set*(i-1)+1):(max_per_set*i)] )
+ # Two cases: remainder is >= min_per_set (easy)...
+ if (rem >= min_nb_per_set)
+ indices_workers = c( indices_workers, list(tail(indices,rem)) )
+ #...or < min_per_set: harder, need to remove indices from current sets to feed
+ # the too-small remainder. It may fail: then fallback to "slightly bigger sets"
+ else
+ {
+ save_indices_workers = indices_workers
+ small_set = tail(indices,rem)
+ # Try feeding small_set until it reaches min_per_set, whle keeping the others big enough
+ # Spread the remaining load among the workers