问题
I would like to use gnu-parallel to parallelize the following snippet
for a in `seq 5` ; do
for b in `seq $a` ; do
echo $a $b
done
done
Is this possible to achieve using something like
parallel echo {1} {2} ::: $(seq 5) ::: $(seq {1})
The above syntax does not work.
Motivation:
I would like to use parallel in order to submit a number of jobs to a cluster, as explained here http://docs.rcc.uchicago.edu/software/scheduler/parallel/README.html
回答1:
GNU Parallel can do the cartesian product. What you want is half of that (the lower triangle of the product). GNU Parallel cannot do that directly. So you will 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)
来源:https://stackoverflow.com/questions/21691813/how-to-use-gnu-parallel-for-nested-loops-with-inner-one-depending-on-the-outer-o