[英]Using srun outside SLURM
I have a code that is usually run under SLURM.我有一个通常在 SLURM 下运行的代码。 Something like就像是
if ! lengthy_command
then
echo "Error occured"
fi
For accounting purposes, I would like to move to a srun
based launch of the command:出于会计目的,我想转向基于srun
的命令启动:
if ! srun <srun params> lengthy_command
then
echo "Error occured"
fi
But after changing that line, the script will no longer run in an interactive session (outside SLURM).但更改该行后,脚本将不再在交互式会话中运行(在 SLURM 之外)。 Is there any way to generalize the script so it can run under both conditions?有什么方法可以概括脚本,使其可以在两种情况下运行? I cannot see anything in the srun
documentation that points in that direction.我在srun
文档中看不到任何指向该方向的内容。
One option is to use a variable and set it to srun
when in a job (for instance when $SLURM_JOBID
is set), and to leave it empty otherwise.一种选择是使用变量并在作业中将其设置为srun
(例如,设置$SLURM_JOBID
时),否则将其留空。
if [ -n $SLURM_JOBID ] ;
then
LAUNCH=srun <srun params>
else
LAUNCH=
fi
if ! $LAUNCH lengthy_command
then
echo "Error occured"
fi
This approach can be extended by setting LAUNCH
to parallel <parallel options>
when using GNU parallel, or to other commands when run in a cluster with another scheduler.这种方法可以通过在使用 GNU parallel 时将LAUNCH
设置为parallel <parallel options>
或在具有另一个调度程序的集群中运行时设置为其他命令来扩展。
Another option is to create a Bash function named srun
that encapsulates the logic (untested):另一种选择是创建一个名为srun
的 Bash 函数来封装逻辑(未经测试):
srun() {
if [ -n $SLURM_JOBID ] ;
then
command srun $@
else
$@
fi
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.