I know that I can use "parallel" to run multiple instances of whatever script/application in parallel over a variable with a given increment, eg:
我知道我可以使用“parallel”在具有给定增量的变量上并行运行任何脚本/应用程序的多个实例,例如:
parallel "echo hello {}" ::: {1..16..2}
Output would be:
输出将是:
hello 1
hello 3
hello 5
hello 7
hello 9
hello 11
hello 13
hello 15
I want to use an increment that multiplies the run variable so that I get an output like this:
我想使用一个与run变量相乘的增量,以便得到如下输出:
hello 1
hello 2
hello 4
hello 8
hello 16
What should I write in the {1..16..#}?
我应该在{1..16 ..#}写什么?
Thanks!
谢谢!
2 个解决方案
#1
1
Try this:
尝试这个:
parallel "echo hello {}" ::: $(awk 'BEGIN {for(i=0; i<=16; i++) printf 2**i" "}')
awk
is used to print out a list of powers of 2 which will then be used by parallel
.
awk用于打印出2的幂列表,然后并行使用。
Alternatively:
或者:
parallel "echo hello {}" ::: $(printf '%s\n' 2^{0..16} | bc | tr '\n' ' ')
This prints out the numbers 1 to 16 as part of the string x^2
, printf
ensures each number is on a separate line. bc
then computes the actual numbers, and tr
removes the newlines again.
这打印出数字1到16作为字符串x ^ 2的一部分,printf确保每个数字在一个单独的行上。 bc然后计算实际数字,tr再次删除换行符。
#2
1
Use {= =} (available in version 20140822 and later):
使用{= =}(在20140822及更高版本中可用):
seq 1 2 16 | parallel echo hello {}
parallel echo hello '{= $_=2*$_ =}' ::: {1..16}
seq 1 16 | parallel echo hello '{= $_=2**$_ =}'
parallel echo hello '{= $_=2**$_ =}' ::: {1..16}
#1
1
Try this:
尝试这个:
parallel "echo hello {}" ::: $(awk 'BEGIN {for(i=0; i<=16; i++) printf 2**i" "}')
awk
is used to print out a list of powers of 2 which will then be used by parallel
.
awk用于打印出2的幂列表,然后并行使用。
Alternatively:
或者:
parallel "echo hello {}" ::: $(printf '%s\n' 2^{0..16} | bc | tr '\n' ' ')
This prints out the numbers 1 to 16 as part of the string x^2
, printf
ensures each number is on a separate line. bc
then computes the actual numbers, and tr
removes the newlines again.
这打印出数字1到16作为字符串x ^ 2的一部分,printf确保每个数字在一个单独的行上。 bc然后计算实际数字,tr再次删除换行符。
#2
1
Use {= =} (available in version 20140822 and later):
使用{= =}(在20140822及更高版本中可用):
seq 1 2 16 | parallel echo hello {}
parallel echo hello '{= $_=2*$_ =}' ::: {1..16}
seq 1 16 | parallel echo hello '{= $_=2**$_ =}'
parallel echo hello '{= $_=2**$_ =}' ::: {1..16}