How to use the command sbatch (with examples)
- Linux
- November 5, 2023
The sbatch
command is used to submit batch jobs to the SLURM scheduler. SLURM is a workload manager that allocates computing resources on a cluster. By using the sbatch
command, users can submit their job scripts to the scheduler, which will schedule and manage the execution of these jobs on the cluster.
Use case 1: Submit a batch job
Code:
sbatch path/to/job.sh
Motivation:
The motivation for using this example is to submit a batch job to the SLURM scheduler for execution. This is useful when you have a job script that you want to run on the cluster.
Explanation:
sbatch
: This is the command used to submit batch jobs to the SLURM scheduler.path/to/job.sh
: This is the path to the job script that you want to submit. The job script contains the commands and instructions for the job that you want to run.
Example Output:
When the command sbatch path/to/job.sh
is executed, the output will be the job ID assigned to the submitted job. For example, the output could be Submitted batch job 123456
.
Use case 2: Submit a batch job with a custom name
Code:
sbatch --job-name=myjob path/to/job.sh
Motivation:
The motivation for using this example is to assign a custom name to a batch job. This can be useful for easier identification and organization of jobs running on the cluster.
Explanation:
--job-name=myjob
: This argument is used to specify a custom name for the job. The name should be provided after the--job-name=
option.
Example Output:
When the command sbatch --job-name=myjob path/to/job.sh
is executed, the output will be the job ID assigned to the submitted job. For example, the output could be Submitted batch job 123456
.
Use case 3: Submit a batch job with a time limit of 30 minutes
Code:
sbatch --time=00:30:00 path/to/job.sh
Motivation:
The motivation for using this example is to set a time limit for the execution of a batch job. This can be useful when you need to ensure that your job does not run indefinitely and exceeds a specific time duration.
Explanation:
--time=00:30:00
: This argument is used to specify the time limit for the job. The time is specified in the format of “hours:minutes:seconds”. In this example, the time limit is set to 30 minutes.
Example Output:
When the command sbatch --time=00:30:00 path/to/job.sh
is executed, the output will be the job ID assigned to the submitted job. For example, the output could be Submitted batch job 123456
.
Use case 4: Submit a job and request multiple nodes
Code:
sbatch --nodes=3 path/to/job.sh
Motivation:
The motivation for using this example is to request multiple nodes for the execution of a batch job. This can be useful when your job requires more computational resources and would benefit from parallel processing across multiple nodes.
Explanation:
--nodes=3
: This argument is used to request a specific number of nodes for the job. In this example, we request 3 nodes.
Example Output:
When the command sbatch --nodes=3 path/to/job.sh
is executed, the output will be the job ID assigned to the submitted job. For example, the output could be Submitted batch job 123456
.
Conclusion
In this article, we have explored different use cases of the sbatch
command. We have seen how to submit a batch job, assign a custom name to a job, set a time limit for a job, and request multiple nodes for a job. Understanding these use cases will help users effectively utilize the sbatch
command and submit their jobs to the SLURM scheduler.