SLURM/JobSubmission: Difference between revisions

From UMIACS
Jump to navigation Jump to search
No edit summary
No edit summary
Line 9: Line 9:
<code>srun</code> is the command used to run a process on the compute nodes in the cluster. It works by passing it a command (this could be a script) which will be run on a compute node and then <code>srun</code> will return. <code>srun</code> accepts many command line options to specify the resources required by the command passed to it. Some common command line arguments are listed below and full documentation of all available options is available in the man page for <code>srun</code>, which can be accessed by running <code>man srun</code>.  
<code>srun</code> is the command used to run a process on the compute nodes in the cluster. It works by passing it a command (this could be a script) which will be run on a compute node and then <code>srun</code> will return. <code>srun</code> accepts many command line options to specify the resources required by the command passed to it. Some common command line arguments are listed below and full documentation of all available options is available in the man page for <code>srun</code>, which can be accessed by running <code>man srun</code>.  
<pre>
<pre>
tgray26@opensub01:srun --qos=dpart --mem=100mb --time=1:00:00 bash -c 'echo "Hello World from" `hostname`'
username@opensub01:srun --qos=dpart --mem=100mb --time=1:00:00 bash -c 'echo "Hello World from" `hostname`'
Hello World from openlab06.umiacs.umd.edu
Hello World from openlab06.umiacs.umd.edu
</pre>
</pre>
Line 28: Line 28:
An interactive shell session on a compute node can be useful for debugging or developing code that isn't ready to be run as a batch job. To get an interactive shell on a node, use <code>srun</code> to invoke a shell:
An interactive shell session on a compute node can be useful for debugging or developing code that isn't ready to be run as a batch job. To get an interactive shell on a node, use <code>srun</code> to invoke a shell:
<pre>
<pre>
tgray26@opensub01:srun --pty --qos=dpart --mem 1gb --time=01:00:00 bash
username@opensub01:srun --pty --qos=dpart --mem 1gb --time=01:00:00 bash
tgray26@openlab06:
username@openlab06:
</pre>
</pre>
'''Please do not leave interactive shells running for long periods of time when you are not working. This blocks resources from being used by everyone else.'''
'''Please do not leave interactive shells running for long periods of time when you are not working. This blocks resources from being used by everyone else.'''
Line 36: Line 36:
The salloc command can also be used to request resources be allocated without needing a batch script. Running salloc with a list of resources will allocate the resources you requested, create a job, and drop you into a subshell with the environment variables necessary to run commands in the newly created job allocation. When your time is up or you exit the subshell, your job allocation will be relinquished.
The salloc command can also be used to request resources be allocated without needing a batch script. Running salloc with a list of resources will allocate the resources you requested, create a job, and drop you into a subshell with the environment variables necessary to run commands in the newly created job allocation. When your time is up or you exit the subshell, your job allocation will be relinquished.
<pre>
<pre>
tgray26@opensub00:salloc --qos=dpart -N 1 --mem=2gb --time=01:00:00
username@opensub00:salloc --qos=dpart -N 1 --mem=2gb --time=01:00:00
salloc: Granted job allocation 159
salloc: Granted job allocation 159
tgray26@opensub00:srun /usr/bin/hostname
username@opensub00:srun /usr/bin/hostname
openlab00.umiacs.umd.edu
openlab00.umiacs.umd.edu
tgray26@opensub00:exit
username@opensub00:exit
exit
exit
salloc: Relinquishing job allocation 159
salloc: Relinquishing job allocation 159
Line 54: Line 54:
</pre>
</pre>
Then you need to submit the script with sbatch and request resources:
Then you need to submit the script with sbatch and request resources:
<pre>tgray26@opensub00:sbatch --qos=dpart --mem=1gb --time=1:00:00 helloWorld.sh
<pre>username@opensub00:sbatch --qos=dpart --mem=1gb --time=1:00:00 helloWorld.sh
Submitted batch job 121
Submitted batch job 121
</pre>
</pre>
SLURM will return a job number that you can use to check the status of your job with squeue:
SLURM will return a job number that you can use to check the status of your job with squeue:
<pre>
<pre>
tgray26@opensub00:squeue
username@opensub00:squeue
             JOBID PARTITION    NAME    USER ST      TIME  NODES NODELIST(REASON)
             JOBID PARTITION    NAME    USER ST      TIME  NODES NODELIST(REASON)
               121    dpart helloWor tgray26 R      0:01      2 openlab[00-01]
               121    dpart helloWor username R      0:01      2 openlab[00-01]
