我有两个有不同建议的程序,它们的调用方式如下:
./FolderCounter <PATH TO FOLDER> traceX
./VideoCounter <PATH TO VIDEO> traceY
运行这些应用程序我使用GNU parallel实现以下命令:
parallel ./FolderCounter {} trace3 ::: $(cat PatinN_files.txt) &> data_output/Result_PatinN_files.txt
parallel ./FolderCounter {} trace5 ::: $(cat PatinS_files.txt) &> data_output/Result_PatinS_files.txt
parallel ./VideoCounter {} trace3 ::: $(cat PatinN_videos.txt) &> data_output/Result_PatinN_video.txt
parallel ./VideoCounter {} trace5 ::: $(cat PatinS_videos.txt) &> data_output/Result_PatinS_video.txt
我的目标是将这四行合并为一个GNU并行命令,这样一旦有可用的处理器,它就可以更好地管理并行作业的数量并启动下一批文件。
我该怎么做?
答案 0 :(得分:1)
首先:不要这样做:
parallel ... ::: $(cat foo)
执行:
parallel ... :::: foo
在大多数情况下,这会做你想要的,而第一种可能会导致问题,如果它包含带空格的行。
我认为PatinN_files.txt与PatinN_videos.txt具有相同的行数。
通常情况下,我会进行2次运行:trace3-run和trace5 run:
parallel ./FolderCounter {1} trace3 ";" ./VideoCounter {2} trace3 ::::+ PatinN_files.txt PatinN_videos.txt &> data_output/Result_PatinN.txt
parallel ./FolderCounter {1} trace5 ";" ./VideoCounter {2} trace5 ::::+ PatinS_files.txt PatinS_videos.txt &> data_output/Result_PatinS.txt
或者你可以简单地使用GNU Parallel来生成所有要运行的命令,然后运行它们(这不需要txt文件具有相同的行数):
(
parallel --dry-run ./FolderCounter {} trace3 :::: PatinN_files.txt
parallel --dry-run ./FolderCounter {} trace5 :::: PatinS_files.txt
parallel --dry-run ./VideoCounter {} trace3 :::: PatinN_videos.txt
parallel --dry-run ./VideoCounter {} trace5 :::: PatinS_videos.txt
) | parallel &> data_output/Result.txt
要跟踪哪个输入生成了哪个输出,请使用:
) | parallel --tag &> data_output/Result.txt
要将日志输出分成4个不同的文件会有点困难。如果真的需要它可以做到,但不如上面那么优雅。
如果您只是想在空闲时备用cpus来运行作业,可以使用--load 100%
:
parallel --load 100% ./FolderCounter {} trace3 ::: $(cat PatinN_files.txt) &> data_output/Result_PatinN_files.txt &
parallel --load 100% ./FolderCounter {} trace5 ::: $(cat PatinS_files.txt) &> data_output/Result_PatinS_files.txt &
parallel --load 100% ./VideoCounter {} trace3 ::: $(cat PatinN_videos.txt) &> data_output/Result_PatinN_video.txt &
parallel --load 100% ./VideoCounter {} trace5 ::: $(cat PatinS_videos.txt) &> data_output/Result_PatinS_video.txt &
wait
如果即时负载小于cpu的数量,它将开始工作。