[英]How can I convert my script for submitting SLURM jobs from Bash to Perl?
I have the following Bash script for job submission to SLURM on a cluster: 我有以下Bash脚本,用于将作业提交到群集上的SLURM :
#!/bin/bash
#SBATCH -A 1234
#SBATCH -t 2-00:00
#SBATCH -n 24
module add xxx
srun resp.com
The #SBATCH
lines are SLURM commands: #SBATCH
行是SLURM命令:
#SBATCH -A 1234
is the project number (1234) #SBATCH -A 1234
是项目编号(1234) #SBATCH -t 2-00:00
is the job time #SBATCH -t 2-00:00
是作业时间 #SBATCH -n 24
is the number of cores #SBATCH -n 24
是内核数 module add xxx
loads the Environment Module xxx
(in this case I'm actually using module add gaussian
, where gaussian
is a computational quantum-chemistry program). module add xxx
加载环境模块 xxx
(在这种情况下,我实际上使用的是module add gaussian
,其中gaussian
是计算量子化学程序)。
srun
is the SLURM command to launch a job. srun
是启动作业的SLURM命令。 resp.com
includes commands for gaussian and atom coordinates. resp.com
包括用于高斯和原子坐标的命令。
I tried converting the Bash script to the following Perl script, but it didn't work. 我尝试将Bash脚本转换为以下Perl脚本,但是没有用。 How can I do this in Perl? 我如何在Perl中做到这一点?
#!/usr/bin/perl
use strict;
use warnings;
use diagnostics;
system ("#SBATCH -A 1234");
system ("#SBATCH -t 2-00:00");
system ("#SBATCH -n 24");
system ("module add xxx");
system ("srun resp.com ");
Each of your system
calls creates a child process to run the program in question and returns when the child process dies. 您的每个system
调用都会创建一个子进程来运行有问题的程序,并在该子进程死后返回。
The whole point of module
is to configure the current shell by, among other things, modifying it's environment. module
是通过修改环境来配置当前shell。 When this process completes (dies) say goodbye to those changes. 该过程完成(死亡)时,请告别那些更改。 The call to srun
, in it's shinny new process with a shinny new environment, hasn't got a chance. 在具有光亮的新环境的光亮新流程中,对srun
的呼吁没有机会。
Steps forward: 前进的步骤:
system("#SBATCH whatever");
了解SLURM和bash和究竟为什么system("#SBATCH whatever");
might not be of any value. 可能没有任何价值。 Hint: #
marks the beginning of a comment in both Bash & Perl. 提示: #
表示Bash和Perl中评论的开始。 module add
is doing with xxx
and how you might replicate what it's doing inside the shell within the Perl interpreter. 了解module add
对xxx
以及如何在Perl解释器的shell中复制它的作用。 ThisSuitIsBlackNot recommends use Env::Modulecmd { load => 'foo/1.0' };
ThisSuitIsBlackNot建议use Env::Modulecmd { load => 'foo/1.0' };
to replicate this functionality. 复制此功能。 module add
, system ('module add xxx; srun resp.com')
would put those two commands in the same shell process, but at this point you need to ask yourself what you've gained by adding a Perl interpreter to the mix. 除非对module add
, system ('module add xxx; srun resp.com')
任何了解, system ('module add xxx; srun resp.com')
会将这两个命令放在同一个shell进程中,但是此时,您需要问自己添加Perl解释器后获得了什么混合。 What you need to do is write 你需要做的就是写
#!/usr/bin/perl
#SBATCH -A 1234
#SBATCH -t 2-00:00
#SBATCH -n 24
use strict;
use warnings;
use diagnostics;
system ("module add xxx && srun resp.com ");
and then submit it with 然后用
sbatch my_perl_script.pl
The #SBATCH
lines are comments destined to be parsed by the sbatch
command. #SBATCH
行是注定要由sbatch
命令解析的sbatch
。 They must be comments in the submission script. 它们必须是提交脚本中的注释。
The module
command modifies the environment, but that environment is lost as soon as it is called if you invoke it with system
on its own as system
creates a subshell. 该module
命令修改了环境,但是如果您在system
创建子外壳程序时单独使用system
调用该环境,则会立即丢失该环境。 You need to either invoke it on the same subshell as srun
, as shown above, or use Perl tools to load the module in the environment of the Perl script so that it is available to srun
, using use Env::Modulecmd { load => 'foo/1.0' };
您需要在与srun
相同的子shell上调用它,如上所示,或者使用Perl工具在Perl脚本的环境中加载模块,以便可以使用srun
,请use Env::Modulecmd { load => 'foo/1.0' };
as mentioned elsewhere. 如其他地方提到的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.