LinuxCommandLibrary

sbatch

Submit batch jobs to Slurm

TLDR

Submit a batch job

$ sbatch [path/to/job.sh]
copy

Submit a batch job with a custom name
$ sbatch --job-name=[myjob] [path/to/job.sh]
copy

Submit a batch job with a time limit of 30 minutes
$ sbatch --time=[00:30:00] [path/to/job.sh]
copy

Submit a job and request multiple nodes
$ sbatch --nodes=[3] [path/to/job.sh]
copy

SYNOPSIS


sbatch [OPTIONS] <script_name> [<script_arguments>]
sbatch [OPTIONS] --wrap="<command_string>"

PARAMETERS

--account, -A
    Charge resources used by this job to account.

--array=
    Submit a job array with task IDs specified by indexes (e.g., 0-9, 1,3,5).

--chdir, -D
    Set the working directory of the batch script to directory.

--cpus-per-task, -c
    Request count CPUs per task.

--constraint, -C
    Request nodes with specific features (e.g., 'GPU&K20').

--dependency, -d
    Defer the start of this job until dependency_list (e.g., 'afterok:1234') is satisfied.

--error, -e
    Redirect stderr to filepath. Formats like %j (job ID) can be used.

--export=
    Control which environment variables are exported to the job. Common values: ALL, NONE, VAR1,VAR2.

--exclusive
    Allocate nodes exclusively to this job.

--job-name, -J
    Specify a name for the job.

--mail-type=
    Notify user by email when type of event occurs (e.g., BEGIN, END, FAIL, ALL).

--mail-user=
    Send email notifications to email_address.

--mem=
    Request memory (e.g., 10G for 10 Gigabytes) per node or per CPU. Suffixes like M, G, T are supported.

--nodes, -N
    Request min_nodes[-max_nodes] to be allocated for the job.

--ntasks, -n
    Request count tasks for the job.

--output, -o
    Redirect stdout to filepath. Formats like %j (job ID) can be used.

--partition, -p
    Request a specific partition (queue) for the job.

--time=
    Set a time limit for the job execution, e.g., DD-HH:MM:SS, HH:MM:SS, MM.

--wrap=""
    Submit the command_string as a job, bypassing the need for a script file.

--wait
    Block until the submitted job completes.

DESCRIPTION


The sbatch command is a fundamental utility within the Slurm Workload Manager, designed to submit a job script for asynchronous execution on a cluster. It serves as the primary mechanism for users to convey their computational tasks and their resource requirements—such as CPU cores, memory, time limits, and specific nodes—to the Slurm scheduler. Unlike srun, which is used for interactive or synchronous job execution, sbatch queues jobs to run non-interactively when the requested resources become available. This makes it an indispensable tool for long-running, high-throughput computing, and scientific simulations that do not require immediate user interaction. A typical sbatch job involves creating a shell script containing the commands to be executed, often prefaced with special #SBATCH directives that instruct Slurm on various job parameters like partition, output files, and dependencies.

CAVEATS

Job parameters specified on the command line override those specified in #SBATCH directives within the script.
sbatch only submits the job; it does not execute the job script directly or immediately.
Jobs may queue for extended periods depending on available resources and cluster policy.
It is not suitable for interactive sessions; use srun for such purposes.

<I>#SBATCH</I> DIRECTIVES

Job scripts often begin with lines like #SBATCH --nodes=1 or #SBATCH --time=01:00:00. These directives provide a way to specify job parameters directly within the script file, making scripts self-contained and reproducible. sbatch parses these lines and applies the requested resources. Command-line options take precedence over these directives.

JOB SUBMISSION OUTPUT

Upon successful submission, sbatch prints a job ID to standard output, typically in the format Submitted batch job <JOB_ID>. This ID is crucial for monitoring, cancelling, or querying the job's status using other Slurm commands like squeue or scancel.

HISTORY

Slurm, and by extension sbatch, emerged as a modern, open-source workload manager to address the evolving needs of high-performance computing clusters. It was developed to replace older systems like PBS Pro and Torque, offering improved scalability, flexibility, and features for managing complex computational workflows. sbatch has been a core component since Slurm's inception, providing the standard mechanism for users to submit batch jobs to the cluster. Its design reflects the common requirement in HPC environments to queue and execute non-interactive tasks efficiently.

SEE ALSO

srun(1), squeue(1), scancel(1), sinfo(1), sstat(1), sacct(1)

Copied to clipboard