【问题标题】:execute bash files when previous ones have finished to run在之前的文件完成运行时执行 bash 文件
【发布时间】:2020-06-28 08:36:15
【问题描述】:

您好,我需要帮助

实际上我需要执行几个 bash 文件,例如:

file1.sh
file2.sh
file3.sh 
file4.sh 

这些文件将生成用于另一个 bash 文件调用的数据final.sh

因此,为了赢得时间,我想通过以下方式在集群上执行 fileNb.sh 文件 sumultany:

for file in file*.sh; do sbatch $file; done

,然后当所有工作都完成后,我想自动执行final.sh文件。

有人有想法吗?

非常感谢

【问题讨论】:

  • 将最终脚本与其他脚本的依赖关系发送到队列。
  • 你能分享一个脚本来添加依赖选项吗?
  • sbatch -d afterok:$JobID1:$JobID2:$JobIDN final.sh
  • @Poshi 是否可以这样做:sbatch --dependency=afterok:file1.sh:file2.sh:file3.sh final.sh`` ?? Because I get sbatch: 错误:批处理作业提交失败:作业依赖问题```
  • 不,您必须使用工作 ID。

标签: bash jobs execute slurm


【解决方案1】:

一个干净的选项是将作业集重新组织为job array,然后为整个阵列上的最终作业添加dependency

假设fileN.sh 看起来像这样:

#!/bin/bash
#SBATCH --<some option>
#SBATCH --<some other option>

./my_program input_fileN

您可以将其设为作业数组。在单个提交文件file.sh中,写下这个

#!/bin/bash
#SBATCH --<some option>
#SBATCH --<some other option>
#SBATCH --array=1-4

./my_program input_file${SLURM_ARRAY_TASK_ID}

然后运行

JOBID=$(sbatch --parsable file.sh)
sbatch --dependency after:$JOBID final.sh

如果您的作业不能直接用整数参数化,请创建一个 Bash 数组,如下所示:

#!/bin/bash
#SBATCH --<some option>
#SBATCH --<some other option>
#SBATCH --array=0-2

ARGS=(SRR63563 SRR63564 SRR63565)

fasterq-dump --threads 10  ${ARGS[$SLURM_ARRAY_TASK_ID]} -O /path1/path2/path3/

【讨论】:

  • 谢谢,但是如果在每份工作中我有不同的名字而不是从 0 到 3 的数字呢?我该如何处理数组? ,这是我的 fileN 内容的示例:fasterq-dump --threads 10 SRR63563 -O /path1/path2/path3/ ; fasterq-dump --threads 10 SRR63564 -O /path1/path2/path3/ ; fasterq-dump --threads 10 SRR63565 -O /path1/path2/path3/
【解决方案2】:

你可以这样做:

sbatch --wait file1.sh &
sbatch --wait file2.sh &
sbatch --wait file3.sh &
sbatch --wait file4.sh &
wait
sbatch final.sh

或者,更简单的是 GNU Parallel

parallel -j4 sbatch --wait ::: file*.sh
sbatch final.sh

【讨论】:

    【解决方案3】:

    这样不行吗?

    for file in file*.sh; do sbatch $file; done; ./final.sh
    

    【讨论】:

    • OP 希望使用 slurm并行运行初始作业。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多