</pre>
</pre>
====Advanced Batch Scripts====
====Advanced Batch Scripts====
Line 98: Line 98:
*<code>scancel 255</code>    ''cancel job 255''
*<code>scancel 255</code>    ''cancel job 255''
*<code>scancel 255.3</code>    ''cancel job step 3 of job 255''
*<code>scancel 255.3</code>    ''cancel job step 3 of job 255''
*<code>scancel --user tgray26 --partition=dpart</code>    ''cancel all jobs for tgray26 in the dpart partition''
*<code>scancel --user username --partition=dpart</code>    ''cancel all jobs for username in the dpart partition''


=Identifying Resources and Features=
=Identifying Resources and Features=
Line 120: Line 120:
If you need to do processing on a GPU, you will need to request that your job have access to GPUs just as you need to request processors or CPU cores. You will also need to make sure that you submit your job to the correct partition since nodes with GPUs are often put into their own partition to prevent the nodes from being tied up by jobs that don't utilize GPUs. In SLURM, GPUs are considered "generic resources" also known as GRES. To request some number of GPUs be reserved/available for your job you can use the flag <code>--gres=gpu:2</code> or if there are multiple types of GPUs available in the cluster and you need a specific type, you can provide the type option to the gres flag e.g. <code>--gres=gpu:k20:1</code>
If you need to do processing on a GPU, you will need to request that your job have access to GPUs just as you need to request processors or CPU cores. You will also need to make sure that you submit your job to the correct partition since nodes with GPUs are often put into their own partition to prevent the nodes from being tied up by jobs that don't utilize GPUs. In SLURM, GPUs are considered "generic resources" also known as GRES. To request some number of GPUs be reserved/available for your job you can use the flag <code>--gres=gpu:2</code> or if there are multiple types of GPUs available in the cluster and you need a specific type, you can provide the type option to the gres flag e.g. <code>--gres=gpu:k20:1</code>
<pre>
<pre>
tgray26@opensub01:srun --pty --partition=gpu --qos=gpu --gres=gpu:2 nvidia-smi
username@opensub01:srun --pty --partition=gpu --qos=gpu --gres=gpu:2 nvidia-smi
Wed Jul 13 15:33:18 2016
Wed Jul 13 15:33:18 2016
+------------------------------------------------------+
+------------------------------------------------------+
Line 144: Line 144:
Please note that your job will only be able to see/access the GPUs you requested. If you only need 1 GPU, please request only 1 GPU and the other one will be left available for other users:
Please note that your job will only be able to see/access the GPUs you requested. If you only need 1 GPU, please request only 1 GPU and the other one will be left available for other users:
<pre>
<pre>
tgray26@opensub01:srun --pty --partition=gpu --qos=gpu --gres=gpu:k20:1 nvidia-smi
username@opensub01:srun --pty --partition=gpu --qos=gpu --gres=gpu:k20:1 nvidia-smi
Wed Jul 13 15:31:29 2016
Wed Jul 13 15:31:29 2016
+------------------------------------------------------+
+------------------------------------------------------+

Revision as of 15:44, 7 May 2021

Job Submission

SLURM offers a variety of ways to run jobs. It is important to understand the different options available and how to request the resources required for a job in order for it to run successfully. All job submission should be done from submit nodes; any computational code should be run in a job allocation on compute nodes. The following commands outline how to allocate resources on the compute nodes and submit processes to be run on the allocated nodes.

Please note that the hard maximum number of jobs that the SLURM scheduler can handle is 10000. It is best to limit your number of submitted jobs at any given time to less than half this amount in the case that another user also wants to submit a large number of jobs.

An important notice: computational jobs run on submission nodes will be terminated. Please use the compute nodes for that purpose.

srun

srun is the command used to run a process on the compute nodes in the cluster. It works by passing it a command (this could be a script) which will be run on a compute node and then srun will return. srun accepts many command line options to specify the resources required by the command passed to it. Some common command line arguments are listed below and full documentation of all available options is available in the man page for srun, which can be accessed by running man srun.

username@opensub01:srun --qos=dpart --mem=100mb --time=1:00:00 bash -c 'echo "Hello World from" `hostname`'
Hello World from openlab06.umiacs.umd.edu

It is important to understand that srun is an interactive command. By default input to srun is broadcast to all compute nodes running your process and output from the compute nodes is redirected to srun. This behavior can be changed; however, srun will always wait for the command passed to finish before exiting, so if you start a long running process and end your terminal session, your process will stop running on the compute nodes and your job will end. To run a non-interactive submission that will remain running after you logout, you will need to wrap your srun commands in a batch script and submit it with sbatch

