彼此独立地运行并行 bash 命令
我有一个由 40 个 nproc 组成的集群,其中我的软件一次使用 10 个核心。 我想从单个 bash 脚本一次运行 4 个任务(作业脚本),每当一个任务完成时,就启动另一个任务。循环需要根据输入文件(大约 600)运行。 每个命令在其特定文件夹中执行 n 次。
目前,我正在使用以下脚本
#! /bin/bash
for f in lib1/*.png; do
for g in lib2/*.png; do
for h in lib3/*.png; do
for i in lib4/*.png; do
./MySoftyware --input $f --out $f_out.png &
P1=$!
./MySoftyware --input $g --out $g_out.png &
P2=$!
./MySoftyware --input $h --out $h_out.png &
P3=$!
./MySoftyware --input $i --out $i_out.png &
P4=$!
wait $P1 $P2 $P3 $P4
done
done
done
done
问题是该进程仅在所有四个命令完成后才再次启动,但我希望它在四个命令中的一个命令完成后立即在下一个可用文件上执行。 例如,如果$f在$i之前完成,它应该执行$f中的下一个文件,而不是等待$i完成
I have a cluster of 40 nproc where my software uses ten cores at a time. I want to run 4 task at a time from single bash script (job script), and whenever one completes it, start another one. The loop needs to run as per the input files (approx 600).
Each command executes in its specific folder for n times.
currently, I am using the following script
#! /bin/bash
for f in lib1/*.png; do
for g in lib2/*.png; do
for h in lib3/*.png; do
for i in lib4/*.png; do
./MySoftyware --input $f --out $f_out.png &
P1=$!
./MySoftyware --input $g --out $g_out.png &
P2=$!
./MySoftyware --input $h --out $h_out.png &
P3=$!
./MySoftyware --input $i --out $i_out.png &
P4=$!
wait $P1 $P2 $P3 $P4
done
done
done
done
The issue is that process only starts again when all four are completed, but I want it to execute on its next available file as soon as one is completed from the four commands.
e.g., if $f is completed before $i, it should execute the next file in $f and not wait for the completion of $i
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论