Difference between revisions of "Submitting a job to a slurm queue"

From HPC Guide
Jump to navigation Jump to search
Line 1: Line 1:
==submit commands==
+
SLURM (Simple Linux Utility for Resource Management) is a job scheduler used on many high-performance computing systems. It manages and allocates resources such as compute nodes and controls job execution.
'''sbatch''' - submits script
 
  
'''salloc''' - submit interactive job - allocates what it needs, but will not start to work on the node/s
+
=== Accessing the System ===
 +
To submit jobs to the SLURM scheduler at Tel Aviv University, you must access the system through one of the designated login nodes. These nodes act as the gateway for submitting and managing your SLURM jobs. The available login nodes are:
  
'''srun''' - submits interactive job w mpi ("job step")
+
* <code>powerslurm-login.tau.ac.il</code>
 +
* <code>powerslurm-login2.tau.ac.il</code>
  
'''sattach''' - connect stdin/out/err for an existing job (or job step)
+
==== Login Requirements: ====
  
So for example, may submit a job with command:
+
# Membership in the "power" group: Ensure you are a part of the "power" group which grants the necessary permissions for accessing the HPC resources.
<pre>
+
# University Credentials: Log in using your Tel Aviv University credentials. This ensures secure access and that your job submissions are appropriately accounted for under your user profile.
sbatch script.sh
 
</pre>
 
  
===Examples===
+
Remember, these login nodes are the initial point of contact for all your job management tasks, including job submission, monitoring, and other SLURM-related operations.
'''sbatch'''
 
<pre>
 
sbatch --ntasks=1 --time=10 pre_process.bash (time is 10 minutes)
 
(Submitted batch job 45001)
 
sbatch --ntasks=128 --time=60 --depend=45001 do_work.bash
 
(Submitted batch job 45002)
 
sbatch --ntasks=1 --time=30 --depend=45002 post_process.bash
 
(Submitted batch job 45003)
 
</pre>
 
  
'''srun'''
+
=== Basic Job Submission Commands ===
<pre>
 
srun -intasks=2 --label hostname  (--label means that before the output line write the task id)
 
  0:compute-0-1
 
  1:compute-0-1
 
</pre>
 
  
Using 2 nodes:
+
# sbatch: Submit a batch job script.
<pre>
+
#* Example: <code>sbatch --ntasks=1 --time=10 pre_process.bash</code>
srun -innodes=2 --exclusive --label hostname
+
#* This submits <code>pre_process.bash</code> with 1 task for 10 minutes.
  0:compute-0-1
+
#* Example of chaining jobs: <code>sbatch --ntasks=128 --time=60 --depend=45001 do_work.bash</code>
  1:compute-0-2
+
# salloc: Allocate resources for an interactive job but doesn't start it immediately.
</pre>
+
#* Example: <code>salloc --ntasks=8 --time=10 bash</code>
 +
# srun: Submit an interactive job with MPI (Message Passing Interface), often called a "job step."
 +
#* Example: <code>srun --ntasks=2 --label hostname</code>
 +
#* With MPI: <code>srun -intasks=2 --label hostname</code>
 +
# sattach: Attach stdin/out/err to an existing job or job step.
  
opening bash
+
=== Interactive Job Examples ===
<pre>
 
srun --ntasks=56 --pty bash
 
[dolevg@compute-0-12 beta16.dvory]$....
 
</pre>
 
  
On some slurm clusters need also to specify resources (as in powerslurm), w/o them, the qsub would fail, as in:
+
* Opening a bash shell: <code>srun --ntasks=56 --pty bash</code>
<pre>
+
* Specifying compute nodes: <code>srun --ntasks=56 -p gcohen_2018 --nodelist="compute-0-12" --pty bash</code>
[sagish@powerslurm ~]$ srun --pty bash -p power-yoren
 
srun: error: Unable to allocate resources: No partition specified or system default partition
 
[sagish@powerslurm ~]$
 
</pre>
 
<pre>
 
[dvory@powerslurm-login ~]$ srun --pty -c 1 --mem=2G -p power-yoren /bin/bash
 
[dvory@compute-0-62 ~]$
 
</pre>
 
  
Specifying compute node (which is available)
+
=== Script Example: ===
<pre>
+
<syntaxhighlight lang="bash">
srun --ntasks=56 -p gcohen_2018 --nodelist="compute-0-12" --pty bash
+
#!/bin/bash
</pre>
 
  
See available nodes:
+
#SBATCH --job-name=my_job            # Job name
'''salloc'''
+
#SBATCH --account=my_account          # Account name for billing
<pre>
+
#SBATCH --partition=long              # Partition name
salloc --ntasks=8 --time=10 bash
+
#SBATCH --time=02:00:00              # Time allotted for the job (hh:mm:ss)
salloc: Granted job allocation 45000
+
#SBATCH --ntasks=4                    # Number of tasks (processes)
(gives us a bash prompts of a node:)
+
#SBATCH --cpus-per-task=1            # Number of CPU cores per task
</pre>
+
#SBATCH --mem-per-cpu=4G              # Memory per CPU core
<pre>
+
#SBATCH --output=my_job_%j.out        # Standard output and error log (%j expands to jobId)
env | grep SLURM
+
#SBATCH --error=my_job_%j.err        # Separate file for standard error
  SLURM_JOBID=45000
 
  SLURM_NPROCS=4
 
  SLURM_JOB_NODELIST=compute-0-1,compute-0-2
 
</pre>
 
  
<pre>
+
# Load modules or software if required
srun --label hostname
+
# module load python/3.8
  0:compute-0-1
 
  1:compute-0-1
 
  2:compute-0-2
 
  3:compute-0-2
 
