Slurm独立任务并行脚本无法运行,请求故障排查
Slurm脚本任务提交后立即被移除的问题排查与解决
问题重现
提交以下Slurm脚本后,任务未启动即被立即移除,日志文件无任何记录,尝试移除--exclusive参数和显式分配内存后问题仍存在:
#!/bin/bash # #SBATCH --job-name=parReconstructPar # Job name #SBATCH --output=log.parReconstructPar # Standard output and error log #SBATCH --partition=orbit # define the partition #SBATCH -n 32 # srun --exclusive -n1 reconstructPar -allRegions -time 0.0:0.3 & srun --exclusive -n1 reconstructPar -allRegions -time 0.35:0.65 & srun --exclusive -n1 reconstructPar -allRegions -time 0.7:1.0 & srun --exclusive -n1 reconstructPar -allRegions -time 1.05:1.35 & srun --exclusive -n1 reconstructPar -allRegions -time 1.4:1.7 & srun --exclusive -n1 reconstructPar -allRegions -time 1.75:2.05 & srun --exclusive -n1 reconstructPar -allRegions -time 2.1:2.4 & srun --exclusive -n1 reconstructPar -allRegions -time 2.45:2.75 & srun --exclusive -n1 reconstructPar -allRegions -time 2.8:3.1 & srun --exclusive -n1 reconstructPar -allRegions -time 3.15:3.4 & srun --exclusive -n1 reconstructPar -allRegions -time 3.45:3.7 & srun --exclusive -n1 reconstructPar -allRegions -time 3.75:4.0 & srun --exclusive -n1 reconstructPar -allRegions -time 4.05:4.3 & srun --exclusive -n1 reconstructPar -allRegions -time 4.35:4.6 & srun --exclusive -n1 reconstructPar -allRegions -time 4.65:4.9 & srun --exclusive -n1 reconstructPar -allRegions -time 4.95:5.2 & srun --exclusive -n1 reconstructPar -allRegions -time 5.25:5.5 & srun --exclusive -n1 reconstructPar -allRegions -time 5.55:5.8 & srun --exclusive -n1 reconstructPar -allRegions -time 5.85:6.1 & srun --exclusive -n1 reconstructPar -allRegions -time 6.15:6.4 & srun --exclusive -n1 reconstructPar -allRegions -time 6.45:6.7 & srun --exclusive -n1 reconstructPar -allRegions -time 6.75:7.0 & srun --exclusive -n1 reconstructPar -allRegions -time 7.05:7.3 & srun --exclusive -n1 reconstructPar -allRegions -time 7.35:7.6 & srun --exclusive -n1 reconstructPar -allRegions -time 7.65:7.9 & srun --exclusive -n1 reconstructPar -allRegions -time 7.95:8.2 & srun --exclusive -n1 reconstructPar -allRegions -time 8.25:8.5 & srun --exclusive -n1 reconstructPar -allRegions -time 8.55:8.8 & srun --exclusive -n1 reconstructPar -allRegions -time 8.85:9.1 & srun --exclusive -n1 reconstructPar -allRegions -time 9.15:9.4 & srun --exclusive -n1 reconstructPar -allRegions -time 9.45:9.7 & srun --exclusive -n1 reconstructPar -allRegions -time 9.75:10.0 &
核心问题分析
--exclusive参数的资源冲突
当在srun中使用--exclusive时,每个srun任务会请求独占整个节点,而非仅占用1个核心。你通过SBATCH -n 32仅申请了32个核心(通常对应2-4个多核心节点),但脚本中启动了32个带--exclusive的srun任务,需要32个独立节点,资源需求完全超出申请范围,调度器会直接拒绝任务并移除。缺少
wait命令导致主脚本提前退出
所有srun任务都以后台方式运行(&),主脚本会在启动所有任务后立即退出。Slurm会在主脚本退出时终止所有关联的子任务,这也是任务未执行就消失的原因之一,即使资源问题解决后,这个问题也会导致任务无法完成。
解决步骤
1. 修改脚本移除冲突参数并添加等待命令
调整后的脚本如下:
#!/bin/bash # #SBATCH --job-name=parReconstructPar # Job name #SBATCH --output=log.parReconstructPar # Standard output and error log #SBATCH --partition=orbit # define the partition #SBATCH -n 32 # 可选:显式为每个任务分配内存,比如每个任务1GB,总内存32GB #SBATCH --mem=32G srun -n1 reconstructPar -allRegions -time 0.0:0.3 & srun -n1 reconstructPar -allRegions -time 0.35:0.65 & srun -n1 reconstructPar -allRegions -time 0.7:1.0 & srun -n1 reconstructPar -allRegions -time 1.05:1.35 & srun -n1 reconstructPar -allRegions -time 1.4:1.7 & srun -n1 reconstructPar -allRegions -time 1.75:2.05 & srun -n1 reconstructPar -allRegions -time 2.1:2.4 & srun -n1 reconstructPar -allRegions -time 2.45:2.75 & srun -n1 reconstructPar -allRegions -time 2.8:3.1 & srun -n1 reconstructPar -allRegions -time 3.15:3.4 & srun -n1 reconstructPar -allRegions -time 3.45:3.7 & srun -n1 reconstructPar -allRegions -time 3.75:4.0 & srun -n1 reconstructPar -allRegions -time 4.05:4.3 & srun -n1 reconstructPar -allRegions -time 4.35:4.6 & srun -n1 reconstructPar -allRegions -time 4.65:4.9 & srun -n1 reconstructPar -allRegions -time 4.95:5.2 & srun -n1 reconstructPar -allRegions -time 5.25:5.5 & srun -n1 reconstructPar -allRegions -time 5.55:5.8 & srun -n1 reconstructPar -allRegions -time 5.85:6.1 & srun -n1 reconstructPar -allRegions -time 6.15:6.4 & srun -n1 reconstructPar -allRegions -time 6.45:6.7 & srun -n1 reconstructPar -allRegions -time 6.75:7.0 & srun -n1 reconstructPar -allRegions -time 7.05:7.3 & srun -n1 reconstructPar -allRegions -time 7.35:7.6 & srun -n1 reconstructPar -allRegions -time 7.65:7.9 & srun -n1 reconstructPar -allRegions -time 7.95:8.2 & srun -n1 reconstructPar -allRegions -time 8.25:8.5 & srun -n1 reconstructPar -allRegions -time 8.55:8.8 & srun -n1 reconstructPar -allRegions -time 8.85:9.1 & srun -n1 reconstructPar -allRegions -time 9.15:9.4 & srun -n1 reconstructPar -allRegions -time 9.45:9.7 & srun -n1 reconstructPar -allRegions -time 9.75:10.0 & # 等待所有后台任务完成 wait
2. 验证任务状态
提交修改后的脚本后,使用sacct命令查看任务详细状态,确认是否正常运行:
sacct -j <你的作业ID> --format=JobID,JobName,State,ExitCode,NodeList
如果任务仍有问题,查看输出日志或Slurm系统日志(通常在/var/log/slurm/目录下,需管理员权限)获取具体错误信息。
3. 可选:使用数组任务简化脚本
对于这种多批次独立任务,Slurm数组任务(SBATCH --array)是更简洁高效的方式,避免手动编写大量重复srun命令:
#!/bin/bash # #SBATCH --job-name=parReconstructPar #SBATCH --output=log.parReconstructPar_%a.log #SBATCH --partition=orbit #SBATCH -n 1 #SBATCH --array=0-31 # 定义时间区间数组 time_intervals=( "0.0:0.3" "0.35:0.65" "0.7:1.0" "1.05:1.35" "1.4:1.7" "1.75:2.05" "2.1:2.4" "2.45:2.75" "2.8:3.1" "3.15:3.4" "3.45:3.7" "3.75:4.0" "4.05:4.3" "4.35:4.6" "4.65:4.9" "4.95:5.2" "5.25:5.5" "5.55:5.8" "5.85:6.1" "6.15:6.4" "6.45:6.7" "6.75:7.0" "7.05:7.3" "7.35:7.6" "7.65:7.9" "7.95:8.2" "8.25:8.5" "8.55:8.8" "8.85:9.1" "9.15:9.4" "9.45:9.7" "9.75:10.0" ) # 取当前数组任务对应的时间区间 current_time=${time_intervals[$SLURM_ARRAY_TASK_ID]} reconstructPar -allRegions -time $current_time
数组任务会自动为每个时间区间启动一个独立子任务,资源管理更清晰,也便于单独查看每个任务的日志。
内容的提问来源于stack exchange,提问作者GarstigerGerhard
相关产品推荐
相关产品推荐

