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

From HPC Guide
Jump to navigation Jump to search
Line 1: Line 1:
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 ==
  
=== Accessing the System ===
+
To submit jobs to SLURM at Tel Aviv University, you need to access the system through one of the following login nodes:
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:
 
  
* <code>powerslurm-login.tau.ac.il</code>
+
* powerslurm-login.tau.ac.il
* <code>powerslurm-login2.tau.ac.il</code>
+
* powerslurm-login2.tau.ac.il
  
==== Login Requirements: ====
+
=== Requirements for Access ===
  
# Membership in the "power" group: Ensure you are a part of the "power" group which grants the necessary permissions for accessing the HPC resources.
+
* '''Group Membership''': You must be part of the "power" group to access the resources.
# 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.
+
* '''University Credentials''': Use your Tel Aviv University username and password to log in.
  
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.
+
These login nodes are your starting point for submitting jobs, checking job status, and managing your SLURM tasks.
  
=== Basic Job Submission Commands ===
+
=== SSH Example ===
====Finding your account and partition====
 
In order to submit jobs to slurm, one needs to know the accounts and partitions she belongs to. Each account may belong to one or more partitions.
 
  
To see the account I belong to, please type:
+
To access the system using SSH, use the following example:
<pre>
 
sacctmgr show associations where user=dvory format=Account%20
 
</pre>
 
If you know your partition, and would like to know which account you need to specify when using it, please do (on powerslurm-login)
 
<pre>
 
check_allowed_account -p <partition>
 
</pre>
 
For example:
 
<pre>
 
check_allowed_account -p power-general
 
</pre>
 
  
====Example for submitting jobs====
+
<syntaxhighlight lang="bash">
# sbatch: Submit a batch job script.
+
# Replace 'your_username' with your actual Tel Aviv University username
#* Example: <code>sbatch --ntasks=1 --time=10 -p power-general -A power-general-users pre_process.bash</code>
+
ssh your_username@powerslurm-login.tau.ac.il
#* This submits <code>pre_process.bash</code> with 1 task for 10 minutes.
+
</syntaxhighlight>
#* Example of chaining jobs: <code>sbatch --ntasks=128 --time=60 -p power-general -A power-general-users --depend=45001 do_work.bash</code>
+
 
#* Example with GPU: <code>sbatch --ntasks=1 --time=10 --gres=gpu:2 -p gpu-general -A gpu-general-users pre_process.bash</code> or <code>sbatch --gres=gpu:1 -p gpu-general -A gpu-general-users gpu_job.sh</code>  
+
If you want to connect to the second login node, use:
# srun: Submit an interactive job with MPI (Message Passing Interface), often called a "job step."
+
 
#* Example: <code>srun --ntasks=2 -p power-general -A power-general-users --label hostname</code>
+
<syntaxhighlight lang="bash">
#* With MPI: <code>srun -intasks=2 -p power-general -A power-general-users --label hostname</code>
+
# Replace 'your_username' with your actual Tel Aviv University username
# sattach: Attach stdin/out/err to an existing job or job step.
+
ssh your_username@powerslurm-login2.tau.ac.il
 +
</syntaxhighlight>
  
=== Interactive Job Examples ===
+
If you have an SSH key set up for password-less login, you can specify it like this:
* Opening a bash shell: <code>srun --ntasks=56 -p power-general -A power-general-users  --pty bash</code>
 
* Specifying compute nodes: <code>srun --ntasks=56 -p power-general -A power-general-users --nodelist="compute-0-12" --pty bash</code>
 
* Using GUI: <code>srun --ntasks=56 -p power-general -A power-general-users --x11 /bin/bash</code>
 
  
=== Script Examples: ===
+
<syntaxhighlight lang="bash">
 +
# Replace 'your_username' and '/path/to/your/private_key' accordingly
 +
ssh -i /path/to/your/private_key your_username@powerslurm-login.tau.ac.il
 +
</syntaxhighlight>
 +
 
 +
== Environment Modules ==
 +
 
 +
Environment Modules in SLURM allow users to dynamically modify their shell environment, providing an easy way to load and unload different software applications, libraries, and their dependencies. This system helps avoid conflicts between software versions and ensures the correct environment for running specific applications.
 +
 
 +
