有没有类似于LSF的"一行代码"可以提交多个作业到SLURM?

9

我可以向SLURM提交"一行代码"吗?

使用来自LSF的bsub和标准的Linux实用程序xargs,我可以轻松地提交一个单独的作业来解压目录中的所有文件:

ls *.gz | sed 's/.gz$//g' | xargs -I {} bsub 'gunzip -c {}.gz > {}'

使用SLURM,我认为srunsbatch会起作用,但是没有成功:
ls *.gz | sed 's/.gz$//g' | xargs -I {}  srun 'gunzip -c {}.gz > {}'
gzip: srun: error: compute-node-01: task 0: Exited with exit code 1
stdin: unexpected end of file

ls *.gz | sed 's/.gz$//g' | xargs -I {}  sbatch 'gunzip -c {}.gz > {}'
sbatch: error: Unable to open file gunzip -c naive_S1_L001_R1_001.fastq.gz > naive_S1_L001_R1_001.fastq

我看到LSF中的bsub被列为等效项与SLURM中的sbatch相似,但目前看来它们仅在提交脚本文件时是等效的:
                  SLURM                    LSF
                  --------------------     ------------------
Job Submission    sbatch [script_file]     bsub [script_file]

有没有其他方法可以使用SLURM提交“一行代码”任务?
3个回答

14

尝试使用 sbatch 的 wrap 选项,例如以下方式:

ls *.gz | sed 's/.gz$//g' | xargs -I {}  sbatch --wrap="gunzip -c {}.gz > {}"
从`sbatch`的手册页中:
--wrap=<command string>
       Sbatch will wrap the specified command string in  a  simple  "sh"  shell
       script,  and submit that script to the slurm controller.  When --wrap is
       used, a script name and arguments may not be specified  on  the  command
       line; instead the sbatch-generated wrapper script is used.

4
您还可以将内容导入到sbatch中。以下是一个示例。
echo '#!/bin/bash
touch hello_slurm.txt
' | sbatch -e err.log -o out.log

这可以被“强制”放在一行,并且与xargs -n1一起使用效果很好,但我认为这种方式更易读,以说明这个想法。个人而言,我更喜欢在这里使用heredoc,因为如果嵌入的“one-liner”或“some-liner”也包含单引号(这使它成为比sbatch --wrap更普遍的解决方案),它会增加一些灵活性。
sbatch  -e err.log -o out.log <<"EOF"
#!/bin/bash
touch 'hello_slurm2.txt'
EOF

顺便提一下,由于问题中也提到了:在使用LSF时,使用bsub也可以采用相同的方法。


使用heredoc的问题在于它很难在Makefile中使用。 - user5359531
有趣。也许可以使用 echo -e "" 来构建多行脚本,然后将其导入到 sbatch 中...谢谢! - Christopher Bottoms

1
Carles Fenoy的回答的基础上,我创建了一个名为sbatch_run的实用程序。
这个脚本需要输入作业名称和命令(用引号括起来),然后为您创建脚本(并运行它)。
sbatch_run jobname 'ls -lArt > list_of_files.txt'

我会为您创建以下脚本并运行它:
#!/bin/env bash
#SBATCH -J jobname.sbatch
#SBATCH -o jobname.sbatch.o_%j
#SBATCH -e jobname.sbatch.e_%j
#SBATCH --partition c14,general,HighMem
#SBATCH --mem 5G
#SBATCH --cpus-per-task 1
#SBATCH --nodes 1
#SBATCH --time 2-0

ls -lArt > list_of_files.txt

有设置每个任务内存和CPU等选项。


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