Skip to content

Slurm 调度使用指南

一、简述

1.1. Slurm概述

Slurm 是一个面向Linux和Unix类似内核的开源、具有容错性和高度可扩展的集群资源管理和作业调度系统。slurm提交作业有3种模式,分别为交互模式(srun)、批处理模式(sbatch)、分配模式(salloc),这三种方式只是用户使用方式的区别,在管理,调度,记账时同等对待。

1.2. 集群计算资源

本系统使用slurm进行资源和作业管理,下文会对slurm常用命令的具体使用方式进行讲解,并给出简易模板示例。

二、基本命令

命令功能
sinfo查看分区和节点信息
squeue查看队列中的作业状态
srun交互式运行并行作业
sbatch批处理式提交作业
salloc分配式提交作业
scancel取消作业运行
scontrol显示slurm作业、分区、节点等状态
sacct查看已完成的作业信息

2.1. sinfo命令

查看系统的 slurm 节点和队列的信息。

命令功能示例
sinfo查看队列信息sinfo
sinfo -n查看指定节点状态sinfo -n n07881
sinfo -p查看指定队列使用情况sinfo -p g1_yeesuan
sinfo --help查看sinfo其余参数情况sinfo --help

sinfo示例如下:

[yeesuan003@login02 ~]$ sinfoPARTITION AVAIL TIMELIMIT NODES STATE NODELISTg1_yeesuan up infinite 3 idle n[07881-07883]

sinfo示例中,主要输出项:

·PARTITION:队列名,后面带有的,表示此队列为默认队列。·AVAIL:up表示可用,down表示不可用。·TIMELIMIT:作业运行时间限制,infinite表示无限制。·NODES:节点数。·STATE:节点状态,常见的状态包括- alloc:节点正在被使用- idle:节点可用- mix:部分占用- down:节点下线- drain:节点故障- unknown:未知原因注:若状态带有后缀,则表示节点未响应·NODELIST:节点名列表。

2.2. squeue命令

显示队列中的作业信息。

命令功能示例
squeue查看运行中的作业列表squeue
squeue -l查看列表细节信息squeue -l
squeue -p查看指定队列作业情况squeue -p g1_yeesuan
squeue --help查看squeue其余参数情况squeue -help

squeue示例如下:

[yeesuan003@login02 amberTest]$ squeueJOBID PARTITION NAME USER ST TIME NODES NODELIST(REASON)2366722 D1_yeesua test yeesuan0 R 0:11 1 n07881

squeue示例中,主要输出项:

·JOBID:作业号。·PARTITION:队列名。·NAME:作业名。·USER:用户名。·ST:作业状态,常见的状态包括- R:正在运行(RUNNING)- PD:正在排队(PENDING)·TIME:已运行时间。·NODES:节点数。·NODELIST(REASON):节点列表(原因)

2.3. 作业提交命令

以下选项在交互模式(srun)、批处理模式(sbatch)、分配模式(salloc)中均可以使用。更多参数见srun --help、sbatch --help、salloc --help。

选项功能示例
-p指定队列名称-p g1_yeesuan
-J指定作业名称-J test
-N指定节点数量-N 1
-n指定进程数-n 4
-c指定每个进程使用的线程数(不指定则默认为1)-c 16
-o指定输出文件-o out.log
-e指定报错输出文件-e error.log

2.3.1. srun命令

提交交互式并行作业。使用srun命令提交作业后,作业进入等待、执行状态,待作业执行完毕后,则返回命令行窗口。

语法:srun [OPTIONS...] 可执行文件 [args...]

srun示例如下:

[yeesuan003@login02 ~]$ srun -J test -p g1_yeesuan -N 1 -n 4 -c 16 helloworld

srun示例中的选项、参数意义:

·-J test:指定作业名称为test。·-p g1_yeesuan:指定队列名称为g1_yeesuan。·-N 1:指定节点数量为1。·-n 4:指定进程数量为4。·-c 16:指定每个进程使用线程数为16。·helloworld:指代要运行程序的可执行文件,您将其换成自己所需的文件即可。

2.3.2. sbatch命令

批处理式提交作业。

语法:sbatch [OPTIONS...] executable [args...]

批处理作业是指用户编写作业脚本,指定资源需求约束,提交后台执行作业。提交批处理作业的命令为 sbatch,用户提交命令即返回命令行窗口,但此时作业在进入调度状态,在资源满足要求时,分配完计算结点之后,系统将在所分配的第一个计算结点(而不是登录结点)上加载执行用户的作业脚本。计算开始后,工作目录中会生成以 slurm 开头的.out 文件为输出文件(若未指定输出的话)。

作业提交命令为:sbatch run.sh,run.sh的脚本示例如下:

