Running Jobs on Anvil

Module 16

From PicoCluster to a supercomputer

All semester, we have worked on PicoCluster: 20 small nodes with 4 cores each. Today we move to Anvil, a supercomputer at Purdue University that our class can use through ACCESS. Its CPU nodes each have 128 cores and about 256 GB of memory, and there are about a thousand of them.

The C, MPI, and OpenMP code we have written runs on Anvil unchanged. What changes is how we run it. Anvil is shared by researchers across the country, so we do not run programs directly. We describe what we need in a short job script, hand it to the scheduler, Slurm, and Slurm runs it on a compute node when one is free.

Today’s files:

Log in

If you have not finished setting up your account, start with Getting an ACCESS Account.

  1. Go to ondemand.anvil.rcac.purdue.edu and sign in with your ACCESS username, choosing the same identity provider as when you registered.
  2. From the Clusters menu, choose Anvil Shell Access.

You now have a terminal on Anvil. Your Anvil username is your ACCESS username with x- in front. Check it:

whoami

If you set up an SSH key, you can also connect from your own terminal with your Anvil username:

ssh x-yourname@anvil.rcac.purdue.edu

Meet the machine

Try the same commands we used on PicoCluster in Module 0:

hostname
lscpu
free -h

You are on a login node, not one of the 128-core compute nodes. Its lscpu shows a 32-core AMD EPYC processor, and free -h shows memory shared by everyone logged in. Many people share it, so it is for editing, compiling, and submitting jobs. Do not run your programs on the login node. Anvil’s rules forbid it, and we are guests.

Anvil also has a few commands of its own:

mybalance        # our class allocation and how much is left
showpartitions   # the partitions (queues) jobs can use
module list      # the software loaded for you

mybalance lists our allocations. Ours for CPU jobs is cis262533, with 50,000 SUs (core-hours). Every job script names it, every job is charged to it, and the whole class shares it. You may see other accounts with a balance of 0. Ignore them.

module list shows that a C compiler (GCC) and an MPI library (Open MPI) are already loaded, so gcc, mpicc, and srun work without any setup.

Get the code and compile it

Make a folder for today and download the files from this page:

mkdir -p ~/module16
cd ~/module16
curl -O https://www.beauchrist.com/courses/f26/cosc365/modules/module-16-running-jobs-on-anvil/anvil_hello.c
curl -O https://www.beauchrist.com/courses/f26/cosc365/modules/module-16-running-jobs-on-anvil/omp_job.sh
curl -O https://www.beauchrist.com/courses/f26/cosc365/modules/module-16-running-jobs-on-anvil/mpi_hello.c
curl -O https://www.beauchrist.com/courses/f26/cosc365/modules/module-16-running-jobs-on-anvil/mpi_job.sh
ls

Compiling is fine on the login node. It is quick, and it is what login nodes are for:

gcc -Wall -O2 -fopenmp -o anvil_hello anvil_hello.c
mpicc -Wall -O2 -o mpi_hello mpi_hello.c

A first job script

A job script is an ordinary shell script with extra comment lines starting with #SBATCH. Slurm reads those lines to learn what the job needs. Here is omp_job.sh:

#!/bin/bash
#SBATCH -A cis262533          # our class allocation (mybalance shows it)
#SBATCH -p shared             # share a node; we pay only for the cores we ask for
#SBATCH -J anvil_hello        # job name, shown by squeue
#SBATCH -N 1                  # 1 node
#SBATCH -n 1                  # 1 task (one process)
#SBATCH -c 8                  # 8 cores for that task
#SBATCH -t 00:05:00           # stop after 5 minutes at most
#SBATCH -o anvil_hello_%j.out # output file; %j becomes the job ID

# Everything below runs on a compute node, not the login node.
export OMP_NUM_THREADS=$SLURM_CPUS_PER_TASK

echo "Job $SLURM_JOB_ID started $(date)"
./anvil_hello
echo "Job finished $(date)"
Option Meaning
-A The account to charge. Required.
-p The partition: which group of nodes to use.
-N The number of nodes.
-n The number of tasks. For MPI, one task is one process.
-c The number of cores per task. For OpenMP, one core per thread.
-t The time limit, as hours:minutes:seconds. Slurm stops the job when it runs out.
-o The file that receives everything the job prints.

