【发布时间】:2016-12-03 20:07:57
【问题描述】:
我想在 64 核机器上处理 2000 个文件。我有一个 python 脚本 foo.py 我运行如下:
cat file0000.txt|./foo.py > out0000.txt
理想情况下,我会将 2000 个文件 file0000.txt 到 file01999.txt 拆分为 40 个大小为 50 的集合,并在每个集合上并行运行 foo.py。对于 40 组中的第 1 到 4 组,这相当于以下内容:
cat file00[0-4][0-9] |./foo.py > outfile1.txt &
cat file00[5-9][0-9] |./foo.py > outfile2.txt &
cat file01[0-4][0-9] |./foo.py > outfile3.txt &
cat file01[5-9][0-9] |./foo.py > outfile4.txt &
遗憾的是,我运行它的系统没有parallel,所以我必须在没有那个非常有用的工具的情况下执行此操作。
Bash script processing commands in parallel 看起来很相似,但最受欢迎的答案并不直接相关,第二受欢迎的答案使用了我无法访问的 parallel。
【问题讨论】:
-
xargs和-P max-procs选项有什么问题? -
@Alper 这可能是答案,但我从未使用过它。您将如何使用它来解决我的问题?
-
ls -1 | xargs -I{} -P 5 sh -c "cat {} | ./foo.py > out{}.txt"之类的东西,注意:ls -1应该列出您的输入文件并根据需要更改-P 5。 -
你能详细说明你为什么不安装 GNU Parallel 吗?根据oletange.blogspot.dk/2013/04/why-not-install-gnu-parallel.html
-
@OleTange 这是我不允许做的安装部分。我从您非常有用的链接中看到,一种选择是下载它并以普通用户身份运行它:)
标签: bash