#!/bin/bash #SBATCH -J test %指定作业名称为test#SBATCH -p g1_yeesuan %指定分区为g1_yeesuan#SBATCH -N 1 %指定节点数量为1#SBATCH -n 4 %指定进程数为4#SBATCH --cpus-per-task 16 %指定每个进程使用线程数,不指定默认为1#SBATCH -o out.log %指定输出文件out.log#SBATCH -e error.log %指定错误输出文件error.logsource /es01/software/profile.d/intel2020.sh %导入个人运行程序所需的环境变量mpirun helloworld %运行命令

2.3.3. salloc命令

申请计算节点。

语法:salloc [OPTIONS...] [command [args...]]

salloc示例如下:

[yeesuan003@login02 ~]$ salloc -p g1_yeesuan -N 1 -n 6salloc: Granted job allocation 2366789salloc: Waiting for resource configurationsalloc: Nodes n07881 are ready for job[yeesuan003@login02 ~]$ squeue -j 2366789JOBID PARTITION NAME USER ST TIME NODES NODELIST(REASON)2366789 D1_yeesua bash yeesuan0 R 2:05 1 n07881[yeesuan003@login02 ~]$ scancel 2366789salloc: Job allocation 2366789 has been revoked.Hangup

srun示例中的命令意义:

·salloc -p g1_yeesuan -N 1 -n 6 :申请g1_yeesuan队列上的一个节点6个核心·squeue -j 2366789 :查看作业号为2366789的作业运行状态·scancel 2366789 :取消作业号为2366789的作业

2.4. scancel命令

取消一个正在运行的作业。

语法:Usage: scancel [OPTIONS] [job_id[_array_id][.step_id]]

scancel示例如下:

[yeesuan003@login02 ~]$ scancel 2366789

scancel示例中的命令意义:

·取消作业号为2366789的作业,使其终止运行

2.5. scontrol命令

查看详细作业、节点、队列等信息。

语法:scontrol [(OPTION)] [(COMMAND)]

命令功能
scontrol show job查看作业的详细信息
scontrol show node查看节点的详细信息
scontrol show partition查看队列的详细信息
scontrol show node | grep CPU查看各节点的cpu状态

scontrol show job示例如下:

[yeesuan003@login02 amberTest]$ scontrol show job 2366817JobId=2366817 JobName=test UserId=yeesuan003(37745) GroupId=yeesuan(42075) MCS_label=N/A Priority=1 Nice=0 Account=yeesuan QOS=normal JobState=RUNNING Reason=None Dependency=(null) Requeue=0 Restarts=0 BatchFlag=1 Reboot=0 ExitCode=0:0 RunTime=00:00:15 TimeLimit=UNLIMITED TimeMin=N/A SubmitTime=2021-12-23T14:45:33 EligibleTime=2021-12-23T14:45:33 AccrueTime=2021-12-23T14:45:33 StartTime=2021-12-23T14:45:33 EndTime=Unknown Deadline=N/A SuspendTime=None SecsPreSuspend=0 LastSchedEval=2021-12-23T14:45:33 Partition=g1_yeesuan AllocNode:Sid=login02:44211 ReqNodeList=(null) ExcNodeList=(null) NodeList=n07881 BatchHost=n07881(...仅截取部分)

scontrol show node示例如下:

[yeesuan003@login02 amberTest]$ scontrol show node n07881NodeName=n07881 Arch=x86_64 CoresPerSocket=28 CPUAlloc=4 CPUTot=56 CPULoad=0.01 AvailableFeatures=(null) ActiveFeatures=(null) Gres=(null) NodeAddr=n07881 NodeHostName=n07881 Version=19.05.7 OS=Linux 3.10.0-957.el7.x86_64 #1 SMP Thu Nov 8 23:39:32 UTC 2018 (...仅截取部分)

scontrol show partition示例如下:

[yeesuan003@login02 amberTest]$ scontrol show partition g1_yeesuanPartitionName=g1_yeesuanAllowGroups=yeesuan AllowAccounts=ALL AllowQos=ALLAllocNodes=ALL Default=NO QoS=N/ADefaultTime=NONE DisableRootJobs=NO ExclusiveUser=NO GraceTime=0 Hidden=NOMaxNodes=UNLIMITED MaxTime=UNLIMITED MinNodes=0 LLN=NO MaxCPUsPerNode=UNLIMITEDNodes=n[07881-07883](...仅截取部分)

scontrol show node | grep CPU示例如下:

[yeesuan003@login02 amberTest]$ scontrol show node | grep CPU CPUAlloc=0 CPUTot=56 CPULoad=0.53 CPUAlloc=0 CPUTot=56 CPULoad=1.13 CPUAlloc=0 CPUTot=56 CPULoad=0.31 CPUAlloc=0 CPUTot=56 CPULoad=2.98(...仅截取部分)