Search code examples
parallel-processinggnucombinatoricsgnu-parallel

GNU-parallel combinatorics, as command-inputs, without printing to terminal


I have two groups of numbers that I would like to create commands from; {37..43} and {37..43}. I would like the commands to take in a number from group_1 and group_2 such that the number from group_2 is always larger than the number from group_1. (i.e. all combinations of the two numbers without repeats: 37-38, 37-39 ... 42-43.)

I desire an output for each command to be of the general form (if you're familiar, a la GROMACS inputs):

parallel "echo -ne 'lipsumlipsum {1} \n lipsumlipsum {2} \n' | lipsumlipsumlipsum" ::: {37..43} ::: {37..43}.

The command parallel echo {= 'if($arg[1] >= $arg[2]) { skip() }' =} ::: {37..43} ::: {37..43} prints to terminal each pair I desire -- however; I do not know how to prevent it from printing each pair to the terminal, and instead input $arg[1] and $arg[2] to their respective holders ({}) within my command.

i) I don't know how to suppress the immediate printing to terminal. ii) I don't know where to place this exclusion criteria within my template code to be applicable to each serial command.

I would like to learn how to do it with the above syntax, rather than 'for-looping' through each sequence with the exclusion i > j, for i,j in {37..43}.

Thank you.


Solution

  • You are so close:

    parallel echo arg1: {=1 'if($arg[1] >= $arg[2]) { skip() }' =} arg2: {2} ::: {37..43} ::: {37..43}
    

    --filter (version >= 20210222) makes this more readable:

    parallel --filter '{1} < {2}' echo arg1: {1} arg2: {2} ::: {37..43} ::: {37..43}
    

    If you are really doing 'n choose k' then:

    parallel --plus echo arg1: {1choose_k} arg2: {2choose_k} ::: {37..43} ::: {37..43}