简体   繁体   English

在 SLURM 批处理脚本中将参数传递给 python 脚本

[英]Passing arguments to a python script in a SLURM batch script

I've written a python script that requires two arguments and works just fine when I run it on the command line with:我写了一个需要两个参数的 python 脚本,当我在命令行上运行它时工作得很好:

pythonscript.py arg1 arg2

I need to run this in a SLURM batch script, but whenever I do I get an "illegal instruction" error and a core dump.我需要在 SLURM 批处理脚本中运行它,但是无论何时我都会收到“非法指令”错误和核心转储。 This is an example of the script I'm using:这是我正在使用的脚本示例:

#!/bin/bash
# Set your minimum acceptable walltime, format: day-hours:minutes:seconds
#SBATCH --time=0-00:30:00

# Set name of job shown in squeue
#SBATCH --job-name pythonscript

# Request CPU resources
#SBATCH --ntasks=1
#SBATCH --ntasks-per-node=1
#SBATCH --cpus-per-task=1

# Memory usage (MB)
#SBATCH --mem-per-cpu=3000

# Use modules to set the software environment
module purge
module load python/2.7.8-gcc

pythonscript.py arg1 arg2

I've spent a lot of time trying to figure out exactly what is causing the core dumps, and this is what I've narrowed it down to.我花了很多时间试图找出导致核心转储的确切原因,这就是我缩小范围的原因。 It only crashes when run from the batch script and only when I'm trying to run the script with arguments.它仅在从批处理脚本运行时崩溃,并且仅在我尝试使用参数运行脚本时崩溃。 When I modify it to run without arguments, it runs properly.当我修改它以在没有参数的情况下运行时,它运行正常。 Can anyone tell me how to pass these arguments to my python script within a SLURM script?谁能告诉我如何在 SLURM 脚本中将这些参数传递给我的 python 脚本?

This may seem like a silly question, but is the pythonscript.py executable?这似乎是一个愚蠢的问题,但是 pythonscript.py 是可执行文件吗?

Also have you tried你也试过

python pythonscript.py arg1 arg2

Alternately, you might be able to change或者,您也许可以更改

#!/bin/bash

to

#!/bin/python

or the appropriate path to the python version you want to use.或您要使用的 python 版本的适当路径。

The problem was the node where my job was sent.问题是发送我的作业的节点。 I managed to check in which node my job run without errors with the command:我设法使用以下命令检查我的作业在哪个节点运行而没有错误:

sacct --format=JobID,"AllocCPUS,Node,JobName%20,MaxVMSize,MaxRSS,ReqMem,Start,End"

I identified the proper node and then switch in my .sh with:我确定了正确的节点,然后在我的 .sh 中切换:

#SBATCH -w, --nodelist=compute124

I use the following and I can add any number of arguments.我使用以下内容,我可以添加任意数量的参数。

#!/bin/bash
#SBATCH --cpus-per-task=1        # number of cores

cd $SLURM_SUBMIT_DIR
pwd

python $SLURM_SUBMIT_DIR/python.py HumptyDumpty.txt newhumpty.txt ad.txt

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM