In Slurm, is there a quick command to determine the total number of jobs (pending and active) at a given moment?
If you just want to summarize the output of squeue
, how about:
squeue -u <username> | awk '
BEGIN {
abbrev["R"]="(Running)"
abbrev["PD"]="(Pending)"
abbrev["CG"]="(Completing)"
abbrev["F"]="(Failed)"
}
NR>1 {a[$5]++}
END {
for (i in a) {
printf "%-2s %-12s %d\n", i, abbrev[i], a[i]
}
}'
which yields something like:
R (Running) 1
PD (Pending) 4
Explanations:
- The
job state
is assumed to be in the 5th field according to the default format ofsqueue
. - Then the script counts the appearance of each job state code except for the 1st line which includes the header.
- Finally it reports the count of each job state code.
In order to make it handy, add the following lines to your .bash_aliases
or .bashrc
(the filename may depend on the system):
function summary() {
squeue "$@" | awk '
BEGIN {
abbrev["R"]="(Running)"
abbrev["PD"]="(Pending)"
abbrev["CG"]="(Completing)"
abbrev["F"]="(Failed)"
}
NR>1 {a[$5]++}
END {
for (i in a) {
printf "%-2s %-12s %d\n", i, abbrev[i], a[i]
}
}'
}
Then you can invoke the command just with summary [option]
, where [option]
accepts options to squeue
if needed (mostly unnecessary).
Hope this helps.
I would interprete "quick command" differently. Additionally I would add -r for cases when you are using job arrays:
squeue -u <username> -h -t pending,running -r | wc -l
option -h removes the header "wc -l" (word count) counts the line of the output. Eventually I am using it with watch
watch 'squeue -u <username> -h -t pending,running -r | wc -l'