How to use gnu-parallel for nested loops with internal depending on the external?

I would like to use gnu-parallel to parallelize the next fragment

for a in `seq 5` ; do for b in `seq $a` ; do echo $a $b done done 

Is it possible to achieve something like

 parallel echo {1} {2} ::: $(seq 5) ::: $(seq {1}) 

The syntax above does not work.

Motivation:

I would like to use parallel to send multiple jobs to the cluster, as described here http://docs.rcc.uchicago.edu/software/scheduler/parallel/README.html

+1
source share
1 answer

GNU Parallel can do a Cartesian product. You want half of this (bottom triangle of the product). GNU Parallel cannot do this directly. So you have to skip the upper triangle:

 parallel [ {2} -gt {1} ] '||' echo {1} {2} ::: $(seq 5) ::: $(seq 5) 

For more complex tasks, use $ job-> skip ():

 parallel echo {=1' $arg[2] > $arg[1] and $job->skip();' =} {2} ::: $(seq 5) ::: $(seq 5) 
+1
source

Source: https://habr.com/ru/post/1271932/


All Articles