Here are some common commands to work with environment modules:<syntaxhighlight lang="bash">
 +
#List Available Modules: To see all the modules available on the system, use:
 +
module avail
 +
 
 +
#To search for a specific module by name (e.g., `gcc`), use:
 +
module avail gcc/gcc-12.1.0
 +
 
 +
#Get Detailed Information About a Module: The `module spider` command provides detailed information about a module, including versions, dependencies, and descriptions:
 +
module spider gcc/gcc-12.1.0
 +
 
 +
#View Module Settings: To see what environment variables and settings will be modified by a module, use:
 +
module show gcc/gcc-12.1.0
 +
 
 +
#Load a Module: To set up the environment for a specific software, use the `module load` command. For example, to load GCC version 12.1.0:
 +
module load gcc/gcc-12.1.0
 +
 
 +
#List Loaded Modules: To view all currently loaded modules in your session, use:
 +
module list
 +
 
 +
#Unload a Module: To unload a specific module from your environment, use:
 +
module unload gcc/gcc-12.1.0
 +
 
 +
#Unload All Modules:** If you need to clear your environment of all loaded modules, use:
 +
module purge
 +
 
 +
</syntaxhighlight>By using these commands, you can easily manage the software environments needed for different tasks, ensuring compatibility and reducing potential conflicts between software versions.
 +
 
 +
== Basic Job Submission Commands ==
 +
 
 +
=== Finding Your Account and Partition ===
 +
 
 +
Before submitting a job, you need to know which partitions you have permission to use.
 +
 
 +
Run the command `<code>check_my_partitions</code>` to view a list of all the partitions you have permission to send jobs to.
 +
 
 +
== Submitting Jobs==
 +
sbatch: Submits a job script for batch processing.
 +
 
 +
'''Example''':<syntaxhighlight lang="bash">
 +
 
 +
 
 +
    sbatch --ntasks=1 --time=10 -p power-general -A power-general-users pre_process.bash
 +
  # This command submits pre_process.bash to the power-general partition for 10 minutes.
 +
  # With 1 GPU:
 +
    sbatch --gres=gpu:1 -p gpu-general -A gpu-general-users gpu_job.sh
 +
 
 +
 
 +
</syntaxhighlight>
 +
 
 +
===Writing SLURM Job Scripts===
 +
 
 +
Here is a simple job script example:
 +
 
 +
==== Basic Script====
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
#!/bin/bash
 
#!/bin/bash
 
 
#SBATCH --job-name=my_job            # Job name
 
#SBATCH --job-name=my_job            # Job name
#SBATCH --account=power-general-users # Account name for billing
+
#SBATCH --account=power-general-users # Account name
 
#SBATCH --partition=power-general    # Partition name
 
#SBATCH --partition=power-general    # Partition name
#SBATCH --time=02:00:00              # Time allotted for the job (hh:mm:ss)
+
#SBATCH --time=02:00:00              # Max run time (hh:mm:ss)
#SBATCH --ntasks=4                   # Number of tasks (processes)
+
#SBATCH --ntasks=1                   # Number of tasks
#SBATCH --cpus-per-task=1            # Number of CPU cores per task
+
#SBATCH --cpus-per-task=1            # CPUs per task
#SBATCH --mem-per-cpu=4G              # Memory per CPU core
+
#SBATCH --mem-per-cpu=4G              # Memory per CPU
#SBATCH --output=my_job_%j.out        # Standard output and error log (%j expands to jobId)
+
#SBATCH --output=my_job_%j.out        # Output file
#SBATCH --error=my_job_%j.err        # Separate file for standard error
+
#SBATCH --error=my_job_%j.err        # Error file
 
 
# Load modules or software if required
 
# module load python/python-3.8
 
  
# Print some information about the job
 
 
echo "Starting my SLURM job"
 
echo "Starting my SLURM job"
 
echo "Job ID: $SLURM_JOB_ID"
 
echo "Job ID: $SLURM_JOB_ID"
Line 70: Line 111:
 
echo "Allocated CPUs: $SLURM_JOB_CPUS_PER_NODE"
 
echo "Allocated CPUs: $SLURM_JOB_CPUS_PER_NODE"
  
# Run your application, this could be anything from a custom script to standard applications
+
# Your application commands go here
 
# ./my_program
 
