在 Slurm 中,是否有快速命令来确定给定时刻的作业总数(待处理和活动)?

In Slurm, is there a quick command to determine the total number of jobs (pending and active) at a given moment?

在 slurm 中,调用命令 squeue -u <username> 将列出给定用户的所有待处理或活动作业。我想知道是否有一种快速的方法可以将它们全部统计出来,以便我知道有多少未完成的工作,包括待处理和活跃的 运行 个工作。谢谢!

如果你只想总结squeue的输出,怎么样:

squeue -u <username> | awk '
BEGIN {
    abbrev["R"]="(Running)"
    abbrev["PD"]="(Pending)"
    abbrev["CG"]="(Completing)"
    abbrev["F"]="(Failed)"
}
NR>1 {a[]++}
END {
    for (i in a) {
        printf "%-2s %-12s %d\n", i, abbrev[i], a[i]
    }
}'

产生类似的东西:

R  (Running)    1
PD (Pending)    4

解释:

  • 根据squeue的默认格式,假定job state在第5个字段。
  • 然后脚本计算每个作业状态代码的出现次数,第一行除外,其中包含 header.
  • 最后报告每个作业状态代码的计数。

为了便于使用,将以下行添加到您的 .bash_aliases.bashrc(文件名可能取决于系统):

function summary() {
    squeue "$@" | awk '
    BEGIN {
        abbrev["R"]="(Running)"
        abbrev["PD"]="(Pending)"
        abbrev["CG"]="(Completing)"
        abbrev["F"]="(Failed)"
    }
    NR>1 {a[]++}
    END {
        for (i in a) {
            printf "%-2s %-12s %d\n", i, abbrev[i], a[i]
        }
    }'
}

然后您可以仅使用 summary [option] 调用命令,其中 [option] 接受 squeue 的选项(如果需要)(大部分是不必要的)。

希望这对您有所帮助。

我会以不同的方式解释 "quick command"。此外,当您使用作业数组时,我会添加 -r :

squeue -u <username> -h -t pending,running -r | wc -l

选项 -h 删除 header "wc -l"(字数统计)输出的行数。 最终我将它与 watch

一起使用
watch 'squeue -u <username> -h -t pending,running -r | wc -l'

@skytaker 的这条评论在我看来确实提供了最佳解决方案,它区分了待定和 运行,并为您分别计算了每一个。与 Stefan Maschek 的解决方案唯一不同的是使用 uniq 而不是 wc:

squeue -u <username> -h -t pending,running -r -O "state" | uniq -c