Running a CUDA Mandelbrot on Slurm with easypp

I started easypp for small C and C++ projects. Put a program in src/bin, put a library under src/libs, and the includes tell the tool which library the program needs, and magically it finds everything. I wanted to take that workflow to a cluster and see where it would hold up.

The first useful result was a 321 × 241 image of the Mandelbrot set. Two MPI ranks shared a GPU on the Luxembourg Supercomputer, and each rank used two OpenMP threads. A simply easypp run creates the Slurm launcher and the modules dependencies for lmod and easybuild, when needed.

Supercomputing Mandelbrot

Mandelbrot makes it easy to see what each parallel API does. MPI gives each process a range of rows. A CUDA kernel computes how many iterations each pixel takes to escape. OpenMP colors those pixels on the CPU. MPI gathers the colored rows back to rank zero, which writes the image. An odd height gives the two ranks different numbers of rows, so even a tiny picture exercises the gather.

The example is three files under examples/hpc-fractal in the easypp checkout.

src/
  bin/fractal.cpp
  libs/fractal/mandelbrot.hpp
  libs/fractal/mandelbrot.cu

See the lack of makefiles.

The C++ program includes fractal/mandelbrot.hpp, which points easypp to the library folder. The .cu file selects nvcc. The MPI header and OpenMP pragmas tell the tool that the host build needs MPI and OpenMP. This gives students a concrete way to see the connection between the API they use and the things their program needs to compile and link.

Finding MPI and CUDA on the cluster

A header gives me a dependency. The cluster still decides which compiler and library installations are available together. easypp uses the environment that is already active, including CC, CXX and the pkg-config paths. When nvcc or MPI metadata is missing, it can probe the CUDA and MPI modules visible in Lmod. It checks that a candidate supplies the missing tool or metadata and preserves the modules already loaded. If several candidates work, easypp reports them and lets me choose. Lmod user guide

After a successful build that discovered modules, easypp writes their names to hpc.conf. I can read it, change a version, and run again. Here is what that file can look like with one site’s module names.

[lmod]
mpi/OpenMPI/4.1.6-GCC-13.2.0
system/CUDA/12.6.0

The [easybuild] section is for exact .eb recipes that I add myself. If their corresponding modules in [lmod] cannot be loaded, easypp can ask an available EasyBuild installation to provision the recipes under my user prefix. That makes the choice visible and gives a collaborator something concrete to reproduce on the same module stack. EasyBuild usage guide

From a Slurm allocation to a picture

On the Supercomputer, inside of the examples/hpc-fractal folder, alloc your slice:

salloc --partition=interactive --qos=debug --constraint=gpu --gres=gpu:1 \
    --nodes=1 --ntasks=2 --cpus-per-task=2 --time=00:05:00 \
    bash --noprofile --norc

Once Slurm grants the allocation, run easypp directly in that shell. This assumes the executable is on your PATH.

easypp run --release -j2 -- 321 241 smoke.ppm

On the first run, easypp writes run.slurm in the project directory and uses it to start a job step with srun. It reuses that file on later runs, so I can edit the launcher when I need a different binding or a site-specific option. If I start easypp inside a job step, it builds and runs there. The shared project lock lets the ranks take turns through the build. Slurm job steps

The launcher defaults OpenMP to the two CPUs per task. The -j2 on easypp run controls the build jobs. Here’s what the program prints when the GPU has computed the image and rank zero has written the PPM file.

Wrote smoke.ppm with 2 MPI ranks and 4 OpenMP threads total

For the cluster checks, I built a static x86-64 executable locally and copied it over. This is handy on clusters with older Rust toolchains or system libraries. The release build command is below. There is also an EasyBuild recipe for putting a prebuilt executable on a group’s module path.

cargo rustc --release --locked --bin easypp -- -C target-feature=+crt-static

What I checked

On Iris, two ranks shared one Tesla V100. I edited run.slurm to print a line on the second run, saw the line in the output, and got a byte-identical image. After splitting easypp into a Rust workspace, I built the tool again and ran a CPU-only MPI/OpenMP fixture on Aion. It reported two ranks and four threads. The follow-up Iris allocation timed out in the queue, so the GPU result is from the earlier build.

There’s a caveat if you put several kinds of program in the same project. The launcher currently looks for MPI across the project. An MPI test can make it start several copies of a serial executable. For a project like that, the generated script is where I can set the task count explicitly.

The part I like about this example is that the decisions worth explaining are still easy to find. The row split is in the C++ program. The GPU work is in the CUDA file. The allocation describes the resources we asked for. A student can change one of those pieces and see the effect on the next picture. easypp on GitHub