# ./my_program
# python my_script.py
 
  
# End of script
 
 
echo "Job completed"
 
echo "Job completed"
 
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==== Script example with GPU ====
+
==== Script for 1 GPU ====
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
#!/bin/bash
 
#!/bin/bash
 +
#SBATCH --job-name=gpu_job            # Job name
 +
#SBATCH --account=my_account          # Account name
 +
#SBATCH --partition=gpu-general        # Partition name
 +
#SBATCH --time=02:00:00                # Max run time
 +
#SBATCH --ntasks=1                    # Number of tasks
 +
#SBATCH --cpus-per-task=1              # CPUs per task
 +
#SBATCH --gres=gpu:1                  # Number of GPUs
 +
#SBATCH --mem-per-cpu=4G              # Memory per CPU
 +
#SBATCH --output=my_job_%j.out        # Output file
 +
#SBATCH --error=my_job_%j.err          # Error file
  
#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 --gres=gpu:NUMBER_OF_GPUS    # number of GPU's to use in the job
 
#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/python-3.8
 
module load python/python-3.8
  
# Print some information about the job
+
echo "Starting GPU job"
echo "Starting my SLURM job"
 
 
echo "Job ID: $SLURM_JOB_ID"
 
echo "Job ID: $SLURM_JOB_ID"
 
echo "Running on nodes: $SLURM_JOB_NODELIST"
 
echo "Running on nodes: $SLURM_JOB_NODELIST"
 
echo "Allocated CPUs: $SLURM_JOB_CPUS_PER_NODE"
 
echo "Allocated CPUs: $SLURM_JOB_CPUS_PER_NODE"
  
# Run your application, this could be anything from a custom script to standard applications
+
# Your GPU commands go here
# ./my_program
 
# python my_script.py
 
  
# End of script
 
 
echo "Job completed"
 
echo "Job completed"
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Example with GUI
+
===Interactive Jobs===
 +
<syntaxhighlight lang="bash">
 +
#Start an interactive session:
 +
srun --ntasks=1 -p power-general -A power-general-users --pty bash
 +
 
 +
#Specify a compute node:
 +
srun --ntasks=1 -p power-general -A power-general-users --nodelist="compute-0-12" --pty bash
 +
 
 +
#Using GUI:
 +
srun --ntasks=1 -p power-general -A power-general-users --x11 /bin/bash
 +
 
 +
</syntaxhighlight>
 +
 
 +
=== Submitting RELION Jobs===
 +
 
 +
To submit a RELION job interactively on the <code>gpu-relion</code> queue with X11 forwarding, use the following steps:<syntaxhighlight lang="bash">
 +
#Start an interactive session with X11:
 +
srun --ntasks=1 -p gpu-relion -A your_account --x11 --pty bash
 +
#Load the RELION module:
 +
module load relion/relion-4.0.1
 +
#Launch RELION:
 +
relion
 +
 
 +
</syntaxhighlight>
 +
 
 +
==AlphaFold==
 +
 
 +
AlphaFold is a deep learning tool designed for predicting protein structures.
 +
 
 +
'''Guide:''' 
 +
