<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet href="https://tcanabrava.github.io/feed_style.xsl" type="text/xsl"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
    <tabi:metadata xmlns:tabi="https://github.com/welpo/tabi">
        <tabi:base_url>https:&#x2F;&#x2F;tcanabrava.github.io</tabi:base_url>
        <tabi:separator>
            •
        </tabi:separator>
        <tabi:about_feeds>This is a web feed, also known as an Atom feed. Subscribe by copying the URL from the address bar into your newsreader. Visit About Feeds to learn more and get started. It&#x27;s free.</tabi:about_feeds>
        <tabi:visit_the_site>Visit website</tabi:visit_the_site>
        <tabi:recent_posts>Recent posts</tabi:recent_posts>
        <tabi:last_updated_on>Updated on $DATE</tabi:last_updated_on>
        <tabi:default_theme>dark</tabi:default_theme>
        <tabi:post_listing_date>date</tabi:post_listing_date>
        <tabi:current_section>hpc</tabi:current_section>
    </tabi:metadata><title>Tomaz Canabrava Ramblings - hpc</title>
        <subtitle>Somewhat updated list of C++, Qt and KDE bits</subtitle>
    <link href="https://tcanabrava.github.io/tags/hpc/atom.xml" rel="self" type="application/atom+xml"/>
    <link href="https://tcanabrava.github.io/tags/hpc/" rel="alternate" type="text/html"/>
    <generator uri="https://www.getzola.org/">Zola</generator><updated>2026-12-04T00:00:00+00:00</updated><id>https://tcanabrava.github.io/tags/hpc/atom.xml</id><entry xml:lang="en">
        <title>Running a CUDA Mandelbrot on Slurm with easypp</title>
        <published>2026-12-04T00:00:00+00:00</published>
        <updated>2026-12-04T00:00:00+00:00</updated>
        <author>
            <name>Tomaz Canabrava</name>
        </author>
        <link rel="alternate" href="https://tcanabrava.github.io/easypp-on-slurm/" type="text/html"/>
        <id>https://tcanabrava.github.io/easypp-on-slurm/</id>
        
            <content type="html">&lt;p&gt;I started easypp for small C and C++ projects. Put a program in &lt;code&gt;src&#x2F;bin&lt;&#x2F;code&gt;, put a library under &lt;code&gt;src&#x2F;libs&lt;&#x2F;code&gt;, 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.&lt;&#x2F;p&gt;
