Computing with Slurm
Important
This page describes computing on the Hoffman2 Cluster, which uses the Slurm workload manager. Connect to it at hoffman2.oarc.ucla.edu (see Connecting/Logging in). For node types and the meaning of highp, shared and campus jobs, see Computing overview. For the legacy cluster running the Altair Grid Engine (qrsh, qsub), see Computing with Altair Grid Engine on the legacy cluster.
Your $HOME, $SCRATCH and project directories, if any, are shared with the legacy cluster. The operating system and application stack are different, so software built on the legacy cluster may need to be rebuilt, and job scripts written for Grid Engine need to be converted (see Converting Grid Engine job scripts to Slurm).
This page describes:
Accounts, QOS and where your jobs run
Every Slurm job runs under an account (-A or --account), and the cluster decides where it runs from that account.
Important
A Slurm account is not your Hoffman2 Cluster user name (your login ID). It is the account of the research group you work in, named after the group’s PI: pi_<PI's user name> (for example pi_gobruin for the group of PI gobruin). You can belong to more than one Slurm account. To list yours, run h2 whoami or:
$ sacctmgr -nP show assoc user=$USER format=account,qos
You do not need to choose a partition or a QOS: the cluster routes each job from its account to the campus, shared or highp nodes. The only choice you make is --qos=highp, to run on your own group’s nodes:
Job type |
How you get it |
Max runtime |
Where it runs |
|---|---|---|---|
Automatically, for accounts of groups without nodes in the Slurm cluster |
24 hours |
On OARC-owned nodes (the |
|
Automatically, for accounts of groups whose contributed nodes are in the Slurm cluster |
24 hours |
On the unused nodes of all contributed (group-owned) nodes in the Slurm cluster, your own group’s nodes included (the |
|
With |
14 days |
On your group’s own nodes (the partition with the same name as your account, e.g. |
Only users in PI groups that have contributed nodes to the cluster, and whose nodes have already moved to the Slurm cluster, can use --qos=highp. Groups whose nodes have not moved yet keep running their highp jobs on the legacy (Grid Engine) cluster. Do not set --qos (or --partition) otherwise: jobs are routed automatically. You will see the QOS names campus24 and pi_shared24 in the output of squeue and sacct, but you do not need to put them in your job scripts.
If you belong to more than one Slurm account, you must choose one with -A <account> (e.g. -A pi_gobruin, not your user name); otherwise the job is rejected.
Per-user limits (for example the maximum number of CPUs, GPUs, nodes and running jobs) depend on where the job runs. To see your accounts, where the jobs of each one run, whether you can use highp, the current limits and how busy each partition is, run:
$ h2 whoami
Tip
Always specify -A <account> in your job scripts and srun/salloc commands (it is required if you belong to more than one account), and add --qos=highp only when you want to run on your group’s nodes.
Defaults
If you do not request them explicitly:
Runtime (
--time): campus and shared jobs get 2 hours;highpjobs get the maximum of 14 days. The job is killed when it reaches its runtime.Memory (
--memor--mem-per-cpu): there is no default limit, and the job is allocated all the memory of every node it runs on. This prevents other jobs, including your own, from using the remaining cores of those nodes. Always request the memory your job needs.GPUs: jobs that do not request a GPU (
--gres=gpu:N) are restricted to CPU nodes.
Grid Engine and Slurm command equivalents
Task |
Grid Engine (legacy) |
Slurm |
|---|---|---|
Start an interactive session |
|
|
Submit a batch job |
|
|
Check your jobs |
|
|
Cancel a job |
|
|
Details of a finished job |
|
|
Job script directives |
|
|
Job ID variable |
|
|
Array task ID variable |
|
|
Note
On the Hoffman2 Cluster, qsub, qrsh, qstat and qdel do not submit or manage jobs; they print help on the Slurm equivalents.
Requesting Slurm resources
Slurm resource requests use options rather than Grid Engine complexes (-l) and parallel environments (-pe). The most common requests are:
Resource |
Slurm option |
Example |
|---|---|---|
Account |
|
|
Run on your group’s nodes (highp) |
|
|
Runtime |
|
|
Memory per node |
|
|
Memory per core |
|
|
Cores for threads (OpenMP, shared memory) |
|
|
Tasks (MPI processes) |
|
|
Nodes |
|
|
GPU cards |
|
|
Node features (CPU or GPU type) |
|
|
Job name |
|
|
Note
Grid Engine’s h_data is memory per core, which corresponds to Slurm’s --mem-per-cpu. Slurm’s --mem is the memory for the whole job on each node.
Cores and memory of the compute nodes
To choose how many cores and how much memory to request, it helps to know what the nodes have. CLUSTER_AT_A_GLANCE lists the nodes of the Slurm cluster grouped by CPU type, with the number of nodes, the cores per node, the memory per core and the totals:
$ CLUSTER_AT_A_GLANCE
CPU-type # nodes #cores/node # tot. cores memory/core GB tot memory GB
amd-epyc-9634 12 84 1008 4.464 4500.000
...
intel-gold-6342 42 48 2016 10.417 21000.000
...
intel-xeon6-6736P 56 72 4032 6.944 28000.000
TOTALS 766 - 30528 - 235604.570
A job that asks for more cores than a node has (--cpus-per-task), or for more memory than a node has (--mem, or --mem-per-cpu times the cores), never starts. Requests that fit on many nodes start sooner. The CPU type is also the feature name to select it with -C (e.g. -C intel-gold-6342). The list includes every node in the Slurm cluster, not only those in the partitions where your jobs run (see Accounts, QOS and where your jobs run). For the GPU nodes, see Checking which GPU cards are in use.
Slurm interactive sessions
Do not run CPU or memory intensive work on the login nodes (see Role of login nodes). For interactive work, start a shell on a compute node with srun:
$ srun --time=02:00:00 --mem=4G --pty $SHELL -l
or to start a session with a bash shell independently of your $SHELL:
$ srun --time=02:00:00 --mem=4G --pty bash -l
For a session with 4 cores on one node:
$ srun --time=02:00:00 --cpus-per-task=4 --mem=8G --pty $SHELL -l
On your group’s nodes, with a longer runtime (only for groups with contributed nodes in the Slurm cluster):
$ srun --qos=highp --time=1-00:00:00 --cpus-per-task=4 --mem=16G --pty $SHELL -l
Add -A <account> if you belong to more than one Slurm account.
Note
These commands will typically return something like:
srun: No --account given; setting account to your only account: gobruins
srun: No -p and no QOS; admin account defaulting to -p gobruins, qos=gobruins
srun: No GPU requested; constraining to CPU nodes (features=cpu)
srun: Job will use 1 switch
srun: Default account: gobruins
srun: Submitting to partition: gobruins
srun: Charging account: gobruins
srun: Using QOS: gobruins
indicating that the session has been allocated (you may notice that your prompt will have changed from [user@login<n>] to [user@<compute-node>]), you can now proceed running your interactive code.
Alternatively, salloc reserves the resources and opens a shell on the allocated compute node; type exit to release the allocation:
$ salloc --time=02:00:00 --ntasks=4 --mem-per-cpu=4G
this command would typically return something like:
salloc: No --account given; setting account to your only account: gobruins
salloc: No -p and no QOS; admin account defaulting to -p gobruins, qos=gobuins
salloc: No GPU requested; constraining to CPU nodes (features=cpu)
salloc: Job will use 1 switch
salloc: Default account: systems
salloc: Submitting to partition: gobruins
salloc: Charging account: gobruins
salloc: Using QOS: gobruins
salloc: Granted job allocation <JOBID>
salloc: Nodes <node-list> are ready for job
indicating that job <JOBID> has been allocated on <node-list>.
You would then run your application with:
$ srun <application>
The session ends, and the resources are released, when you exit the shell or the requested time runs out.
Opening GUI applications from a Slurm interactive session
If you have connected to the cluster via Remote Desktop or via terminal and SSH with X11 Forwarding enabled you can open GUI applications (such as the MATLAB Desktop or others) via the Hoffman2 Cluster script x11session which opens a Slurm interactive session with the correct X11 Forwarding so that you can open GUI applications. To learn how to use the x11session script you can issue,
$ x11session --help
For example for an interactive session with a runtime of 2 hours, requesting 2 cores and 4GB of memory per core:
$ x11session --time=02:00:00 --mem-per-cpu=4G -c 2
Slurm batch jobs
Non-interactive work is submitted with sbatch. Slurm job scripts start with #SBATCH directives that request resources:
#!/bin/bash
#SBATCH --job-name=myjob
#SBATCH --account=pi_gobruin
#SBATCH --time=02:00:00
#SBATCH --mem=4G
#SBATCH --output=/u/scratch/j/joebruin/myjob.%j.out
# start from a clean environment, then load what the job needs
module purge
module load gcc
./my_program
where pi_gobruin is replaced by your group’s Slurm account (see Accounts, QOS and where your jobs run; it is not your user name), /u/scratch/j/joebruin by your own scratch directory (see below), and %j is replaced by the job ID. By default standard error is written to the same file as standard output; add #SBATCH --error=... to separate them. Jobs start in the directory from which they were submitted. Add #SBATCH --qos=highp to run on your group’s nodes (see Accounts, QOS and where your jobs run).
Where to write job output
Your $HOME directory has a small quota. We recommend that jobs write their output files, and their standard output and error, to your $SCRATCH directory or, if your group has one, to your group’s project directory (see Your scratch directory and Your project directory).
Warning
Environment variables are not expanded in #SBATCH lines. A directive such as #SBATCH --output=$SCRATCH/myjob.%j.out does not write to your scratch directory: Slurm creates a directory literally named $SCRATCH in the directory from which you submitted the job, and writes the output there. To avoid it, either:
use the full path in the directive. To see it, run
echo $SCRATCH(e.g./u/scratch/j/joebruin); orleave the path out of the directive (e.g.
#SBATCH --output=myjob.%j.out) and submit the job from the directory where you want the output:$ cd $SCRATCH/myrun $ sbatch $HOME/jobs/myjob.sh
Environment variables work as usual in the commands of the script (for example cd $SCRATCH/myrun).
Loading modules in Slurm jobs
A new shell, and therefore every job, starts with a default set of modules that includes intel/2026.2.0. Many applications on the cluster were built with a different version of the Intel compilers and their modules conflict with it, for example:
$ module load gromacs/2024.3
Loading intel/2024.1.0
ERROR: Module cannot be loaded due to a conflict.
HINT: Might try "module unload intel/2026.2.0" first.
Start each job script with module purge, then load the modules the job needs. This also makes the job independent of the modules loaded in the shell from which you submitted it.
Some modules are visible only after the module they depend on is loaded (for example, many GPU applications appear only after module load cuda/12.8), so module avail does not show them. To find all the versions of an application, and the modules to load first, use:
$ module spider amber
$ h2 modules amber
$ modules_lookup -m amber
module spider lists amber/24_GPU under a heading that ends in (via cuda/12.8), the module to load first. h2 modules and modules_lookup -m print the commands to run, for example amber/24_GPU: module load cuda/12.8; module load amber/24_GPU. Load the modules in the order shown. See also Environmental modules.
Submit the script with:
$ sbatch myjob.sh
Options passed on the sbatch command line take precedence over the matching #SBATCH directives in the script, for example:
$ sbatch --time=08:00:00 --mem=16G myjob.sh
Before submitting, you can check a script against the cluster rules (missing runtime, memory, account and more) with:
$ h2 validate myjob.sh
Tip
Load modules and activate environments inside the job script rather than in your ~/.bashrc or ~/.bash_profile: environment changes in your shell startup files are inherited by every job and can conflict with what the job needs.
Building a job script with job.q
job.q writes a Slurm job script for you. It asks which software to load and what to run, picks your Slurm account, asks for the resources, checks the script with h2 validate and, if you confirm, submits it with h2 submit. Run it from the directory that holds your script or input file, which becomes the job’s working directory:
$ cd $HOME/myproject
$ job.q
job.q asks, in order:
Software: the name of a module (e.g.
R,python,matlab,gromacs, ornone). It looks the name up withmodules_lookup, lists the versions, and adds themodule loadlines, including any modules that must be loaded first (e.g.cuda/12.8foramber/24_GPU). You can add more than one package. Module names are case sensitive.What to run: your script or input file, then the command line. For a
.R,.py,.m,.jlor.shfile it suggests the command (Rscript,python3,matlab -batch,julia,bash). It also asks whether to wrap the command in/usr/bin/time -p, which reports how long it ran.Job name.
Account: if you have more than one Slurm account, choose the one to charge (your default account is preselected; see Accounts, QOS and where your jobs run).
Resources: cores (on one node), memory per core in GB, run time in hours and number of GPUs, with a GPU model if you want one. More than 24 hours is accepted only for an account that can use
highp, andjob.qthen adds--qos=highp. For a GPU job without a cuda module, it offers to add one.Notification: whether to be emailed about the job at
$USER@mail(the default is no), and when:bwhen the job begins,ewhen it ends,fif it fails, or any combination (e.g.ef, the default).Output directory for the job’s standard output and error. The default is
$SCRATCH/joblogs;job.qdoesn’t accept a directory under$HOME(see Where to write job output).
Press Enter at a prompt to accept the default, shown in brackets, and Ctrl-C to quit. The defaults are 1 core, 4 GB per core, 2 hours, no GPUs and no email.
For example, for user joebruin with account pi_gobruin and the R script analysis.R, accepting the defaults except for an email when the job ends or fails gives a job script analysis_<date>_<time>.job like this one:
#!/bin/bash
#SBATCH --job-name=analysis
#SBATCH -A pi_gobruin
#SBATCH --chdir=/u/home/j/joebruin/myproject
#SBATCH --output=/u/scratch/j/joebruin/joblogs/analysis.%j.out
#SBATCH --error=/u/scratch/j/joebruin/joblogs/analysis.%j.err
# Resources requested:
#SBATCH --time=02:00:00
#SBATCH --ntasks=1
#SBATCH --cpus-per-task=1
#SBATCH --mem-per-cpu=4G
# Email address to notify
#SBATCH --mail-user=joebruin@mail
#SBATCH --mail-type=END,FAIL
...
module purge
module load R/4.6.1
module list
...
/usr/bin/time -p \
Rscript /u/home/j/joebruin/myproject/analysis.R
(... marks lines left out here, which print the job’s node, start and end times and exit code to the output file.) job.q then shows a summary of the account, run time, cores, memory, GPUs, modules, email and output files, and the result of h2 validate, and asks Submit this job now?.
Any answer can also be given as an option on the command line, and job.q then asks only for the rest. With -y it asks nothing: it uses the defaults for what isn’t given and submits the job without asking for confirmation. For example:
$ job.q -p R -n analysis.R -s 4 -m 2 -t 8 # asks only the remaining questions
$ job.q -y -p R/4.6.1 -n analysis.R -arg 100 -M # no questions; email when it ends or fails
$ job.q -y -ns -p python -n train.py -g 1 -C A100 -t 12
The main options are:
Option |
Meaning |
|---|---|
|
module to load, e.g. |
|
script or input file to run |
|
command line to run (by default derived from |
|
argument added to the command (can be repeated) |
|
job name (by default the file name without its extension) |
|
Slurm account to charge |
|
number of cores, on one node |
|
memory per core, in GB |
|
run time in hours |
|
run with |
|
number of GPUs, and the GPU model (e.g. |
|
email |
|
when to email: any of |
|
directory for the job’s standard output and error |
|
ask nothing, use the defaults and submit |
|
write and validate the script, but don’t submit it |
|
name the script |
For the complete list, run job.q -h.
To change the script before submitting it (e.g. to add directives that job.q doesn’t ask about), run job.q -ns, edit the .job file, and submit it with:
$ h2 submit analysis_<date>_<time>.job
job.q writes single-node jobs (one task, with several cores if you ask for them). For MPI jobs over several nodes and for job arrays, start from the examples below.
Note
On the Grid Engine (legacy) cluster, job.q is a different, menu-driven script that writes Grid Engine command files (see Queue scripts).
Distributed memory (MPI) jobs
Request MPI processes with --ntasks (and --nodes/--ntasks-per-node to spread them over several nodes) and start the program with mpirun:
#SBATCH --nodes=2
#SBATCH --ntasks-per-node=32
#SBATCH --mem-per-cpu=2G
module purge
module load intel/2026.0.0 # Intel compilers and Intel MPI
mpirun ./my_mpi_program
mpirun takes the number of processes and the nodes from the Slurm allocation, so it needs no -n or host list.
Warning
Start MPI programs with mpirun, not srun. On the Hoffman2 Cluster, Intel MPI programs started with srun fail (mpi/pmi2: failed to send temp kvs to srun), and Open MPI programs started with srun silently run as many independent single-process copies (every process reports itself as rank 0 of 1). srun is fine for non-MPI commands inside a job, e.g. srun hostname.
Use Intel MPI unless your code requires Open MPI, which is available after module load cuda/12.8, then module load openmpi/5.0.2. Applications installed as modules (e.g. gromacs, amber) load their own MPI: do not load another one on top of it. Prefer a single node when your job fits on one.
Job arrays
To run the same script on many inputs, use a job array. Within each task, $SLURM_ARRAY_TASK_ID holds the task index:
#SBATCH --array=1-100
#SBATCH --output=myarray.%A_%a.out
./my_program input.$SLURM_ARRAY_TASK_ID
where %A is the array job ID and %a the task index. Array indices can go up to 1000.
Warning
For a job array, #SBATCH --mail-type (e.g. END,FAIL) sends one email for the whole array. Don’t add ARRAY_TASKS to it: Slurm would then send an email for every task, which can be hundreds of messages.
Requesting GPUs with Slurm
Request GPU cards with --gres=gpu:N and select the card type with a feature constraint (-C). Jobs that do not request --gres=gpu run only on CPU nodes. For example, for an interactive session with one A100 card:
$ srun --time=02:00:00 --mem=16G --gres=gpu:1 -C A100 --pty bash -l
or, in a batch script:
#SBATCH --gres=gpu:1
#SBATCH -C A100
You can also select cards by compute capability or GPU memory, and combine features with &, for example -C cuda_cc_8_0 or -C "gpu&vmem40G". Load a cuda module before running GPU code (not needed inside containers started with --nv).
To list the GPU nodes, their card types, the -C feature tags to select them and the partitions where they are available, run:
$ h2 gpus
The number of GPUs each user can use at the same time is limited (see h2 whoami). See also Role of GPU nodes.
Checking which GPU cards are in use
Two scripts give a quick overview of the GPU nodes. GPU_NODES_AT_A_GLANCE lists each GPU node with its card type, number of GPUs, compute capability, CPU type, number of CPU cores, memory and GPU memory:
$ GPU_NODES_AT_A_GLANCE
GPU_NODES_AT_A_GLANCE_WITH_USED_GPUs also shows, for each node, how many of its GPUs are currently allocated to jobs (#Used/#GPUs) and the partitions the node belongs to (PARTITIONS):
$ GPU_NODES_AT_A_GLANCE_WITH_USED_GPUs
Use it to gauge, at a given moment, whether cards of the type you need are free before requesting them with --gres=gpu:N -C <card>.
Note
A free GPU in this list is not necessarily available to you:
the node must be in a partition where your jobs run:
campus(accounts of groups without nodes in the Slurm cluster),pi_shared(accounts of groups with nodes in the Slurm cluster) or, with--qos=highp, your group’spi_<PI's user name>partition (see Accounts, QOS and where your jobs run). Ignore theadminpartition.the node also needs enough free CPU cores and memory for your job, which the script does not show
other pending jobs, with higher priority, may be waiting for the same GPUs
the number of GPUs you can use at the same time is limited
The output is a snapshot that can change within minutes.
Converting Grid Engine job scripts to Slurm
The h2 command can translate a Grid Engine job script (#$ directives) to Slurm, printing the result and conversion notes:
$ h2 convert-uge myjob.sh > myjob-slurm.sh
Review the result, add your Slurm account (#SBATCH -A pi_<PI's user name>) and, only to run on your group’s nodes, #SBATCH --qos=highp. Then check and submit it:
$ h2 validate myjob-slurm.sh
$ h2 submit myjob-slurm.sh
Common translations:
Grid Engine |
Slurm |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
not needed (Slurm jobs start in the submission directory) |
|
|
|
not needed |
Monitoring and canceling Slurm jobs
To list your pending and running jobs:
$ squeue --me
To cancel a job:
$ scancel <JOB_ID>
where <JOB_ID> is the job ID reported by sbatch or squeue.
To see why a job is still pending, its position in the queue and whether it fits the resources it asks for:
$ h2 why-pending <JOB_ID>
To see the details of a running or finished job, including its state, exit code, the end of its error output and likely causes of failure:
$ h2 diagnose <JOB_ID>
The standard Slurm accounting command sacct also reports finished jobs, for example:
$ sacct -j <JOB_ID> --format=JobID,JobName,State,Elapsed,ExitCode
Note
At this time the Hoffman2 Cluster does not record the CPU and memory used by each job, so sacct fields such as MaxRSS and TotalCPU are empty and sstat reports no usage (seff is not installed). To measure how much memory your program needs, run it in an interactive session and check it with top, or run it with /usr/bin/time -v ./my_program (see Maximum resident set size in its output).