Common srun arguments

  • --mem=1gb if no unit is given MB is assumed
  • --nodes=2 if passed to srun, the given command will be run concurrently on each node
  • --qos=dpart to see the available QOS options on a cluster, run show_qos
  • --time=hh:mm:ss time needed to run your job
  • --job-name=helloWorld
  • --output=filename file to redirect stdout to
  • --error=filename file to redirect stderr
  • --partition=$PNAME request job run in the $PNAME partition
  • --ntasks=2 request 2 "tasks" which map to cores on a CPU, if passed to srun the given command will be run concurrently on each core
  • --account=accountname use qos specific to an account

Interactive Shell Sessions

An interactive shell session on a compute node can be useful for debugging or developing code that isn't ready to be run as a batch job. To get an interactive shell on a node, use srun to invoke a shell:

username@opensub01:srun --pty --qos=dpart --mem 1gb --time=01:00:00 bash
username@openlab06:

Please do not leave interactive shells running for long periods of time when you are not working. This blocks resources from being used by everyone else.

salloc

The salloc command can also be used to request resources be allocated without needing a batch script. Running salloc with a list of resources will allocate the resources you requested, create a job, and drop you into a subshell with the environment variables necessary to run commands in the newly created job allocation. When your time is up or you exit the subshell, your job allocation will be relinquished.

username@opensub00:salloc --qos=dpart -N 1 --mem=2gb --time=01:00:00
salloc: Granted job allocation 159
username@opensub00:srun /usr/bin/hostname
openlab00.umiacs.umd.edu
username@opensub00:exit
exit
salloc: Relinquishing job allocation 159

Please note that any commands not invoked with srun will be run locally on the submit node. Please be careful when using salloc.

sbatch

The sbatch command allows you to write a batch script to be submitted and run non-interactively on the compute nodes. To run a simple Hello World command on the compute nodes you could write a file, helloWorld.sh with the following contents:

#!/bin/bash

srun bash -c 'echo Hello World from `hostname`'

Then you need to submit the script with sbatch and request resources:

username@opensub00:sbatch --qos=dpart --mem=1gb --time=1:00:00 helloWorld.sh
Submitted batch job 121

SLURM will return a job number that you can use to check the status of your job with squeue:

username@opensub00:squeue
             JOBID PARTITION     NAME     USER ST       TIME  NODES NODELIST(REASON)
               121     dpart helloWor username  R       0:01      2 openlab[00-01]

Advanced Batch Scripts

You can also write a batch script with all of your resources/options defined in the script itself. This is useful for jobs that need to be run 10s/100s/1000s of times. You can then handle any necessary environment setup and run commands on the resources you requested by invoking commands with srun. The srun commands can also be more complex and be told to only use portions of your entire job allocation, each of these distinct srun commands makes up one "job step". The batch script will be run on the first node allocated as part of your job allocation and each job step will be run on whatever resources you tell them to. In the following example, we have a batch job that will request 2 nodes in the cluster. We then load a specific version of Python into my environment and submit two job steps, each one using one node. Since srun is blocks until the command finishes, we use the '&' operator to background the process so that both job steps can run at once; however, this means that we then need to use the wait command to block processing until all background processes have finished.

#!/bin/bash

# Lines that begin with #SBATCH specify commands to be used by SLURM for scheduling

#SBATCH --job-name=helloWorld                                   # sets the job name
#SBATCH --output=helloWorld.out.%j                              # indicates a file to redirect STDOUT to; %j is the jobid. Must be set to a file instead of a directory or else submission will fail.
#SBATCH --error=helloWorld.out.%j                               # indicates a file to redirect STDERR to; %j is the jobid. Must be set to a file instead of a directory or else submission will fail.
#SBATCH --time=00:05:00                                         # how long you think your job will take to complete; format=hh:mm:ss
#SBATCH --qos=dpart                                             # set QOS, this will determine what resources can be requested
#SBATCH --nodes=2                                               # number of nodes to allocate for your job
#SBATCH --ntasks=4                                              # request 4 cpu cores be reserved for your node total
#SBATCH --ntasks-per-node=2                                     # request 2 cpu cores be reserved per node
#SBATCH --mem=1gb                                               # memory required by job; if unit is not specified MB will be assumed

module load Python/2.7.9                                        # run any commands necessary to setup your environment