Slurm sets SLURM_CPUS_PER_TASK to the value of -c, so the script tells OpenMP to start exactly as many threads as we have cores. Asking for more threads than cores would only make them take turns.

Submit, watch, and read the output

sbatch omp_job.sh        # submit; prints "Submitted batch job 1234567"
squeue -u $USER          # your waiting and running jobs

In squeue, the ST column shows the job’s state: PD means pending (waiting for cores) and R means running. A short job often finishes before you can look, and then it no longer appears at all.

When it is done, the output is in a file named after the job ID:

ls
cat anvil_hello_*.out

You should see a node name that is not the login node, 8 threads, and the cores they ran on. To cancel a job that is stuck or wrong, use its ID:

scancel 1234567

Partitions and what they cost

Our allocation is measured in core-hours: one core for one hour. How a job is charged depends on its partition:

Partition Use it for Limits and charges
shared Jobs on part of one node Up to 128 cores. Charged only for the cores you request.
debug Quick tests Up to 2 nodes and 2 hours, one running job per person.
wholenode Jobs that need entire nodes, such as MPI across nodes Charged for all 128 cores of every node, even if you use 1.

So use shared for everything we do in class unless I say otherwise. A 5-minute job with 8 cores costs at most \(8 \times 5/60 \approx 0.7\) core-hours. The same 5 minutes on one wholenode node costs about 10.7 core-hours, whether or not you use the cores. The time limit matters too. A job that hangs keeps costing until it reaches its limit, so keep -t short.

An MPI job

mpi_job.sh runs 16 MPI processes on one node:

#!/bin/bash
#SBATCH -A cis262533          # our class allocation (mybalance shows it)
#SBATCH -p shared
#SBATCH -J mpi_hello
#SBATCH -N 1                  # 1 node
#SBATCH -n 16                 # 16 MPI processes
#SBATCH -t 00:05:00
#SBATCH -o mpi_hello_%j.out

# srun starts one copy of the program for each task. It replaces mpirun.
srun ./mpi_hello

There is no -n 16 after srun. It reads the number of tasks from the #SBATCH lines. Submit it with sbatch mpi_job.sh, and read mpi_hello_*.out. The greetings arrive in any order, just as on PicoCluster.

Experiments

Change one thing at a time, submit again, and compare the output files.

  1. Change -c 8 to -c 1, then to -c 32. Does the thread count follow? Which cores do the threads use?
  2. Remove the export OMP_NUM_THREADS line, and keep -c 8. How many threads start now? (OpenMP chooses for itself when nothing tells it.)
  3. Change -t 00:05:00 to -t 00:01:00, and add sleep 120 before ./anvil_hello. What happens, and what does the output file say?
  4. In mpi_job.sh, try -n 64. Then try -n 200 with -N 1. Why does Slurm reject the second job?
  5. Copy your Project 4 program to Anvil and run it on a 900 × 600 image with 1, 8, 32, and 64 threads. How far does the speedup go compared with PicoCluster’s 4 cores? (Ask for as many cores with -c as you use threads.)

Check your understanding

  1. Why should you not run ./anvil_hello directly in the Anvil shell?
  2. What is the difference between -n and -c? Which one matters for an OpenMP program, and which for an MPI program?
  3. Your job has been in state PD for several minutes. What does that mean? Is anything wrong?
  4. Why is wholenode a poor choice for a job that uses 8 cores?
  5. Where does a job’s output go, if not to your screen?
  1. That runs it on the login node, which many people share. Programs belong on compute nodes, through Slurm. Compiling and editing on the login node are fine.
  2. -n is the number of tasks (processes). -c is the number of cores each task gets. An OpenMP program is one task with many cores, so it uses -c. An MPI program is many tasks, so it uses -n.
  3. The job is pending, waiting for Slurm to find the cores it asked for. That is normal on a busy machine. Asking for fewer cores or less time can help it start sooner.
  4. wholenode charges for all 128 cores of the node, so the other 120 are paid for but wasted. shared charges only for the 8 requested.
  5. To the file named by -o, in the folder you submitted from. Without -o, Slurm names it slurm-<job ID>.out.
Back to top