【问题标题】:gnu parallel: combined use of --pipe and argsgnu 并行:结合使用 --pipe 和 args
【发布时间】:2019-01-09 17:52:21
【问题描述】:

使用--pipe -N<int> 我可以发送给定数量的行作为parallel 启动的作业的输入。但是,我如何才能在每个块上使用 ::: 给出的不同参数运行多个作业?

让我们来看看这个小输入文件:

A   B   C
D   E   F
G   H   I
J   K   L

此外,让我们将每两行定义为一个parallel 作业。并且在它们上执行命令cut -f<int> 应该使用列号作为并行输入参数,例如::: {1..3}

因此对于给定的示例,输出将如下所示

A
D
B
E
C
F
G
J
H
K
I
L

我试过这个命令:

cat input.txt|parallel --pipe -N2 'cut -f{1}' ::: {1..3}

但是输出是这样的:

A
D
I
L

我错过了什么?

脚蹼

【问题讨论】:

    标签: bash gnu-parallel


    【解决方案1】:

    这个:

    cat input.txt|parallel --pipe -N2 'cut -f{1}' ::: {1..3}
    

    从每个输入源读取 2 条记录。如果你这样做会更清楚:

    $ cat input.txt|parallel --pipe -v -N2 'cut -f{}' ::: {1..3}
    cut -f1  -f2
    cut: only one type of list may be specified
    Try 'cut --help' for more information.
    cut -f3
    I
    L
    

    GNU Parallel 将每个参数与一个块配对。您正在寻找的更像是--tee,其中每个块都发送到每个命令。但是,--tee 不会将输入分成块,而是将所有输入发送到命令。所以也许我们可以将两者结合起来:

    doit() { parallel --pipe -N2 -v cut -f$@; }
    export -f doit
    cat input.txt|parallel --pipe --tee -v doit {} ::: {1..3}
    

    或者你可以翻转顺序(这可能效率较低):

    doit() { parallel -v --pipe --tee cut -f{} ::: {1..3}; }
    export -f doit
    cat input.txt|parallel --pipe -N2 -v doit
    

    如果您对正在运行的内容感到满意,请删除 -v

    --tee 非常高效(--pipe 为 1-2 GBytes/s,--pipepart 为 2-3 GBytes/s),但它的缺点是它并行启动所有作业:所以如果你而不是 {1..3} 有 10000 个值,那么它将启动 10000 个进程。

    【讨论】:

    • 您好 Ole,感谢您的详细回答。下周我会和它一起玩。
    猜你喜欢
    • 2021-12-02
    • 2022-06-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-28
    • 2012-04-05
    • 1970-01-01
    • 2013-02-15
    相关资源
    最近更新 更多