agentleFS
AI-ModConAI-ModCon/genesis-skills/skills/hpc-skills/slurm/SKILL.md

slurm

Skill30 starsChanged 51 days agoBSD-2-ClauseView on GitHub

Slurm workload manager for HPC batch job scheduling. Use when submitting batch or interactive jobs with sbatch/salloc/srun, monitoring with squeue/sacct/scontrol, cancelling with scancel, writing #SBATCH job scripts, working with job arrays, setting job dependencies, checking fair-share accounting with sacctmgr/sreport, or troubleshooting failed jobs on any Slurm cluster.

4 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

2 rules. 0 are common, 1 is distinctive, and 1 is very specific to this project.

  • 0

    Common

    Most of the 4 edited versions we read keep these.

  • 1

    Distinctive

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Run many similar jobs from one submission.

    line 165
  2. Distinctive:

    Always load modules inside the job script, not just in your login shell.

    line 224

“Common” is measured: kept by at least 6 in 10 of the 4 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Slurm Workload Manager

Slurm is the dominant HPC batch scheduler. Jobs are submitted to queues (partitions), allocated nodes, and run with full or partial node access.

Quick Command Reference

CommandPurpose
sbatch script.shSubmit a batch job script
sallocAllocate nodes for an interactive session
srunRun a parallel job step (inside or outside a batch job)
squeueView pending and running jobs
scontrol show job <id>Detailed job info
scancel <id>Cancel a job
scontrol hold/release <id>Hold or release a pending job
sinfoCluster partition and node status
sacctQuery completed job accounting records
sacctmgrManage accounts, QOS, and allocations

Job State Codes

CodeStateMeaning
PDPENDINGWaiting for resources
RRUNNINGCurrently executing
CGCOMPLETINGCleaning up after execution
CDCOMPLETEDFinished with exit code 0
CACANCELLEDCancelled by user or admin
FFAILEDNon-zero exit code
TOTIMEOUTExceeded time limit
OOMOUT_OF_MEMORYKilled by memory manager
PRPREEMPTEDPreempted by higher-priority job

Writing Job Scripts

Directives go at the top of the script as #SBATCH comments before any executable line.

Minimal working script:

#!/bin/bash
#SBATCH --job-name=myjob
#SBATCH --nodes=1
#SBATCH --ntasks-per-node=32
#SBATCH --time=01:00:00
#SBATCH --account=myproject
#SBATCH --output=myjob_%j.out
#SBATCH --error=myjob_%j.err

module load gcc openmpi
srun ./my_application

Key #SBATCH Directives

DirectiveExampleNotes
--job-namemyjobShown in squeue
--nodes / -N4Number of nodes
--ntasks-per-node128MPI ranks per node
--cpus-per-task / -c4Threads per MPI rank
--time / -t2-00:00:00D-HH:MM:SS or HH:MM:SS
--partition / -pgpuQueue to use
--account / -AmyprojectAllocation to charge
--output / -ojob_%j.outStdout path
--error / -ejob_%j.errStderr path
--gresgpu:4Generic resources (GPUs)
--mem64GMemory per node
--mem-per-cpu4GMemory per CPU core
--exclusive—Reserve entire node(s)
--dependencyafterok:12345Wait for another job
--array0-99Submit job array
--mail-typeEND,FAILEmail notifications
--mail-useruser@hostEmail address

Output Filename Tokens

TokenMeaning
%jJob ID
%AArray parent job ID
%aArray task index
%xJob name
%NFirst node name

Submitting Jobs

# Batch submission
sbatch script.sh

# Override directives at submission
sbatch --nodes=8 --time=4:00:00 script.sh

# Interactive allocation (drops into a shell on allocated node)
salloc --nodes=2 --time=1:00:00 --partition=debug
srun ./my_app          # run within the allocation
exit                   # release allocation

# One-off parallel command (creates its own allocation)
srun --nodes=1 --ntasks=4 ./my_app

Monitoring Jobs

# Your jobs
squeue -u $USER

# All jobs, long format
squeue -l

# Specific job
squeue -j 12345

# Estimated start times for pending jobs
squeue --start -u $USER

# Full detail (reason for pending, TRES, etc.)
scontrol show job 12345

# Live updates every 5 seconds
watch -n5 squeue -u $USER

Reading output files: Slurm writes stdout/stderr when the job finishes (or continuously if --output is to a path). Watch a running job's output:

tail -f myjob_12345.out

After job completes:

sacct -j 12345 --format=JobID,State,Elapsed,MaxRSS,ExitCode

Cancelling and Holding Jobs

scancel 12345                      # cancel by job ID
scancel 12345_5                    # cancel one array element
scancel -u $USER --state=PENDING   # cancel all your pending jobs
scancel -n myjob                   # cancel by name

scontrol hold 12345                # hold a pending job
scontrol release 12345             # release held job

Job Arrays

Run many similar jobs from one submission. Each element gets a unique SLURM_ARRAY_TASK_ID.

#SBATCH --array=0-99             # indices 0..99
#SBATCH --array=1-50:2           # odd indices 1,3,5,...,49
#SBATCH --array=0-999%20         # up to 20 running at once
#SBATCH --output=job_%A_%a.out   # %A=parent ID, %a=task index

Inside the script, use $SLURM_ARRAY_TASK_ID to select input:

INPUT="data/input_${SLURM_ARRAY_TASK_ID}.txt"
srun ./process "$INPUT"

Array management:

squeue -r -j 36           # show all elements
scancel 36                # cancel entire array
scancel 36_[1-5]          # cancel elements 1–5

Job Dependencies

Chain jobs so they start only when a predecessor finishes:

JOB1=$(sbatch stage1.sh | awk '{print $4}')
sbatch --dependency=afterok:$JOB1 stage2.sh

# Common dependency types:
# afterok:<id>    — start only if <id> succeeds
# afterany:<id>   — start regardless of <id> outcome
# afternotok:<id> — start only if <id> fails
# singleton       — only one job with this name runs at a time

Common Environment Variables (Inside a Job)

VariableValue
$SLURM_JOB_IDJob ID
$SLURM_NODELISTList of allocated nodes
$SLURM_NTASKSTotal number of tasks
$SLURM_CPUS_PER_TASKCPUs per task
$SLURM_SUBMIT_DIRDirectory where sbatch was run
$SLURM_ARRAY_JOB_IDParent array job ID
$SLURM_ARRAY_TASK_IDThis element's index

Module System

module avail              # list available modules
module spider <pkg>       # search for a package
module load gcc/12 openmpi/4.1
module list               # show loaded modules
module purge              # unload everything

Always load modules inside the job script, not just in your login shell.

Additional Resources

  • Annotated job script examples: references/job-scripts.md
  • Monitoring, troubleshooting, scontrol recipes: references/job-control.md
  • Accounting, fairshare, allocation reporting: references/accounting.md
  • Copy-paste templates: assets/templates/

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.