srun -N 1 --mem=512mb bash -c "hostname; python --version" &    # use srun to invoke commands within your job; using an '&'
srun -N 1 --mem=512mb bash -c "hostname; python --version" &    # will background the process allowing them to run concurrently
wait                                                            # wait for any background processes to complete

# once the end of the batch script is reached your job allocation will be revoked

Another useful thing to know is that you can pass additional arguments into your sbatch scripts on the command line and reference them as ${1} for the first argument and so on.

More Examples

scancel

The scancel command can be used to cancel job allocations or job steps that are no longer needed. It can be passed individual job IDs or an option to delete all of your jobs or jobs that meet certain criteria.

  • scancel 255 cancel job 255
  • scancel 255.3 cancel job step 3 of job 255
  • scancel --user username --partition=dpart cancel all jobs for username in the dpart partition

Identifying Resources and Features

The sinfo can show you additional features of nodes in the cluster but you need to ask it to show some non-default options using a command like this sinfo -o "%15N %10c %10m %25f %10G".

$ sinfo -o "%40N %8c %8m  %20f %25G"
NODELIST                                 CPUS     MEMORY    AVAIL_FEATURES       GRES
openlab[11,13-18,20-23,25,27-29]         16       23937     Xeon,x5560           (null)
openlab[30-33]                           64       257757    Opteron,6274         (null)
openlab[38-61]                           16       23936+    Xeon,E5530           (null)
openlab08                                32       128718    Xeon,E5-2690         gpu:m40:1,gpu:k20:2

There is also a prewritten alias show_nodes on all of our SLURM computing clusters that shows each node's name, number of CPUs, memory, processor type (as AVAIL_FEATURES), GRES, State, and partitions that can submit to it.

You can identify further specific information about a node using scontrol with various flags.

Requesting GPUs

If you need to do processing on a GPU, you will need to request that your job have access to GPUs just as you need to request processors or CPU cores. You will also need to make sure that you submit your job to the correct partition since nodes with GPUs are often put into their own partition to prevent the nodes from being tied up by jobs that don't utilize GPUs. In SLURM, GPUs are considered "generic resources" also known as GRES. To request some number of GPUs be reserved/available for your job you can use the flag --gres=gpu:2 or if there are multiple types of GPUs available in the cluster and you need a specific type, you can provide the type option to the gres flag e.g. --gres=gpu:k20:1

username@opensub01:srun --pty --partition=gpu --qos=gpu --gres=gpu:2 nvidia-smi
Wed Jul 13 15:33:18 2016
+------------------------------------------------------+
| NVIDIA-SMI 361.28     Driver Version: 361.28         |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  Tesla K20c          Off  | 0000:03:00.0     Off |                    0 |
| 30%   24C    P0    48W / 225W |     11MiB /  4799MiB |      0%      Default |
+-------------------------------+----------------------+----------------------+
|   1  Tesla K20c          Off  | 0000:84:00.0     Off |                    0 |
| 30%   23C    P0    52W / 225W |     11MiB /  4799MiB |     93%      Default |
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID  Type  Process name                               Usage      |
|=============================================================================|
|  No running processes found                                                 |
+-----------------------------------------------------------------------------+

Please note that your job will only be able to see/access the GPUs you requested. If you only need 1 GPU, please request only 1 GPU and the other one will be left available for other users:

username@opensub01:srun --pty --partition=gpu --qos=gpu --gres=gpu:k20:1 nvidia-smi
Wed Jul 13 15:31:29 2016
+------------------------------------------------------+
| NVIDIA-SMI 361.28     Driver Version: 361.28         |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  Tesla K20c          Off  | 0000:03:00.0     Off |                    0 |
| 30%   24C    P0    50W / 225W |     11MiB /  4799MiB |     92%      Default |
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID  Type  Process name                               Usage      |
|=============================================================================|
|  No running processes found                                                 |
+-----------------------------------------------------------------------------+

The --gres flag may also be passed to sbatch and salloc rather than directly to srun

MPI example

#!/usr/bin/bash 
#SBATCH --job-name=mpi_test # Job name 
#SBATCH --nodes=4 # Number of nodes 
#SBATCH --ntasks=8 # Number of MPI ranks 
#SBATCH --ntasks-per-node=2 # Number of MPI ranks per node 
#SBATCH --ntasks-per-socket=1 # Number of tasks per processor socket on the node 
#SBATCH --time=00:30:00 # Time limit hrs:min:sec 

module load mpi 

srun --mpi=openmpi /nfshomes/derek/testing/mpi/a.out