Key Points

Introduction


  • A relatively simple program can become a challenge when we need to scale up.
  • For example, when we need to handle bigger datasets in disk or memory.
  • Or we need to work with more complex models that require more compute power (High Performance Computing or HPC).
  • Or when we need to run the program many many times (High Throughtput Computing or HTC).
  • Or all of the above…

Connecting to Falcon - SSH keys


  • A key pair has a public key (installed on Falcon, safe to share) and a private key (never shared).
  • Protect the private key with a passphrase.
  • An SSH config entry gives the connection a short name that ssh, scp, rsync and VS Code all understand.
  • Add the key to an agent with -t so the passphrase is remembered for a limited time.

Finding the software and libraries you need


  • Python packages are often extensions inside a bundle module, and module load numpy fails if there is no module with that name.
  • module spider finds everything, including extensions, and tells you which module to load.
  • export LMOD_AVAIL_EXTENSIONS=yes makes module avail show extensions as well.
  • A module name has the form software/version-toolchain, and modules in one session should share a toolchain generation.
  • In job scripts use --login, module purge, and full module names.

Estimating resources


  • Start your resource request from the machine where the code already runs, then measure and refine.
  • --ntasks counts processes and --cpus-per-task counts threads per process. A multi-threaded Python script is one task with several CPUs.
  • #SBATCH lines must come before the first command.
  • sbatch submits, squeue shows the queue, scancel cancels and sacct shows finished jobs.
  • Look in the .e file first when something goes wrong.
  • A supercomputer is many computers, not a faster computer: a first run is often no faster than a laptop.
  • Re-running a job in the same directory overwrites its results.

Making the job script safe


  • Slurm defines environment variables such as SLURM_JOB_ID, SLURM_SUBMIT_DIR and SLURM_CPUS_PER_TASK inside every job.
  • Put ${SLURM_JOB_ID} in file and directory names so that jobs cannot overwrite each other.
  • Always write ${NAME} with curly brackets, so Bash cannot misread where a variable name ends.
  • Start job scripts with set -euo pipefail to stop on errors, unset variables and failed pipelines.
  • Run in a unique scratch directory, copy back what you need and delete the directory only after everything succeeded.
  • Scratch has a quota on space and on the number of files. Leftover files count against both.

Can more cores make it faster?


  • More CPUs do not automatically mean a faster job. Measure it with a scaling test before asking for many.
  • Speedup is T(1) / T(N) and efficiency is speedup divided by the number of CPUs.
  • Amdahl’s law: the part of a program that cannot use extra CPUs limits the speedup to 1 / (1 - p).
  • The fastest setting is rarely the most efficient. Choose a request that balances run time and cost.
  • Asking for too much can make a job slower, and always makes it more expensive. Repeat surprising measurements.
  • For many independent runs, run them side by side instead of making one run bigger.

Measuring efficiency with sacct and seff


  • sacct shows what your finished jobs requested and used. seff summarises one job as CPU and memory efficiency.
  • CPU efficiency is the CPU time used divided by (CPUs × wall-clock time). With no other waste it equals speedup divided by CPUs.
  • Idle CPUs during the serial part of a program are the main reason efficiency is below 100%.
  • seff measures how busy the CPUs were, not how useful: spinning, memory stalls and extra work all count as busy.
  • Judge a job by wall-clock time first, then by total CPU time compared with a one-CPU run, and only then by efficiency.
  • Use measured time and peak memory, plus a safety margin, to right-size the next request.

Watching a job run: interactive sessions, tmux, htop and ps


  • An interactive session (srun --pty bash) gives you a shell on a compute node. Exit it when you are done, because it holds its resources.
  • Start tmux on a named login node first and run srun inside it. The session then survives a lost connection.
  • A second shell in the same allocation (srun --jobid=<id> --overlap --pty bash) lets you watch a running job.
  • htop shows CPU use live. ps -L shows what each thread is doing, and the number of threads in state R is the number of busy CPUs.
  • The %CPU in ps is an average over the process’s life, not a live value.
  • Our script is parallel for a few seconds and serial for the rest, which is what limited the speedup.
  • Busy CPUs are not necessarily useful work. A profiler shows what they are doing.

Finding the bottleneck with a profiler


  • A profiler measures where a program spends its time, so you can improve the code that matters.
  • map --profile runs a program under MAP in a job script and writes a .map file.
  • Copy the .map file out of the scratch directory before the script cleans it up, and open it in the Linaro Forge client on your computer.
  • The source view shows the hotspots: the lines with the largest share of the time.
  • The summary percentages are a first impression. The source and timeline views have the detail.

Improving the code


  • Profile first, change one thing at a time, and measure after each change.
  • Trying a library routine is good practice, but it only helps if the time is where the routine works.
  • A newer software stack is a cheap thing to try, and can speed up a program without any change to the code.
  • Always check that the results of the faster version still agree with the original.
  • After a change, measure the scaling again: the serial part, and so the limit for extra CPUs, may have changed.

Running many analyses: array jobs and GNU Parallel


  • An array job creates many tasks from one script. SLURM_ARRAY_TASK_ID tells each task which one it is, and %A_%a names its log files.
  • Each task is a separate job: it can fail and be rerun on its own (--array=3,7), and it counts towards the job limits.
  • A QOS limits what a user can have submitted, running or in use at once. The limits protect the cluster from mistakes and overload, and can be changed for a user once we know the intended use.
  • Many short tasks load the scheduler and waste time on start-up. Use array jobs for analyses of more than about an hour, and group shorter work into fewer, longer jobs.
  • GNU Parallel runs many tasks inside one Slurm job. Set the number of tasks at once (-j), the threads per task and the total memory deliberately.
  • Choose by task length, number of tasks, differing resource needs and how you want failures handled.

Using GPUs


  • GPU nodes are in separate partitions, and you ask for a GPU explicitly (--gres=gpu:1).
  • The software for GPU nodes can be a different set of modules, and may be visible only on GPU nodes. Check module list.
  • Check that Python sees the GPU (cuda.is_available(), nvidia-smi) before running anything long.
  • A kernel runs on the GPU with many threads at once. Data has to be copied to and from the GPU, which takes time.
  • A GPU is not automatically faster: small problems, start-up, transfers and double-precision speed all matter.
  • Libraries such as CuPy save you from writing kernels for common operations.