[https://hpcguide.tau.ac.il/index.php?title=Alphafold AlphaFold Guide]
 +
 
 +
==Common SLURM Commands==
 +
<syntaxhighlight lang="bash">
 +
#View all queues (partitions):
 +
sinfo
 +
#View all jobs:
 +
squeue
 +
#View details of a specific job:
 +
scontrol show job <job_number>
 +
#Get information about partitions:
 +
scontrol show partition
 +
</syntaxhighlight>
 +
 
 +
== Troubleshooting & Tips ==
 +
 
 +
'''Common Error:'''
 +
<syntaxhighlight lang="bash">
 +
srun: error: Unable to allocate resources: No partition specified or system default partition
 +
</syntaxhighlight>
 +
 
 +
'''Solution:''' Always specify a partition. Example:
 +
 
 +
<syntaxhighlight lang="bash">
 +
srun --pty -c 1 --mem=2G -p power-general /bin/bash
 +
</syntaxhighlight>
 +
 
 +
'''Chain Jobs:''' Use the <code>--depend</code> flag to set job dependencies.
 +
 
 +
'''Example:'''
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 +
sbatch --ntasks=1 --time=60 -p power-general -A power-general-users --depend=45001 do_work.bash
 +
</syntaxhighlight>
  
srun  --pty -c 1 --mem=2G -p <power-xxx> --x11 /bin/bash
+
'''Always Specify Resources:''' When submitting jobs, ensure you include all required resources like partition, memory, and CPUs to avoid job failures.
  
 +
'''Attaching to Running Jobs:''' If you need to monitor or interact with a running job, use <code>sattach</code>. This command allows you to attach to a job's input, output, and error streams in real-time.
 +
 +
'''Example:'''
 +
<syntaxhighlight lang="bash">
 +
sattach <job_id>
 
</syntaxhighlight>
 
</syntaxhighlight>
  
=== Error Handling ===
+
To view job steps of a specific job, use the following command:
* 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>
 
* Be aware that specifying GPU resources is crucial for jobs
 
  
=== SLURM Information Commands ===
+
<syntaxhighlight lang="bash">
 +
scontrol show job <job_id>
 +
</syntaxhighlight>
 +
 
 +
Look for sections labeled "StepId" within the output.
  
* sinfo: View all queues (partitions).
+
'''For specific job steps, use:'''
* squeue: View all jobs.
+
<syntaxhighlight lang="bash">
* scontrol show partition: View all partitions.
+
sattach <job_id.step_id>
* scontrol show job <job_number>: View a job's attributes.
+
</syntaxhighlight>
  
=== Tips for Managing SLURM Jobs ===
+
'''Note:''' <code>sattach</code> is particularly useful for interactive jobs, where you can provide input directly. For non-interactive jobs, it acts like <code>tail -f</code>, allowing you to monitor the output stream.
  
* Chain jobs by using the <code>--depend</code> flag in <code>sbatch</code>.
+
This guide provides the essentials for new users to get started with SLURM. For more complex tasks, refer to the full SLURM documentation or contact your system administrator.
* 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 10:42, 19 September 2024

Accessing the System

To submit jobs to SLURM at Tel Aviv University, you need to access the system through one of the following login nodes:

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

Requirements for Access

  • Group Membership: You must be part of the "power" group to access the resources.
  • University Credentials: Use your Tel Aviv University username and password to log in.

These login nodes are your starting point for submitting jobs, checking job status, and managing your SLURM tasks.

SSH Example

To access the system using SSH, use the following example:

# Replace 'your_username' with your actual Tel Aviv University username
ssh your_username@powerslurm-login.tau.ac.il

If you want to connect to the second login node, use:

# Replace 'your_username' with your actual Tel Aviv University username
ssh your_username@powerslurm-login2.tau.ac.il

If you have an SSH key set up for password-less login, you can specify it like this:

# Replace 'your_username' and '/path/to/your/private_key' accordingly
ssh -i /path/to/your/private_key your_username@powerslurm-login.tau.ac.il

Environment Modules

Environment Modules in SLURM allow users to dynamically modify their shell environment, providing an easy way to load and unload different software applications, libraries, and their dependencies. This system helps avoid conflicts between software versions and ensures the correct environment for running specific applications.

Here are some common commands to work with environment modules:

#List Available Modules: To see all the modules available on the system, use:
module avail

#To search for a specific module by name (e.g., `gcc`), use:
module avail gcc/gcc-12.1.0

#Get Detailed Information About a Module: The `module spider` command provides detailed information about a module, including versions, dependencies, and descriptions:
module spider gcc/gcc-12.1.0

#View Module Settings: To see what environment variables and settings will be modified by a module, use:
module show gcc/gcc-12.1.0

#Load a Module: To set up the environment for a specific software, use the `module load` command. For example, to load GCC version 12.1.0:
module load gcc/gcc-12.1.0

#List Loaded Modules: To view all currently loaded modules in your session, use:
module list

#Unload a Module: To unload a specific module from your environment, use:
module unload gcc/gcc-12.1.0

#Unload All Modules:** If you need to clear your environment of all loaded modules, use:
module purge

By using these commands, you can easily manage the software environments needed for different tasks, ensuring compatibility and reducing potential conflicts between software versions.

Basic Job Submission Commands

Finding Your Account and Partition

Before submitting a job, you need to know which partitions you have permission to use.

Run the command `check_my_partitions` to view a list of all the partitions you have permission to send jobs to.

Submitting Jobs

sbatch: Submits a job script for batch processing.

Example:

    sbatch --ntasks=1 --time=10 -p power-general -A power-general-users pre_process.bash
   # This command submits pre_process.bash to the power-general partition for 10 minutes. 
   # With 1 GPU:
    sbatch --gres=gpu:1 -p gpu-general -A gpu-general-users gpu_job.sh

Writing SLURM Job Scripts

Here is a simple job script example:

Basic Script

#!/bin/bash
#SBATCH --job-name=my_job             # Job name
#SBATCH --account=power-general-users # Account name
#SBATCH --partition=power-general     # Partition name
#SBATCH --time=02:00:00               # Max run time (hh:mm:ss)
#SBATCH --ntasks=1                    # Number of tasks
#SBATCH --cpus-per-task=1             # CPUs per task
#SBATCH --mem-per-cpu=4G              # Memory per CPU
#SBATCH --output=my_job_%j.out        # Output file
#SBATCH --error=my_job_%j.err         # Error file

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"

# Your application commands go here
# ./my_program

echo "Job completed"

Script for 1 GPU

#!/bin/bash
#SBATCH --job-name=gpu_job             # Job name
#SBATCH --account=my_account           # Account name
#SBATCH --partition=gpu-general        # Partition name
#SBATCH --time=02:00:00                # Max run time
#SBATCH --ntasks=1                     # Number of tasks
#SBATCH --cpus-per-task=1              # CPUs per task
#SBATCH --gres=gpu:1                   # Number of GPUs
#SBATCH --mem-per-cpu=4G               # Memory per CPU
#SBATCH --output=my_job_%j.out         # Output file
#SBATCH --error=my_job_%j.err          # Error file

module load python/python-3.8

echo "Starting GPU job"
echo "Job ID: $SLURM_JOB_ID"
echo "Running on nodes: $SLURM_JOB_NODELIST"
echo "Allocated CPUs: $SLURM_JOB_CPUS_PER_NODE"

# Your GPU commands go here

echo "Job completed"

Interactive Jobs

#Start an interactive session:
srun --ntasks=1 -p power-general -A power-general-users --pty bash

#Specify a compute node:
srun --ntasks=1 -p power-general -A power-general-users --nodelist="compute-0-12" --pty bash

#Using GUI:
srun --ntasks=1 -p power-general -A power-general-users --x11 /bin/bash

Submitting RELION Jobs

To submit a RELION job interactively on the gpu-relion queue with X11 forwarding, use the following steps:

#Start an interactive session with X11:
srun --ntasks=1 -p gpu-relion -A your_account --x11 --pty bash
#Load the RELION module:
module load relion/relion-4.0.1
#Launch RELION:
relion

AlphaFold

AlphaFold is a deep learning tool designed for predicting protein structures.

Guide: AlphaFold Guide

Common SLURM Commands

#View all queues (partitions):
sinfo
#View all jobs:
squeue
#View details of a specific job:
scontrol show job <job_number>
#Get information about partitions:
scontrol show partition

Troubleshooting & Tips

Common Error:

srun: error: Unable to allocate resources: No partition specified or system default partition

Solution: Always specify a partition. Example:

srun --pty -c 1 --mem=2G -p power-general /bin/bash

Chain Jobs: Use the --depend flag to set job dependencies.

Example:

sbatch --ntasks=1 --time=60 -p power-general -A power-general-users --depend=45001 do_work.bash

Always Specify Resources: When submitting jobs, ensure you include all required resources like partition, memory, and CPUs to avoid job failures.

Attaching to Running Jobs: If you need to monitor or interact with a running job, use sattach. This command allows you to attach to a job's input, output, and error streams in real-time.

Example:

sattach <job_id>

To view job steps of a specific job, use the following command:

scontrol show job <job_id>

Look for sections labeled "StepId" within the output.

For specific job steps, use:

sattach <job_id.step_id>

Note: sattach is particularly useful for interactive jobs, where you can provide input directly. For non-interactive jobs, it acts like tail -f, allowing you to monitor the output stream.

This guide provides the essentials for new users to get started with SLURM. For more complex tasks, refer to the full SLURM documentation or contact your system administrator.