&lt;p&gt;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 &lt;code&gt;easypp run&lt;&#x2F;code&gt; creates the Slurm launcher and the modules dependencies for &lt;code&gt;lmod&lt;&#x2F;code&gt; and &lt;code&gt;easybuild&lt;&#x2F;code&gt;, when needed.&lt;&#x2F;p&gt;
&lt;span id=&quot;continue-reading&quot;&gt;&lt;&#x2F;span&gt;&lt;h2 id=&quot;supercomputing-mandelbrot&quot;&gt;Supercomputing Mandelbrot&lt;&#x2F;h2&gt;
&lt;p&gt;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.&lt;&#x2F;p&gt;
&lt;p&gt;The example is three files under &lt;code&gt;examples&#x2F;hpc-fractal&lt;&#x2F;code&gt; in the easypp checkout.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;src&#x2F;&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  bin&#x2F;fractal.cpp&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  libs&#x2F;fractal&#x2F;mandelbrot.hpp&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  libs&#x2F;fractal&#x2F;mandelbrot.cu&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;See the lack of makefiles.&lt;&#x2F;p&gt;
&lt;p&gt;The C++ program includes &lt;code&gt;fractal&#x2F;mandelbrot.hpp&lt;&#x2F;code&gt;, which points easypp to the
library folder. The &lt;code&gt;.cu&lt;&#x2F;code&gt; file selects &lt;code&gt;nvcc&lt;&#x2F;code&gt;. 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.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;finding-mpi-and-cuda-on-the-cluster&quot;&gt;Finding MPI and CUDA on the cluster&lt;&#x2F;h2&gt;
&lt;p&gt;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 &lt;code&gt;CC&lt;&#x2F;code&gt;, &lt;code&gt;CXX&lt;&#x2F;code&gt; and the pkg-config paths.
When &lt;code&gt;nvcc&lt;&#x2F;code&gt; 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. &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;lmod.readthedocs.io&#x2F;en&#x2F;latest&#x2F;010_user.html&quot;&gt;Lmod user guide&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;p&gt;After a successful build that discovered modules, easypp writes their names
to &lt;code&gt;hpc.conf&lt;&#x2F;code&gt;. I can read it, change a version, and run again. Here is what
that file can look like with one site’s module names.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;ini&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-punctuation&quot;&gt;[&lt;&#x2F;span&gt;&lt;span class=&quot;z-entity z-name z-section z-group-title z-ini&quot;&gt;lmod&lt;&#x2F;span&gt;&lt;span class=&quot;z-punctuation&quot;&gt;]&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;mpi&#x2F;OpenMPI&#x2F;4.1.6-GCC-13.2.0&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-source&quot;&gt;system&#x2F;CUDA&#x2F;12.6.0&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;The &lt;code&gt;[easybuild]&lt;&#x2F;code&gt; section is for exact &lt;code&gt;.eb&lt;&#x2F;code&gt; recipes that I add myself. If
their corresponding modules in &lt;code&gt;[lmod]&lt;&#x2F;code&gt; 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. &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;docs.easybuild.io&#x2F;using-easybuild&#x2F;&quot;&gt;EasyBuild usage guide&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;h2 id=&quot;from-a-slurm-allocation-to-a-picture&quot;&gt;From a Slurm allocation to a picture&lt;&#x2F;h2&gt;
&lt;p&gt;On the Supercomputer, inside of the &lt;code&gt;examples&#x2F;hpc-fractal&lt;&#x2F;code&gt; folder, alloc your slice:&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;salloc&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; --partition=interactive --qos=debug --constraint=gpu --gres=gpu:1&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-character z-escape&quot;&gt; \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-string&quot;&gt;    --nodes=1 --ntasks=2 --cpus-per-task=2 --time=00:05:00&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-character z-escape&quot;&gt; \&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-string&quot;&gt;    bash --noprofile --norc&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Once Slurm grants the allocation, run easypp directly in that shell. This
assumes the executable is on your &lt;code&gt;PATH&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;easypp&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; run --release -j2 --&lt;&#x2F;span&gt;&lt;span class=&quot;z-constant z-numeric&quot;&gt; 321 241&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; smoke.ppm&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;On the first run, easypp writes &lt;code&gt;run.slurm&lt;&#x2F;code&gt; in the project directory and
uses it to start a job step with &lt;code&gt;srun&lt;&#x2F;code&gt;. 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. &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;slurm.schedmd.com&#x2F;quickstart.html&quot;&gt;Slurm job steps&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;p&gt;The launcher defaults OpenMP to the two CPUs per task. The &lt;code&gt;-j2&lt;&#x2F;code&gt; on
&lt;code&gt;easypp run&lt;&#x2F;code&gt; 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.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;Wrote smoke.ppm with 2 MPI ranks and 4 OpenMP threads total&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;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.&lt;&#x2F;p&gt;
&lt;pre class=&quot;giallo z-code&quot;&gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-entity z-name z-function&quot;&gt;cargo&lt;&#x2F;span&gt;&lt;span class=&quot;z-string&quot;&gt; rustc --release --locked --bin easypp -- -C target-feature=+crt-static&lt;&#x2F;span&gt;&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;&lt;h2 id=&quot;what-i-checked&quot;&gt;What I checked&lt;&#x2F;h2&gt;
&lt;p&gt;On Iris, two ranks shared one Tesla V100. I edited &lt;code&gt;run.slurm&lt;&#x2F;code&gt; 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&#x2F;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.&lt;&#x2F;p&gt;
&lt;p&gt;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.&lt;&#x2F;p&gt;
&lt;p&gt;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. &lt;a rel=&quot;external&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;tcanabrava&#x2F;easypp&quot;&gt;easypp on GitHub&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
</content>
        <summary type="html">A small C++ project that uses MPI, OpenMP and CUDA, and what easypp can infer from its source tree on a cluster.</summary>
        </entry>
</feed>
