It turned out a person has an answer to one of my question: python - Find the list of combination (with repetition) given rank and number of items. (Lexicographic ordering) - Code Review Stack Exchange
Yes, it’s in Python and I used more common language to reduce language barrier. I think I can improve one of my code with this finding.
EDIT: I tested it in G’MIC, and it is correct. I pushed this new algorithm. Now for the multi-threaded filling approach.
Final EDIT: I pushed the multi-threaded filling approach too thanks to this Joseph Wood.
Here are timings for 20,030,010 repeated combinations:
C:\Windows\System32
λ gmic tic +new_rep_r_combinations 20,10 toc
[gmic]./ Start G'MIC interpreter (v.3.3.2).
[gmic]./ Initialize timer.
[gmic]./ Elapsed time: 0.612 s.
[gmic]./ Display image [0] = '[: begin( const n_items=$n_it...'.
[0] = '[: begin( const n_items=$n_items; const max_ind=s-1; const ax...':
size = (20030010,1,1,10) [764.1 Mio of float32].
data = (0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, ... ,19,18,19,19,18,19,19,19,18,19,19,19,19,18,19,19,19,19,19,18,19,19,19,19,19,19,18,19,19,19,19,19,19,19,18,19,19,19,19,19,19,19,19,18,19,19,19,19,19,19,19,19,19,18,19,19,19,19,19,19,19,19,19,19).
min = 0, max = 19, mean = 9.5, std = 5.76628, coords_min = (0,0,0,0), coords_max = (2.003e+07,0,0,0).
[gmic]./ End G'MIC interpreter.
C:\Windows\System32
λ gmic tic +rep_r_combinations 20,10 toc
[gmic]./ Start G'MIC interpreter (v.3.3.2).
[gmic]./ Initialize timer.
[gmic]./ Elapsed time: 1.398 s.
[gmic]./ Display image [0] = '[> begin( const n_items=$n_it...'.
[0] = '[> begin( const n_items=$n_items; const max_ind=s-1; const ax...':
size = (20030010,1,1,10) [764.1 Mio of float32].
data = (0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, ... ,19,18,19,19,18,19,19,19,18,19,19,19,19,18,19,19,19,19,19,18,19,19,19,19,19,19,18,19,19,19,19,19,19,19,18,19,19,19,19,19,19,19,19,18,19,19,19,19,19,19,19,19,19,18,19,19,19,19,19,19,19,19,19,19).
min = 0, max = 19, mean = 9.5, std = 5.76628, coords_min = (0,0,0,0), coords_max = (2.003e+07,0,0,0).
[gmic]./ End G'MIC interpreter.