exit (terminates the shell)
 
</pre>
 
  
==info commands==
+
# Print some information about the job
'''sinfo'''    -- to see all queues (partitions)
+
echo "Starting my SLURM job"
 +
echo "Job ID: $SLURM_JOB_ID"
 +
echo "Running on nodes: $SLURM_JOB_NODELIST"
 +
echo "Allocated CPUs: $SLURM_JOB_CPUS_PER_NODE"
  
'''squeue'''  -- to see all jobs
+
# Run your application, this could be anything from a custom script to standard applications
 +
# ./my_program
 +
# python my_script.py
  
'''scontrol show partition'''    -- to see all partitions
+
# End of script
 +
echo "Job completed"
  
'''scontrol show job <number>'''  -- to see job's attributes
+
</syntaxhighlight>
 +
 
 +
=== Error Handling ===
 +
 
 +
* On some clusters, specifying resources is necessary. Without them, the job may fail.
 +
** Example error: <code>srun: error: Unable to allocate resources: No partition specified or system default partition</code>
 +
** Correct usage: <code>srun --pty -c 1 --mem=2G -p power-yoren /bin/bash</code>
 +
 
 +
=== SLURM Information Commands ===
 +
 
 +
* sinfo: View all queues (partitions).
 +
* squeue: View all jobs.
 +
* scontrol show partition: View all partitions.
 +
* scontrol show job <job_number>: View a job's attributes.
 +
 
 +
=== Tips for Managing SLURM Jobs ===
 +
 
 +
* Chain jobs by using the <code>--depend</code> flag in <code>sbatch</code>.
 +
* Use <code>salloc</code> for interactive jobs that require specific resources for a limited time.
 +
* <code>srun</code> is versatile for both interactive and batch jobs, especially with MPI.
 +
* Always specify necessary resources in clusters where defaults are not set.

Revision as of 14:04, 17 January 2024

SLURM (Simple Linux Utility for Resource Management) is a job scheduler used on many high-performance computing systems. It manages and allocates resources such as compute nodes and controls job execution.

Accessing the System

To submit jobs to the SLURM scheduler at Tel Aviv University, you must access the system through one of the designated login nodes. These nodes act as the gateway for submitting and managing your SLURM jobs. The available login nodes are:

  • powerslurm-login.tau.ac.il
  • powerslurm-login2.tau.ac.il

Login Requirements:

  1. Membership in the "power" group: Ensure you are a part of the "power" group which grants the necessary permissions for accessing the HPC resources.
  2. University Credentials: Log in using your Tel Aviv University credentials. This ensures secure access and that your job submissions are appropriately accounted for under your user profile.

Remember, these login nodes are the initial point of contact for all your job management tasks, including job submission, monitoring, and other SLURM-related operations.

Basic Job Submission Commands

  1. sbatch: Submit a batch job script.
    • Example: sbatch --ntasks=1 --time=10 pre_process.bash
    • This submits pre_process.bash with 1 task for 10 minutes.
    • Example of chaining jobs: sbatch --ntasks=128 --time=60 --depend=45001 do_work.bash
  2. salloc: Allocate resources for an interactive job but doesn't start it immediately.
    • Example: salloc --ntasks=8 --time=10 bash
  3. srun: Submit an interactive job with MPI (Message Passing Interface), often called a "job step."
    • Example: srun --ntasks=2 --label hostname
    • With MPI: srun -intasks=2 --label hostname
  4. sattach: Attach stdin/out/err to an existing job or job step.

Interactive Job Examples

  • Opening a bash shell: srun --ntasks=56 --pty bash
  • Specifying compute nodes: srun --ntasks=56 -p gcohen_2018 --nodelist="compute-0-12" --pty bash

Script Example:

#!/bin/bash

#SBATCH --job-name=my_job             # Job name
#SBATCH --account=my_account          # Account name for billing
#SBATCH --partition=long              # Partition name
#SBATCH --time=02:00:00               # Time allotted for the job (hh:mm:ss)
#SBATCH --ntasks=4                    # Number of tasks (processes)
#SBATCH --cpus-per-task=1             # Number of CPU cores per task
#SBATCH --mem-per-cpu=4G              # Memory per CPU core
#SBATCH --output=my_job_%j.out        # Standard output and error log (%j expands to jobId)
#SBATCH --error=my_job_%j.err         # Separate file for standard error

# Load modules or software if required
# module load python/3.8

# Print some information about the job
echo "Starting my SLURM job"
echo "Job ID: $SLURM_JOB_ID"
echo "Running on nodes: $SLURM_JOB_NODELIST"
echo "Allocated CPUs: $SLURM_JOB_CPUS_PER_NODE"

# Run your application, this could be anything from a custom script to standard applications
# ./my_program
# python my_script.py

# End of script
echo "Job completed"

Error Handling

  • On some clusters, specifying resources is necessary. Without them, the job may fail.
    • Example error: srun: error: Unable to allocate resources: No partition specified or system default partition
    • Correct usage: srun --pty -c 1 --mem=2G -p power-yoren /bin/bash

SLURM Information Commands

  • sinfo: View all queues (partitions).
  • squeue: View all jobs.
  • scontrol show partition: View all partitions.
  • scontrol show job <job_number>: View a job's attributes.

Tips for Managing SLURM Jobs

  • Chain jobs by using the --depend flag in sbatch.
  • Use salloc for interactive jobs that require specific resources for a limited time.
  • srun is versatile for both interactive and batch jobs, especially with MPI.
  • Always specify necessary resources in clusters where defaults are not set.