Close Menu
DPC Virtual Tips
    Read More

    Configure vCenter File-Based Backups to NFS: Practical Lab Guide

    September 11, 2026

    Creating Your First Ansible Playbook: A Practical Lab Guide

    September 10, 2026

    Linux Commands to Investigate High Disk Partition Usage

    September 9, 2026
    • Home
    • About Us
    • Contact
    • Cookie Policy
    • Comment Policy
    • Privacy Policy
    • Terms of Use
    Monday, September 14
    DPC Virtual Tips
    • Home
    • Linux & Automation
    • HPC & Slurm
    • VMware & Virtualization
    • About Us
    • Contact
    DPC Virtual Tips
    Home » Slurm Job Submission: Practical Guide to srun, sbatch, and salloc
    HPC & Slurm

    Slurm Job Submission: Practical Guide to srun, sbatch, and salloc

    By Danilo ChiacchioAugust 27, 20269 Mins Read
    Facebook Twitter Pinterest LinkedIn Tumblr Email
    Slurm Job Submission: Practical Guide to srun, sbatch, and salloc
    Slurm Job Submission: Practical Guide to srun, sbatch, and salloc
    Share
    Facebook Twitter LinkedIn Pinterest Email

    Slurm job submission is a fundamental task for users working with High Performance Computing (HPC) clusters. In this guide, I will demonstrate the basic commands used to submit jobs, including srun for interactive execution and sbatch for batch processing.

    When working with a Slurm-managed cluster, users do not usually execute workloads directly on compute nodes. Instead, they request resources from the scheduler, which allocates nodes, CPUs, and execution time according to the job requirements.

    This article provides practical examples of job submission in a Slurm environment, showing how to run commands interactively, submit scripts, inspect the queue, and understand the main differences between srun and sbatch.

    To build a small environment for testing these commands, see “Setting Up a Slurm Cluster in a Lab Environment“.

    Running Commands and Job Steps with srun

    The srun command launches tasks or job steps on resources managed by Slurm. When it is executed outside an existing allocation, srun can request the required resources first and then launch the command. If the resources are not immediately available, the command may wait in the scheduler until the request can be satisfied.

    1- Run a simple command:

    srun -N1 -n1 hostname
    Slurm srun command executing hostname on one compute node
    Slurm srun command executing hostname on one compute node

    In this case, for instance:

    -N, --nodes=<minnodes>[-maxnodes]|<size_string> = Request that a minimum of minnodes nodes be allocated to this job. A maximum node count may also be specified with maxnodes. If only one number is specified, this is used as both the minimum and maximum node count. So, in this case, "-N1" means "I need one node".
    
    -n, --ntasks=<number> = Specify the number of tasks to run. Request that srun allocate resources for ntasks tasks. The default is 1 task per node, but note that the ---cpus-per-task option overrides this default. This option applies to job and step allocations.
    
    hostname = In this case, for instance, "hostname" is the command to be executed by the job.

    The command’s output is “hpcnode01“, indicating that “hostname” was executed on the first compute node, “hpcnode01”.

    Important: Look at the command prompt – we’re on a login node, and the job was submitted using it.

    2- Execute the same command, but using different options with “srun”:

    srun -N1 -n2 hostname
    Slurm srun resource allocation error when requesting two tasks on one single-CPU node
    Slurm srun resource allocation error when requesting two tasks on one single-CPU node

    Look at the srun error:

    srun: error: Unable to allocate resources: Requested node configuration is not available

    As we learned before, the “-n” option specifies the number of tasks to run. The default is one task per node, which explains the error we’re seeing.

    In this lab, each compute node provides only one CPU to Slurm. Requesting two tasks on a single node therefore cannot be satisfied with the current resource configuration. This behavior depends on the cluster’s CPU topology, SelectType configuration, and oversubscription policy, so a system with more CPUs per node could satisfy the same request.

    Another example:

    srun -N32 -n16 bash -c "hostname"

    Here we requested 32 nodes but only 16 tasks. Since there are fewer tasks than requested nodes, Slurm reduces the number of nodes used to 16. This matches the documented behavior of srun when the requested node count exceeds the task count:

    Slurm srun reducing a 32-node request to 16 nodes for 16 tasks
    Slurm srun reducing a 32-node request to 16 nodes for 16 tasks

    Another one, if we request a number of nodes that our partition does not have, we’ll have the following error:

    Slurm srun job queued because the requested partition configuration is unavailable
    Slurm srun job queued because the requested partition configuration is unavailable

    In this example, the 50-node request remains PENDING with the reason PartitionConfig, indicating that the request cannot currently be satisfied under the partition configuration or limits:

    Slurm squeue showing a pending job with PartitionConfig reason
    Slurm squeue showing a pending job with PartitionConfig reason

    PD means “Pending”. Under “Nodelist (Reason)”, we can confirm the reason for this job state!

    If you want to learn more, check “Why Is My Slurm Job Pending? How to Decode Every Common Reason“.

    3- Interactive shell on a compute node:

    Another interesting use of “srun” is to acquire an interactive shell from a compute node:

    srun --pty -N1 -n1 bash
    Interactive shell allocated on a Slurm compute node using srun pty
    Interactive shell allocated on a Slurm compute node using srun pty

    As we can see in the previous picture, we’re on the login node, execute “srun”, and then we get the compute node 01 shell (we’re literally on the compute node 01 shell).

    The “squeue” command, for instance, can show the job details:

    Slurm squeue showing the running interactive srun job
    Slurm squeue showing the running interactive srun job

    To finish the job, just type “exit” on the compute node command line:

    Exiting an interactive Slurm srun shell and returning to the login node
    Exiting an interactive Slurm srun shell and returning to the login node

    Note: Look at that after exiting, the job was finished!

    sbatch – Batch Submission (Scripted Jobs)

    With “sbatch”, we write a script, Slurm schedules it, and runs it when resources are free.

    1- Simple batch script:

    Create the file “test.batch” with the following content:

    #!/bin/bash
    #SBATCH --job-name=testjob
    #SBATCH --nodes=1
    #SBATCH --ntasks=1
    #SBATCH --time=00:01:00
    #SBATCH --output=test_%j.out
    
    hostname
    date
    sleep 10

    Important:

    • Resource requests and job options can be defined using #SBATCH directives inside the script or supplied through command-line options. In practice, keeping the main resource requirements inside the script makes the job easier to reproduce and review.
    • Slurm reads the script.
    • Parses all lines starting with “#SBATCH”.
    • Uses them to define:
      • Resources (nodes, tasks, time);
      • Job name;
      • Output files;
      • Account, partition, QOS, etc.

    Without them, Slurm will use defaults, which is dangerous in HPC:

    • Wrong partition;
    • Too little time;
    • Too many CPUs;
    • Job killed;
    • Accounting errors.
    #SBATCH --job-name=
    #SBATCH --account=
    #SBATCH --partition=
    #SBATCH --nodes=
    #SBATCH --ntasks=
    #SBATCH --time=
    #SBATCH --output=

    Submit the job:

    sbatch test.sbatch

    Note: If Slurm rejects the job because of its account or partition association, see “Slurm Invalid Account Error: How to Fix It“.

    Check the job:

    squeue

    As we can confirm in the following picture, the job was submitted using “sbatch”, and the job ID 214 was generated for this job. For each submitted job, Slurm is responsible for generating a unique job ID:

    Slurm sbatch submission returning job ID 214
    Slurm sbatch submission returning job ID 214

    The batch script has the entry “#SBATCH –output=test_%j.out”. With that, a file is generated containing the batch script output:

    Slurm batch job output file generated with the job ID in its filename
    Slurm batch job output file generated with the job ID in its filename

    2- Parallel batch job:

    Create the file “parallel.batch” with the following content:

    #!/bin/bash
    #SBATCH --job-name=parallel
    #SBATCH --nodes=4
    #SBATCH --ntasks=4
    #SBATCH --time=00:05:00
    #SBATCH --output=parallel_%j.out
    
    srun hostname

    Submit the job:

    sbatch parallel.batch

    And check the queue:

    Slurm parallel batch job running on four compute nodes
    Slurm parallel batch job running on four compute nodes

    Lab observation: In this particular execution, Job 216 unexpectedly remained active until it reached its five-minute time limit and was terminated by Slurm. The --time directive defines a maximum runtime; it does not force a job to remain active for that duration. A script containing only srun hostname would normally complete as soon as its tasks finish. If this behavior is reproducible, the job and step state should be investigated separately.

    squeue

    The “squeue” command provides valuable details. Let’s dig into them:

    Slurm squeue columns showing job ID partition state runtime nodes and nodelist
    Slurm squeue columns showing job ID partition state runtime nodes and nodelist

    Afterward, we can check the output file for our parallel job:

    Slurm batch job terminated after reaching its configured maximum time limit
    Slurm batch job terminated after reaching its configured maximum time limit

    Look at the message:

    slurmstepd: error: *** JOB 216 ON hpcnode01 CANCELLED AT 2026-01-16T16:00:30 DUE TO TIME LIMIT ***

    It is expected to see this because we configured the job’s runtime (#SBATCH –time=00:05:00). Slurm sees it and executes the job for this amount of time!

    Key Differences Between srun and sbatch

    Featuresrunsbatch
    Primary purposeLaunch tasks/job stepsSubmit a batch script
    TerminalUsually attachedDetached
    Resource allocationCan create or use an existing allocationCreates a job allocation for the batch script
    If resources unavailableCan wait until resources are availableJob remains queued
    Typical useInteractive work, testing, parallel task launchRepeatable and production batch workloads
    Returns immediately after submissionNo, normally waits for executionYes, after Slurm accepts the script and assigns a Job ID

    What is “salloc”?

    In a basic way, the “salloc” is a command used to allocate resources and obtain an interactive resource allocation that can be used by subsequent srun commands.

    We can think of:

    • srun → run a step
    • salloc → reserve resources
    • sbatch → submit batch job

    Let’s provide you with an example:

    1- Reserve two compute nodes for 10 minutes:

    salloc -N2 -n2 -t 10:00

    The message “salloc: Granted job allocation 218” confirms the allocation of resources. In this case, 218 is the job id assigned for this allocation:

    Slurm salloc command granting interactive job allocation 218
    Slurm salloc command granting interactive job allocation 218

    Now, all “srun” commands will execute using the allocated nodes (in this case, hpcnode01 and hpcnode02). For example:

    Slurm srun commands executing inside an existing salloc resource allocation
    Slurm srun commands executing inside an existing salloc resource allocation

    To terminate the allocation, type “exit”:

    Releasing a Slurm interactive allocation by exiting the salloc shell
    Releasing a Slurm interactive allocation by exiting the salloc shell

    To Wrap This Up: srun vs sbatch vs salloc

    CommandDoes whatTypical usage
    srunRuns one job stepQuick test, one command
    sallocReserves nodes interactivelyDebug session, development
    sbatchSubmits job scriptProduction workloads

    Choosing between srun, sbatch, and salloc becomes easier once you separate resource allocation from task execution. sbatch is normally the right choice for repeatable batch workloads, salloc is useful when you need an interactive allocation, and srun launches tasks either inside an existing allocation or by requesting resources when necessary.

    More importantly, always inspect the job state and scheduler reason instead of assuming that a submitted job should start immediately. Slurm exposes this information directly through tools such as squeue, making job submission and troubleshooting part of the same workflow.

    For additional day-to-day Slurm commands, see “Essential Slurm Administration Commands Every HPC Administrator Should Know“.

    External References

    • Slurm srun Documentation Official SchedMD reference for launching tasks and job steps, requesting resources, and using interactive execution with srun.
    • Slurm sbatch Documentation Official reference for submitting batch scripts, using #SBATCH directives, resource requests, output files, and job time limits.
    • Slurm salloc Documentation Official documentation for obtaining interactive Slurm resource allocations and running commands inside them.
    • Slurm squeue Documentation Reference for inspecting queued and running jobs, job states, allocated nodes, and pending reasons.
    • Slurm Job Reason Codes Official reference for pending reasons including Resources, Priority, PartitionConfig, and other scheduler conditions.
    • Slurm Job State Codes Official definitions for job states such as PENDING, RUNNING, COMPLETED, and TIMEOUT.
    • Slurm Quick Start User Guide SchedMD overview of common user commands and the basic workflow for submitting and monitoring jobs.
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Previous ArticleTroubleshooting NSX Overlay TEP Connectivity from ESXi and Edge Nodes
    Next Article How to Troubleshoot Packet Drops on an ESXi Host
    Danilo Chiacchio
    • LinkedIn

    Infrastructure Engineer with hands-on experience in virtualization, Linux, Windows Server, and enterprise infrastructure troubleshooting. I work with real-world infrastructure environments and technical labs, focusing on diagnosing problems, understanding root causes, and documenting practical solutions. DPC Virtual Tips was created to share hands-on troubleshooting guides, lab experiences, technical procedures, and lessons learned while working with technologies such as VMware, Linux, HPC/Slurm, networking, storage, and infrastructure automation with Python.

    Related Posts

    How to Investigate Jobs Stuck in COMPLETING State on Slurm

    September 8, 2026

    Setting Up a Slurm Cluster in a Lab: Practical Deployment Guide

    August 24, 2026

    Getting Started with Lustre File System

    August 18, 2026
    Leave A Reply Cancel Reply

    Search
    Categories
    • HPC & Slurm (11)
    • Linux & Automation (12)
    • VMware & Virtualization (16)
    Read More
    VMware & Virtualization

    Configure vCenter File-Based Backups to NFS: Practical Lab Guide

    By Danilo ChiacchioSeptember 11, 202610 Mins Read
    Linux & Automation

    Creating Your First Ansible Playbook: A Practical Lab Guide

    By Danilo ChiacchioSeptember 10, 202610 Mins Read
    Linux & Automation

    Linux Commands to Investigate High Disk Partition Usage

    By Danilo ChiacchioSeptember 9, 20267 Mins Read
    HPC & Slurm

    How to Investigate Jobs Stuck in COMPLETING State on Slurm

    By Danilo ChiacchioSeptember 8, 202612 Mins Read
    VMware & Virtualization

    Restoring vCenter Server from a File-Based Backup: Practical Lab Walkthrough

    By Danilo ChiacchioSeptember 7, 20269 Mins Read
    Latest Posts

    Configure vCenter File-Based Backups to NFS: Practical Lab Guide

    September 11, 2026

    Creating Your First Ansible Playbook: A Practical Lab Guide

    September 10, 2026

    Linux Commands to Investigate High Disk Partition Usage

    September 9, 2026
    Images from Gallery
    hpc main commands
    linux commands
    install rock linux
    lustre fs
    shell scripting
    vSAN Trace Files
    Categories
    • HPC & Slurm
    • Linux & Automation
    • VMware & Virtualization
    • Home
    • About Us
    • Contact
    • Cookie Policy
    • Comment Policy
    • Privacy Policy
    • Terms of Use
    Copyright © 2026, DPC Virtual Tips. All rights reserved.

    Type above and press Enter to search. Press Esc to cancel.

    We use cookies to improve your browsing experience, analyze website traffic, and display relevant advertising. You can accept all cookies or manage your preferences at any time.