{"id":8625,"date":"2025-01-28T10:36:10","date_gmt":"2025-01-28T10:36:10","guid":{"rendered":"https:\/\/ri.itservices.manchester.ac.uk\/csf3\/?page_id=8625"},"modified":"2026-03-27T11:03:27","modified_gmt":"2026-03-27T11:03:27","slug":"sge-to-slurm","status":"publish","type":"page","link":"https:\/\/ri.itservices.manchester.ac.uk\/csf3\/batch-slurm\/sge-to-slurm\/","title":{"rendered":"SGE to Slurm Reference"},"content":{"rendered":"<div class=\"hint\">\nThis page is for users who have previously used the CSF3 when it was running the SGE batch system. It will help you to convert your SGE jobscripts to Slurm jobscripts.<\/p>\n<p>New users of the CSF from May 2025 onwards can ignore this &#8211; you have only ever been using the Slurm batch system.\n<\/p><\/div>\n<h2>Introduction<\/h2>\n<p>The use of Slurm on CSF3 represents a significant change for CSF users who are used to using the SGE batch system.<\/p>\n<p>While SGE has served us well, Slurm has been widely adopted by many other HPC sites, is under active development and has features and flexibility that we need as we introduce new platforms for the research community at the University.<\/p>\n<p>This page shows the Slurm commands and jobscript options next to their SGE counterparts to help you move from SGE to Slurm.<\/p>\n<h3>How can I tell which system I&#8217;m using?<\/h3>\n<p>It is now only possible to access to CSF3 Slurm system. <\/p>\n<p>On the login node, you will see the <code>csf3<\/code> system name in green:<\/p>\n<pre>\r\n[<em>mabcxyz1<\/em>@login1[csf3] ~]$  # The upgraded CSF3 uses green in the prompt\r\n<\/pre>\n<h3>What are the key differences?<\/h3>\n<ol class=\"gaplist\">\n<li>Slurm uses <code>sbatch<\/code>, <code>squeue<\/code>, <code>scancel<\/code> and <code>srun<\/code> commands, not <code>qsub<\/code>, <code>qstat<\/code>, <code>qdel<\/code> and <code>qrsh<\/code>. <a href=\"#commands\">See below<\/a>.<\/li>\n<li>The jobscript <em>sentinel<\/em> is <code>#SBATCH<\/code>, not <code>#$<\/code>. <a href=\"#sentinel\">See below<\/a>.<\/li>\n<li>You must specify explicitly the <code>serial<\/code> partition to run a 1-core job. <a href=\"#serial\">See below<\/a>.<\/li>\n<li>The <em>parallel environments<\/em>, called &#8220;partitions&#8221; in Slurm, have new names. <a href=\"#multicore\">See below<\/a>.<\/li>\n<li><strong>You MUST specify a job wallclock time for your job! There is NO default value applied to a job. The maximum permitted is 7 days in most cases (GPU jobs can have a maximum of 4 days.) Your job will be rejected if you don&#8217;t give it a wallclock time<\/strong>. <a href=\"#wallclock\">See below<\/a>.<\/li>\n<li>Job output files (the .o and .e files in SGE) are merged by default, and have a different naming convention, in Slurm. <a href=\"#outfiles\">See below<\/a>.<\/li>\n<li>The jobscript flags (-pe, -l v100=1 and so on) have changed.<\/li>\n<li>The jobscript variables (<code>$JOB_ID<\/code>, <code>$NSLOTS<\/code> and so on) have changed. <a href=\"#envvars\">See below<\/a>.<\/li>\n<\/ol>\n<p>Please see below for more details on how to use Slurm, compared to SGE.<\/p>\n<h2 id=\"sentinel\">Jobscript Special Lines &#8211; SGE (#$) vs Slurm (#SBATCH)<\/h2>\n<p>Your SGE jobscripts will <em>not<\/em> run in the Slurm batch system. This is because the <strong>SGE jobscript <em>special lines<\/em> beginning with <code>#$<\/code> will be ignored by Slurm<\/strong>. Instead, you should use lines beginning with <code>#SBATCH<\/code>, and will need to change the options you use on those lines.<\/p>\n<div class=\"note\">Note that it is <code>#<strong>S<\/strong>BATCH<\/code> (short for Slurm BATCH) and NOT <code>#<strong>$<\/strong>BATCH<\/code>. This is an easy mistake to make when you begin to modify your SGE jobscripts. <strong>Do not use a $ (dollar) symbol in the Slurm special lines.<\/strong><\/div>\n<h3>Can I use a single jobscript for both SGE and Slurm?<\/h3>\n<p>It is possible to have both SGE and Slurm lines in your jobscripts &#8211; they will each ignore the other&#8217;s special lines.<\/p>\n<p>However, there are some differences in the way multi-core and multi-node jobs are run, so we advise writing new jobscripts for use on the upgraded CSF3.<\/p>\n<p>One suggestion is to name your Slurm jobscripts <code><em>jobscript<\/em>.sbatch<\/code> and your SGE jobscripts <code><em>jobscript<\/em>.qsub<\/code>, but you can, of course, use any naming scheme you like.<\/p>\n<p>Examples of SGE jobscripts and their equivalent Slurm jobscript are given below.<\/p>\n<p>The commands used to submit jobs and check on the queue have also changed. See below for the equivalent commands.<\/p>\n<h2 id=\"commands\">Command-line tools &#8211; SGE (qsub, &#8230;) vs Slurm (sbatch, &#8230;)<\/h2>\n<table class=\"jobscriptcompare\">\n<thead>\n<tr>\n<th width=\"50%\">SGE Commands (old CSF3)<\/th>\n<th width=\"50%\">Slurm Commands (new CSF3)<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>\n<pre class=\"sge\"># Batch job submission\r\nqsub <em>jobscript<\/em>\r\nqsub <em>jobscript<\/em> arg1 arg2 ...\r\nqsub <em>options<\/em> -b y <em>executable arg1 ...<\/em>\r\n\r\n# Job queue status\r\nqstat             # Show your jobs (if any)\r\nqstat -u \"*\"      # Show all jobs\r\nqstat -u <em>username<\/em>\r\n\r\n# Cancel (delete) a job\r\nqdel <em>jobid<\/em>\r\nqdel <em>jobname<\/em>\r\nqdel <em>jobid<\/em> -t <em>taskid<\/em>\r\nqdel \"*\"             # Delete all my jobs\r\n\r\n# Interactive job\r\nqrsh -l short\r\n\r\n# Completed job stats\r\nqacct -j <em>jobid<\/em>\r\n<\/pre>\n<\/td>\n<td>\n<pre class=\"slurm\"># Batch job submission\r\nsbatch <em>jobscript<\/em>\r\nsbatch <em>jobscript<\/em> arg1 arg2 ...\r\nsbatch <em>options<\/em> --wrap=\"<em>executable arg1 ...<\/em>\"\r\n\r\n# Job queue status\r\nsqueue      # An alias for \"squeue --me\"\r\n\\squeue     # Unaliased squeue shows all jobs\r\nsqueue -u <em>username<\/em>\r\n\r\n# Cancel (delete) a job\r\nscancel <em>jobid<\/em>\r\nscancel -n <em>jobname<\/em>\r\nscancel <em>jobid<\/em>_<em>taskid<\/em>\r\nscancel -u $USER       # Delete all my jobs\r\n\r\n# Interactive job (1 hour session)\r\nsrun -p interactive -t 1:00:00 --pty bash\r\n\r\n# Completed job stats\r\nsacct -j <em>jobid<\/em>\r\n<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2 id=\"outfiles\">Job Output Files (stdout and stderr)<\/h2>\n<table class=\"jobscriptcompare\">\n<thead>\n<tr>\n<th width=\"50%\">SGE job output files, not merged by default (old CSF3)<\/th>\n<th width=\"50%\">Slurm job output files, merged by default (new CSF)<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>\n<pre class=\"sge\"># Individual (non-array) jobs\r\n<em>jobscriptname<\/em>.o<em>JOBID<\/em>\r\n<em>jobscriptname<\/em>.e<em>JOBID<\/em>\r\n\r\n# Array jobs\r\n<em>jobscriptname<\/em>.o<em>JOBID<\/em>.<em>TASKID<\/em>\r\n<em>jobscriptname<\/em>.e<em>JOBID<\/em>.<em>TASKID<\/em>\r\n<\/pre>\n<\/td>\n<td>\n<pre class=\"slurm\"># Individual (non-array) jobs\r\nslurm-<em>JOBID<\/em>.out\r\n\r\n\r\n# Array jobs (see later for more details)\r\nslurm-<em>ARRAYJOBID_TASKID<\/em>.out\r\n\r\n<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>The Slurm files contain the normal and error output that SGE splits in to two files.<\/p>\n<p>The naming and merging of the files can be changed using jobscript options (<a href=\"#moreoptions\">see below<\/a>) but for now, in the basic jobscripts shown next, we&#8217;ll just accept these default names to keep the jobscripts short.<\/p>\n<h2>Jobscripts<\/h2>\n<p>You will need to rewrite your SGE jobscripts. You could name them <code><em>somename<\/em>.sbatch<\/code> if you like, to make it obvious it is a Slurm jobscript.<\/p>\n<h3>Put #SBATCH lines in one block<\/h3>\n<p>Please note: all Slurm <em>special lines<\/em> beginning with <code>#SBATCH<\/code> must come before ordinary lines that run Linux commands or your application. Any <code>#SBATCH<\/code> lines appearing after the first non-<code>#SBATCH<\/code> line will be ignored. For example:<\/p>\n<pre class=\"slurm\">#!\/bin\/bash --login\r\n\r\n# You may put comment lines before and after #SBATCH lines\r\n#SBATCH -n 4\r\n#SBATCH -c 2\r\n\r\n# Now the first 'ordinary' line. So no more #SBATCH lines allowed after here\r\nexport MY_DATA=~\/scratch\/data\r\n# We recommend that you purge your module environment before loading further modules in Slurm jobs\r\nmodule purge\r\nmodule load <em>myapp<\/em>\/<em>1.2.3<\/em>\r\n\r\n# <strong>Any SBATCH lines here will be ignored!<\/strong>\r\n#SBATCH --job-name  new_job_name\r\n\r\n.\/my_app dataset1.dat\r\n<\/pre>\n<h3>Partitions &#8211; required!<\/h3>\n<p>On the upgraded CSF3 running Slurm, you are <em>required<\/em> to specify, in your jobscript, the Slurm <em>partition<\/em> in which your job will run. Think of these as like queues for different types of jobs.<\/p>\n<p>For example, there is a partition for the AMD nodes running parallel jobs. There&#8217;s a partition for serial jobs, and so on.<\/p>\n<p>The current list of Slurm <em>partitions<\/em> (and the compute resources they offer) is available at the <a href=\"\/csf3\/batch-slurm\/partitions\/\">Partitions page<\/a>.<\/p>\n<h3 id=\"wallclock\">Job Wallclock (time) Limits &#8211; now required!<\/h3>\n<p>On the upgraded CSF3 running Slurm, you are <em>required<\/em> to specify the maximum wallclock time limit for your job.<\/p>\n<p>Previously, on the old CSF3 running SGE, this was optional and would default to the maximum of 7 days (or 4 days for GPU and HPC Pool jobs.)<\/p>\n<p>Why the change? In short, more accurate wallclock times, specified by you, will help with scheduling your job.<\/p>\n<p>In particular, if you know your job will complete within 1 hour, or 1 day, say, by specifying this wallclock limit, the scheduler may be able to squeeze your job onto a compute node that is being held by the scheduler for a much larger, long running job. Slurm will try to use cores by running short jobs that it knows could be left idle while a larger job is waiting for resources.<\/p>\n<p>Of course, you can still specify a maximum wallclock of 7 days, even if your job won&#8217;t actually take that long to complete. But you might wait longer in the queue.<\/p>\n<p><strong>You don&#8217;t need to be super-accurate<\/strong>, and it is much better to <strong>give your job plenty of time to complete<\/strong>. If you don&#8217;t give the job enough time, Slurm will kill the job <em>before<\/em> it completes. So we recommend specifying a number of days.<\/p>\n<p>To specify a wallclock time in a Slurm job:<\/p>\n<pre class=\"slurm\">#SBATCH -t <em>timelimit<\/em>\r\n## OR\r\n#SBATCH --time=<em>timelimit<\/em>\r\n<\/pre>\n<p>where the following are examples of acceptable formats for the <code>timelimit<\/code><\/p>\n<pre class=\"slurm\">#SBATCH -t 10            # minutes\r\n#SBATCH -t 10:30         # minutes:seconds\r\n#SBATCH -t 4:20:00       # hours:minutes:seconds\r\n#SBATCH -t 4-0           # days-hours              # <strong>Recommended format<\/strong>\r\n#SBATCH -t 4-10:00       # days-hours:minutes\r\n#SBATCH -t 5-8:15:30     # days-hours:minutes:seconds\r\n<\/pre>\n<p>If you fail to specify a wallclock time limit, you will get the following error when submitting a job:<\/p>\n<pre>sbatch: error: Batch job submission failed: Requested time limit is invalid (missing or exceeds some limit)\r\n<\/pre>\n<p>Add the <code>-t<\/code> flag and resubmit the job.<\/p>\n<h3 id=\"serial\">Basic Serial (1-core) Josbscript<\/h3>\n<p>A basic serial job requires the <code>serial<\/code> partition to be specified, and a wallclock timelimt.<\/p>\n<pre class=\"slurm\">#!\/bin\/bash --login\r\n#SBATCH -p serial     # Partition name is <strong>required<\/strong> (serial will default to 1 core)\r\n#SBATCH -t 4-0        # Job \"wallclock\" limit is <strong>required<\/strong>. Max permitted is 7 days (7-0).\r\n                      # In this example 4-0 is 4 days (0 hours).\r\n                      # Other formats:  min:sec, hrs:min:sec, day-hours (to name a few)\r\n# Clean env\r\nmodule purge\r\nmodule load apps\/binapps\/someapp\/1.2.3\r\n\r\n# Use $SLURM_NTASKS if you need to say how many cores are being used (1 in this case)\r\n<em>someapp.exe<\/em>\r\n<\/pre>\n<h3 id=\"multicore\">Basic Multi-core (single AMD 168-core compute node) Parallel Jobscript<\/h3>\n<p>The following will run on an AMD 168-core Genoa node, using 96 cores, for 4.5 days. Please see the <a href=\"\/csf3\/batch-slurm\/partitions\/\">full list of available <em>partitions<\/em><\/a> for more details about the compute resources.<\/p>\n<pre class=\"slurm\">#!\/bin\/bash --login\r\n#SBATCH -p multicore   # Partition name is <strong>required<\/strong>. This gives you the AMD Genoa (168-core) nodes.\r\n#SBATCH -n 96          # (or --ntasks=) Number of cores (2--168 on AMD)\r\n#SBATCH -t 4-12        # Job \"wallclock\" limit is <strong>required<\/strong>. Max permitted is 7 days (7-0).\r\n                       # In this example 4-12 is 4 days 12 hours (4.5 days).\r\n\r\n# Clean env\r\nmodule purge\r\nmodule load apps\/binapps\/some_mpi_app\/1.2.3\r\n\r\n# Slurm knows how many cores to use for mpirun\r\nmpirun <em>someMPIapp.exe<\/em>\r\n<\/pre>\n<p>If running OpenMP parallel jobs you can also use the following jobscript, which requests one Slurm <em>task<\/em> and several <em>cores-per-task<\/em>:<\/p>\n<pre class=\"slurm\">#!\/bin\/bash --login\r\n#SBATCH -p multicore\r\n#SBATCH -n 1               # One \"task\" (sets $SLURM_NTASKS to 1)\r\n#SBATCH -c 84              # 84 cores-per-task (sets $SLURM_CPUS_PER_TASK to 84)\r\n#SBATCH -t 4-12            # 4 days 12 hours\r\n\r\nmodule purge\r\nmodule load apps\/binapps\/some_omp_app\/1.2.3\r\n\r\n# Inform OpenMP how many cores to use\r\nexport OMP_NUM_THREADS=$SLURM_CPUS_PER_TASK\r\n<em>someOMPapp.exe<\/em>\r\n<\/pre>\n<h3>Basic Multi-node Parallel Jobscript<\/h3>\n<p>Multi-node jobs can only be run on the HPC Pool nodes. Please see <a href=\"\/csf3\/hpc-pool\/jobs\/\">how to run HPC Pool jobs<\/a>.<\/p>\n<h3>Basic Job Array Jobscript<\/h3>\n<p>The following will run a 1000 task job array, where each task uses 2 cores on an AMD node, and each task can run for 2 days<\/p>\n<pre class=\"slurm\">#!\/bin\/bash --login\r\n#SBATCH -p multicore   # Partition name is <strong>required<\/strong>\r\n#SBATCH -n 2           # (or --ntasks=) Number of cores (2--168 on AMD)\r\n#SBATCH -t 2-0         # Job \"wallclock\" limit is <strong>required<\/strong>. Max permitted is 7 days (7-0).\r\n                       # In this example <em>each<\/em> job array task gets 2 days (0 hours).\r\n#SBATCH -a 1-1000      # 1000 tasks in the job array, numbered 1..1000.\r\n                       # (NB: tasks can begin from 0 in Slurm, unlike SGE)\r\n\r\n# Clean env\r\nmodule purge\r\nmodule load apps\/gcc\/someapp\/1.2.3\r\n\r\n# Use ${SLURM_ARRAY_TASK_ID} to get the task number (1,2,...,1000 in this example)\r\n.\/myprog -in data.${SLURM_ARRAY_TASK_ID}.dat -out results.${SLURM_ARRAY_TASK_ID}.dat\r\n               #\r\n               # My input files are named: data.1.dat, data.2.dat, ..., data.1000.dat\r\n               # 1000 tasks (copies of this job) will run.\r\n               # Task 1 will read data.1.dat, task 2 will read data.2.dat, ... \r\n<\/pre>\n<p><a name=\"moreoptions\"><\/a><\/p>\n<h2>More Jobscript options &#8211; SGE vs Slurm<\/h2>\n<p>Here are some more example jobscripts special lines for achieving things in SGE and Slurm.<\/p>\n<h3>Renaming a job and the output .o and .e files<\/h3>\n<table class=\"jobscriptcompare\">\n<thead>\n<tr>\n<th width=\"50%\">SGE Jobscript<\/th>\n<th width=\"50%\">Slurm Jobscript<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>\n<pre class=\"sge\">#!\/bin\/bash --login\r\n...\r\n# Naming the job is optional.\r\n# <strong>Default<\/strong> is <em>name of jobscript<\/em>\r\n# <strong>DOES<\/strong> rename .o and .e output files.\r\n#$ -N jobname\r\n\r\n# Naming the output files is optional.\r\n# <strong>Default<\/strong> is <strong>separate<\/strong> .o and .e files:\r\n# <strong><em>jobname<\/em>.o<em>JOBID<\/em><\/strong> and <strong><em>jobname<\/em>.e<em>JOBID<\/em><\/strong>\r\n# Use of '-N jobname' <strong>DOES<\/strong> affect those defaults\r\n#$ -o myjob.out\r\n#$ -e myjob.err\r\n\r\n# To join .o and .e in to a single file\r\n# similar to Slurm's default behaviour:\r\n#$ -j y\r\n<\/pre>\n<\/td>\n<td>\n<pre class=\"slurm\">#!\/bin\/bash --login\r\n...\r\n# Naming the job is optional.\r\n# <strong>Default<\/strong> is <em>name of jobscript<\/em>\r\n# Does <strong>NOT<\/strong> rename .out file.\r\n#SBATCH -J jobname\r\n\r\n# Naming the output files is optional.\r\n# <strong>Default<\/strong> is a <strong>single file<\/strong> for .o and .e:\r\n# <strong>slurm-<em>JOBID<\/em>.out<\/strong>\r\n# Use of '-J jobname' does <strong>NOT<\/strong> affect the default\r\n#SBATCH -o myjob.out\r\n#SBATCH -e myjob.err\r\n\r\n# Use wildcards to recreate the SGE names\r\n#SBATCH -o %x.o%j      # %x = SLURM_JOB_NAME\r\n#SBATCH -e %x.e%j      # %j = SLURM_JOB_ID\r\n<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>The <code>$SLURM_JOB_NAME<\/code> variable will tell you the name of your jobscript, unless the <code>-J <em>jobname<\/em><\/code> variable is used to rename your job. Then the env var is set to the value of <em>jobname<\/em>.<\/p>\n<p>If you wanted to use <code>$SLURM_JOB_NAME<\/code> to always give you the name of the jobscript from within your job, you would have to remove the <code>-J<\/code> flag. However, the following command run inside your jobscript will give you the name of the jobscript regardless of whether you use the <code>-J<\/code> flag or not:<\/p>\n<pre class=\"slurm\">scontrol show jobid $SLURM_JOB_ID | grep Command= | awk -F\/ '{print $NF}'\r\n<\/pre>\n<h3>Renaming an array job output .o and .e files<\/h3>\n<p>An array job uses <code>slurm-<em>ARRAYJOBID_TASKID<\/em>.out<\/code> as the default output file for each task in the array job. This can be renamed but you need to use the <code>%A<\/code> and <code>%a<\/code> wildcards (not <code>%j<\/code>).<\/p>\n<table class=\"jobscriptcompare\">\n<thead>\n<tr>\n<th width=\"50%\">SGE Jobscript<\/th>\n<th width=\"50%\">Slurm Jobscript<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>\n<pre class=\"sge\">#!\/bin\/bash --login\r\n...\r\n# An array job (cannot start at 0)\r\n#$ -t 1-1000\r\n\r\n# Naming the job is optional.\r\n# <strong>Default<\/strong> is <em>name of jobscript<\/em>\r\n#$ -N jobname\r\n\r\n# Naming the output files is optional.\r\n# <strong>Default<\/strong> is separate .o and .e files:\r\n# <strong><em>jobname<\/em>.o<em>JOBID<\/em><\/strong> and <strong><em>jobname<\/em>.e<em>JOBID<\/em><\/strong>\r\n# Use of '-N jobname' <strong>DOES<\/strong> affect those defaults\r\n\r\n# To join .o and .e in to a single file\r\n# similar to Slurm's default behaviour:\r\n#$ -j y\r\n\r\n<\/pre>\n<\/td>\n<td>\n<pre class=\"slurm\">#!\/bin\/bash --login\r\n...\r\n# An array job (CAN start at 0)\r\n#SBATCH -a 0-999     # (or --array=0-999)\r\n\r\n# Naming the job is optional.\r\n# <strong>Default<\/strong> is <em>name of jobscript<\/em>\r\n#SBATCH -J jobname\r\n\r\n# Naming the output files is optional.\r\n# <strong>Default<\/strong> is a <strong>single file<\/strong> for .o and .e:\r\n# <strong>slurm-<em>ARRAYJOBID_TASKID<\/em>.out<\/strong>\r\n# Use of '-J jobname' does <strong>NOT<\/strong> affect the default\r\n\r\n# Use wildcards to recreate the SGE names\r\n#SBATCH -o %x.o%A.%a # %x=SLURM_JOB_NAME\r\n#SBATCH -e %x.e%A.%a # %A=SLURM_ARRAY_JOB_ID\r\n                     # %a=SLURM_ARRAY_TASK_ID\r\n<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>Emailing from a job<\/h3>\n<p>SLURM can email you when your job begins, ends or fails.<\/p>\n<table class=\"jobscriptcompare\">\n<thead>\n<tr>\n<th width=\"50%\">SGE Jobscript<\/th>\n<th width=\"50%\">Slurm Jobscript<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>\n<pre class=\"sge\">#!\/bin\/bash --login\r\n...\r\n# Mail events: <strong>b<\/strong>egin, <strong>e<\/strong>nd, <strong>a<\/strong>bort\r\n#$ -m bea\r\n#$ -M &#x65;&#46;a&#x64;&#100;r&#x40;&#x6d;&#97;&#x6e;&#x63;&#104;e&#x73;&#116;e&#x72;&#x2e;&#97;&#x63;&#x2e;&#117;k\t\r\n<\/pre>\n<\/td>\n<td>\n<pre class=\"slurm\">#!\/bin\/bash --login\r\n...\r\n# Mail events: NONE, BEGIN, END, FAIL, ALL\r\n#SBATCH --mail-type=BEGIN,END,FAIL\r\n#SBATCH &#x2d;-&#x6d;&#97;&#x69;&#x6c;-&#x75;&#115;&#x65;&#x72;=&#x65;&#46;&#x61;&#x64;d&#x72;&#64;&#x6d;&#x61;n&#x63;&#104;&#x65;&#x73;t&#x65;&#114;&#x2e;&#x61;c&#x2e;&#117;&#x6b;\r\n<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Note that in Slurm, array jobs only send one email, not an email per job-array tasks as happens in SGE. If you want an email from every job-array task, add <code>ARRAY_TASKS<\/code> to the <code>--mail<\/code> flag:<\/p>\n<pre class=\"slurm\">#SBATCH --mail-type=ALL,ARRAY_TASKS\r\n                            #\r\n                            # DO NOT USE IF YOUR ARRAY JOB CONTAINS MORE THAN\r\n                            # 20 TASKS!! THE UoM MAIL ROUTERS WILL BLOCK THE CSF!\r\n<\/pre>\n<p>But please be aware that you will receive A LOT of email if you run a large job array with this flag enabled.<\/p>\n<h2 id=\"envvars\">Job Environment Variables<\/h2>\n<p>A number of environment variables are available for use in your jobscripts &#8211; these are sometimes useful when creating your own log files, for informing applications how many cores they are allowed to use (we&#8217;ve already seen <code>$SLURM_NTASKS<\/code> in the examples above), and for reading sequentially numbered data files in job arrays.<\/p>\n<table class=\"jobscriptcompare\">\n<thead>\n<tr>\n<th width=\"50%\">SGE Environment Variables<\/th>\n<th width=\"50%\">Slurm Environment Variables<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>\n<pre class=\"sge\">$NSLOTS             # Num cores reserved\r\n\r\n$JOB_ID             # Unique jobid number\r\n$JOB_NAME           # Name of job\r\n\r\n# For array jobs\r\n$JOB_ID             # Same for all tasks\r\n                    # (e.g, <em>2173<\/em>)\r\n\r\n\r\n$SGE_TASK_ID        # Job array task number<sup>*<\/sup>\r\n                    # (e.g., 1,2,3,...)\r\n$SGE_TASK_FIRST     # First task id\r\n$SGE_TASK_LAST      # Last task id\r\n$SGE_TASK_STEPSIZE  # Taskid increment\r\n                    # (default: 1)\r\n\r\n\r\n# Number of GPUs in GPU job\r\n$NGPUS\r\n\r\n# You will be unlikely to use these:\r\n$PE_HOSTFILE        # Multinode host list\r\n$NHOSTS             # Number of nodes in use\r\n$SGE_O_WORKDIR      # Submit directory\r\n<\/pre>\n<\/td>\n<td>\n<pre class=\"slurm fade\">$SLURM_NTASKS        # Num cores from -n flag\r\n$SLURM_CPUS_PER_TASK # Num cores from -c flag\r\n$SLURM_JOB_ID        # Unique job id number\r\n$SLURM_JOB_NAME      # Name of job\r\n\r\n# For array jobs\r\n$SLURM_JOB_ID        # <strong>NOT SAME FOR ALL TASKS<\/strong> \r\n                     # (eg: <em>2173<\/em>,<em>2174<\/em>,<em>2175<\/em>)\r\n$SLURM_ARRAY_JOB_ID  # <strong>SAME <\/strong>for all tasks\r\n                     # (eg: <em>2173<\/em>)\r\n$SLURM_ARRAY_TASK_ID # Job array task number<sup>*<\/sup>\r\n                     # (eg: 1,2,3,...)\r\n$SLURM_ARRAY_TASK_MIN   # First task id\r\n$SLURM_ARRAY_TASK_MAX   # Last task id\r\n$SLURM_ARRAY_TASK_STEP  # Taskid Increment\r\n                        # (default: 1)\r\n$SLURM_ARRAY_TASK_COUNT # Number of tasks\r\n\r\n# Number of GPUs in GPU job\r\n$SLURM_GPUS\r\n\r\n# You will be unlikely to use these:\r\n$SLURM_JOB_NODELIST  # Multinode host list\r\n$SLURM_JOB_NUM_NODES # Number of nodes in use\r\n$SLURM_SUBMIT_DIR    # Submit directory\r\n<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>Note (*)<\/strong>: SGE job-array task IDs are NOT allowed to start from zero &#8211; they must start from 1 (or higher). Slurm job array task IDs <em>can<\/em> start from zero &#8211; it is up to you to specify the starting task id.<\/p>\n<p>Many more environment variables are available for use in your jobscript. The <a href=\"https:\/\/slurm.schedmd.com\/sbatch.html\">Slurm sbatch manual<\/a> (also available on the CSF login node by running <code>man sbatch<\/code>) documents <em>Input<\/em> and <em>Output<\/em> environment variables. The <em>input<\/em> variables can be set by you <em>before<\/em> submitting a job to set job options (although we recommend <em>not<\/em> doing this &#8211; it is better to put all options in your jobscript so that you have a permanent record of how you ran the job). The <em>output<\/em> variables can be used inside your jobscript to get information about the job (e.g., number of cores, job name and so on &#8211; we have documented several of these above.)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This page is for users who have previously used the CSF3 when it was running the SGE batch system. It will help you to convert your SGE jobscripts to Slurm jobscripts. New users of the CSF from May 2025 onwards can ignore this &#8211; you have only ever been using the Slurm batch system. Introduction The use of Slurm on CSF3 represents a significant change for CSF users who are used to using the SGE.. <a href=\"https:\/\/ri.itservices.manchester.ac.uk\/csf3\/batch-slurm\/sge-to-slurm\/\">Read more &raquo;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"parent":9105,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-8625","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/ri.itservices.manchester.ac.uk\/csf3\/wp-json\/wp\/v2\/pages\/8625","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ri.itservices.manchester.ac.uk\/csf3\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/ri.itservices.manchester.ac.uk\/csf3\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/ri.itservices.manchester.ac.uk\/csf3\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ri.itservices.manchester.ac.uk\/csf3\/wp-json\/wp\/v2\/comments?post=8625"}],"version-history":[{"count":21,"href":"https:\/\/ri.itservices.manchester.ac.uk\/csf3\/wp-json\/wp\/v2\/pages\/8625\/revisions"}],"predecessor-version":[{"id":12192,"href":"https:\/\/ri.itservices.manchester.ac.uk\/csf3\/wp-json\/wp\/v2\/pages\/8625\/revisions\/12192"}],"up":[{"embeddable":true,"href":"https:\/\/ri.itservices.manchester.ac.uk\/csf3\/wp-json\/wp\/v2\/pages\/9105"}],"wp:attachment":[{"href":"https:\/\/ri.itservices.manchester.ac.uk\/csf3\/wp-json\/wp\/v2\/media?parent=8625"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}