GNU Parallel | 管道命令

3

我完全不懂如何使用GNUparallel,希望你能就以下命令的运行向我提供建议:

/home/admin/Gfinal/decoder/decdr.pl --gh --w14b /data/tmp/KRX12/a.bin | 
perl  /home/admin/decout/decoder/flow.pl >> /data/tmp/decodedgfile/out_1.txt

我将在一个文件列表 (.bin) 上运行这个命令,那么使用 GNU parallel 实现最佳(最快)方法是什么?需要注意的是,命令的第一部分输出 (/home/admin/Gfinal/decoder/decdr.pl --gh --w14b) 非常大 (> 2 GB)。

非常感谢您的帮助。

2个回答

4
这个会起作用吗:
parallel /home/admin/Gfinal/decoder/decdr.pl --gh --w14b {} '|' perl  /home/admin/decout/decoder/flow.pl >> /data/tmp/decodedgfile/out_1.txt ::: /data/tmp/KRX12/*.bin

(如果 flow.pl 的输出超出了您的磁盘 I/O 处理能力,请尝试使用 parallel --compress 命令)。

或者:

parallel /home/admin/Gfinal/decoder/decdr.pl --gh --w14b {} '|' perl  /home/admin/decout/decoder/flow.pl '>>' /data/tmp/decodedgfile/out_{#}.txt ::: /data/tmp/KRX12/*.bin

这取决于您是想要单个输出文件还是每个输入文件一个输出文件。

此外,花一个小时走一遍教程。您的命令行将感激不尽。 man parallel_tutorial


非常感谢您的回答,真的很感激您的工作。还有一个问题,使用 ( /home/admin/Gfinal/decoder/decdr.pl --gh --w14b ) 后面加上 --pipe 会使进程更快吗? - Helmy
不理解,但尝试并衡量。 - Ole Tange

0

这里有一些关于gnu-parallel / parallel的好视频

参考 YouTube 第1部分:GNU Parallel脚本处理和执行

这是GNU网站上提供平台特定信息的链接。

参考 gnu parallel下载信息

“多个输入源

GNU parallel可以接受在命令行上给出的多个输入源。GNU parallel然后生成所有输入源的组合:

parallel echo ::: A B C ::: D E F

输出(顺序可能不同):

A D

A E

A F

B D

B E ............

输入源可以是文件:

parallel -a abc-file -a def-file echo"

参考 GNU-Parallel-Tutorial

关于管道的参考

Pipe capacity A pipe has a limited capacity. If the pipe is full, then a write(2) will block or fail, depending on whether the O_NONBLOCK flag is set (see below). Different implementations have different limits for the pipe capacity. Applications should not rely on a particular capacity: an application should be designed so that a reading process consumes data as soon as it is available, so that a writing process does not remain blocked.

  In Linux versions before 2.6.11, the capacity of a pipe was the same
   as the system page size (e.g., 4096 bytes on i386).  Since Linux
   2.6.11, the pipe capacity is 65536 bytes.  Since Linux 2.6.35, the
   default pipe capacity is 65536 bytes, but the capacity can be queried
   and set using the fcntl(2) F_GETPIPE_SZ and F_SETPIPE_SZ operations.
   See fcntl(2) for more information.

PIPE_BUF POSIX.1 says that write(2)s of less than PIPE_BUF bytes must be atomic: the output data is written to the pipe as a contiguous sequence. Writes of more than PIPE_BUF bytes may be nonatomic: the kernel may interleave the data with data written by other processes. POSIX.1 requires PIPE_BUF to be at least 512 bytes. (On Linux, PIPE_BUF is 4096 bytes.) The precise semantics depend on whether the file descriptor is nonblocking (O_NONBLOCK), whether there are multiple writers to the pipe, and on n, the number of bytes to be written:

参考 man7.org pipe

你可以查看 fcntl 的 F_GETPIPE_SZ 和 F_SETPIPE_SZ 操作,获取更多信息。

参考 fcntl

祝一切顺利!


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接