Skip to content

Tutorial ​

Ten chapters that take a field solver from one Runge–Kutta step written by hand to a production loop on the GPU. Each chapter is a complete program in docs/examples/src/. The code on these pages is that program, and the output is what it printed when the documentation was built (bash scripts/docs_examples.sh regenerates both, and CI fails when they drift).

The model problem is the linear advection ut+ux=0 on the periodic unit interval, split into 4 blocks of 16 cells with one ghost cell each. The residual is the central difference Ri=−(ui+1−ui−1)/(2Δx), computed by GIDEON's gideon_fd_d1_c2: SELAH is the source of the time operators, GIDEON of the space operators, and a solver built on SELAH takes its residual from a space-operator library rather than writing the stencil itself. Its semi-discrete solution is known exactly, u(x,t)=sin⁡(2π(x−ct)) with c=sin⁡(2πΔx)/(2πΔx), so every error printed below belongs to the time integrator alone.

ChapterYou learn
1. A step by handwhat a Runge–Kutta step is in SELAH's terms: the flat kernels selah_stage_state and selah_step_update
2. The cataloguethe schemes, their coefficients, storage forms and register counts; the splittings
3. A field and a boxthe block-structured field, ghost cells, the two layouts, what a kernel touches and what it leaves alone
4. The stepperdriving one step stage by stage: what the stepper does, and what the caller does
5. Low-storage formsthe same scheme with 2 registers instead of s + 1, and the same answer
6. Splittingspartitions, flows and stage_partition on a Hamiltonian oscillator
7. Maskssolid cells the integrator must not touch
8. The flux registerstage_weight: the conservation identity behind AMR refluxing
9. On the GPUthe same solver on device memory, with FUNDAL
10. Productionyour own register pool, stage 1 without a copy, the fused step residual

Building the examples ​

Every program is compiled the way your own program would be: against the static library that FoBiS builds, which carries PENF and FUNDAL.

bash
fobis fetch                       # PENF, FUNDAL and GIDEON into src/third_party
fobis build --mode static-gnu     # lib/gnu/static/libselah.a and its modules
gfortran -cpp -DFUNDAL_NO_MPI -I lib/gnu/static/mod -I src/third_party/FUNDAL/src/lib \
         docs/examples/src/stepper.F90 lib/gnu/static/libselah.a -o stepper
./stepper

bash scripts/docs_examples.sh does this for every example, and rewrites the snippets and outputs these pages include.

GPL-3.0-or-later, BSD-2-Clause, BSD-3-Clause or MIT, at your choice