Skip to content

slurm 简明使用手册

灵犀易算 二〇二一 年 十二 月 二十 日

一、简述

1.1、slurm 概述

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

1.2、集群计算资源

本系统集群账号配置为双路 Intel Xeon Gold 6258R 28 核 CPU,一个计算节点有 56 个核心,内存大小为 192GB。 本系统使用 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 D1_yeesuan sinfo --help 查看 sinfo 其余参数情况 sinfo --help

sinfo 示例如下:

[yeesuan003@login02 ~]$ sinfo PARTITION AVAIL TIMELIMIT NODES STATE NODELIST D1_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 D1_yeesuan squeue --help 查看 squeue 其余参数情况 squeue -help

squeue 示例如下:

[yeesuan003@login02 amberTest]$ squeue JOBID 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)
  • CG:即将完成(COMPLETING)
  • CD:已完成(COMPLETED)
  • CA:已取消(CANCELLED)
  • F:已失败(FAILED) ·TIME:已运行时间。 ·NODES:节点数。 ·NODELIST(REASON):节点列表(原因)。

2.3、作业提交命令

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

选项 功能 示例

-p 指定队列名称 -p D1_yeesuan -J 指定作业名称 -J test -N 指定节点数量 -N 2 -n 指定总核数 -n 32 -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 D1_yeesuan -N 2 -n 32 -c 1 helloworld

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

·-J test:指定作业名称为 test。 ·-p D1_yeesuan:指定队列名称为 D1_yeesuan。 ·-N 2:指定节点数量为 2。 ·-n 32:指定总核数为 32。 ·-c 1:指定每个进程使用核数为 1。 ·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=D1_yeesuan %指定分区为 D1_yeesuan #SBATCH -N=2 %指定节点数量为 2 #SBATCH -n 32 %指定总核数为 32 #SBATCH --cpus-per-task=1 %指定每个进程使用核数,不指定默认为 1 #SBATCH --ntasks-per-node=16 %指定每个节点进程数/核数,使用-n 参数(优先级更高),变为每个节点最多运行的任务数 #SBATCH -o=out.log %指定输出文件 out.log #SBATCH -e=error.log %指定错误输出文件 error.log source /public/home/user/.bashrc %导入个人运行程序所需的环境变量文件 mpirun -n 32 ./helloworld %运行命令

2.3.3、salloc 命令

申请计算节点。

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

salloc 示例如下:

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

srun 示例中的命令意义:

·salloc -p D1_yeesuan -N1 -n6 :申请 D1_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 2366817 JobId=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=D1_yeesuan AllocNode:Sid=login02:44211 ReqNodeList=(null) ExcNodeList=(null) NodeList=n07881 BatchHost=n07881 (...仅截取部分)

scontrol show node 示例如下:

[yeesuan003@login02 amberTest]$ scontrol show node n07881 NodeName=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 D1_yeesuan PartitionName=D1_yeesuan AllowGroups=yeesuan AllowAccounts=ALL AllowQos=ALL AllocNodes=ALL Default=NO QoS=N/A DefaultTime=NONE DisableRootJobs=NO ExclusiveUser=NO GraceTime=0 Hidden=NO MaxNodes=UNLIMITED MaxTime=UNLIMITED MinNodes=0 LLN=NO MaxCPUsPerNode=UNLIMITED Nodes=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 (...仅截取部分)