Nodal DG (GLL, degree 4-7) advection-absorption with Rusanov fluxes and SSP-RK3
/app/cpu/main.cpp is the source of a multicore CPU program (C++17, OpenMP).
The program takes one input-file path (PROGRAM INPUT_FILE) and writes its result to stdout.
What the program computes
A nodal discontinuous Galerkin (DGSEM) simulation of 2D linear advection with absorption and a source on the periodic unit square:
u_t + d/dx(ax u) + d/dy(ay u) = -sigma(x, y) u + s(x, y)
- Mesh and basis.
E x Esquare elements (elemente = ey*E + ex), tensor-product Gauss-Lobatto-Legendre nodes of degreeP(NP = P+1nodes per direction, node(i, j)of elementestored ate*NP*NP + j*NP + i,ialong x). Nodes, quadrature weights and the differentiation matrixDcome fromgll()in the CPU source. The mass matrix is the diagonal GLL quadrature (collocation). - Velocity. A stream function
psi(6 random Fourier modes, normalised so that|ax|, |ay| <= 1) is sampled at the nodes; in every element the velocity is the derivative of its nodal interpolant:ax = dpsi/dy,ay = -dpsi/dx(applied withD).sigma >= 0andsare smooth random fields; the initial field is a sum of Fourier modes and periodic rational bumps. All trigonometric values are taken from 1D tables over node coordinates (see the CPU source). - Semi-discretisation (strong form). Per element and node, with
F = ax u,G = ay uand2/h = 2E:du/dt = -2E * [ sum_m D[i][m] F(m,j) + sum_m D[j][m] G(i,m) + surface terms ] - sigma u + s. Surface terms act only on element-boundary nodes: at the west face-(F* - F)/w_0, at the east face+(F* - F)/w_P, likewise south/north withG. The numerical flux at a face node with left (or lower) state(uL, aL)and right (or upper) state(uR, aR)(normal velocity components) is the Rusanov flux with an extra penaltyNUF:F* = (aL uL + aR uR)/2 - (max(|aL|, |aR|) + NUF) (uR - uL)/2. - Time stepping.
STEPSsteps of the three-stage SSP Runge-Kutta scheme (Shu-Osher form, as in the CPU source) with stepDT.
All arithmetic is FP64. The problem is linear and dissipative, so rounding differences stay at rounding level. Any correct implementation is accepted (other loop orders, fused kernels, operators in registers or shared memory, other summation orders) as long as the printed numbers agree within the tolerance below.
Input format
One line: E P STEPS DT NUF SIG SEED (E >= 1, 1 <= P <= 7, STEPS >= 0 integers, DT,
NUF >= 0, SIG >= 0 decimals, SEED unsigned 64-bit).
Output format
check K step S mass M l2 L umax X (8 lines, K = 1..8)
blocks B
B lines of B values
probe e i j U (8 lines)
- Checkpoint
Kis taken after stepceil(K * STEPS / 8)(all at step 0 whenSTEPS = 0):mass = sum w_i w_j u / (4E^2)(the integral ofu),l2 = sqrt(sum w_i w_j u^2 / (4E^2)),umax = max |u|over all nodes. B = min(16, E); the B x B table holds averages of element means (sum w_i w_j u / 4) over blocks of elementsex in [bx*E/B, (bx+1)*E/B),ey in [by*E/B, (by+1)*E/B).- Probes are node values at positions derived from the seed.
Numbers are printed with %.12e and compared with the tolerance given below.
Hidden inputs
1 <= E <= 800,1 <= P <= 7,0 <= STEPS <= 720,0 <= NUF <= 0.5,0 <= SIG <= 2;DT = c / (E (2P+1) (1+NUF))withcin[0.12, 0.18](stable).- Correctness inputs include
E = 1(an element that is its own neighbour),P = 1,P = 7,STEPS = 0,NUF = 0,SIG = 0, and oneE = 384, P = 7case with a single step. - The timing input has
Pin 4..7,E = round(3072/(P+1)) +- 8(about 9.4M nodes) and 620-720 steps (three operator evaluations per step).
Your task
Port this program to CUDA in /app/gpu/main.cu: same command line (PROGRAM INPUT_FILE),
same output on stdout. Then make it as fast as you can on the GPU while keeping the output correct.
The main computation must execute on the GPU. Renaming CPU code to .cu, running a
CPU fallback, or launching a dummy kernel while computing the answer on the CPU does not satisfy this task.
The CPU source is the specification: when this text and the code disagree, the code wins.
This sandbox is for writing the source only: it has g++ and the CPU program, but no CUDA
compiler and no GPU. Compilation, execution and verification happen later on an H100 in a
separate verifier, and a port that does not compile is rejected, so check your logic against
the CPU program before you finish (for example by emulating your kernels on the host).
How your port is verified
- Only
/app/gpu/main.cuis collected. It is compiled withnvcc -O3 -arch=sm_90 -std=c++17 -o port /app/gpu/main.cu; no extra libraries are linked. The CUDA runtime and the header-only libraries that ship with the CUDA toolkit (CUB, Thrust, libcu++) are allowed. - Your source must not contain any of:
system(,popen(,fork(,exec*,dlopen(,getenv(,#include <filesystem>,/tests/,/proc/. The program may read only the input file it is given. - Verification runs on one H100 in a fresh container without network. Hidden inputs are generated with a fresh random seed at verification time.
- Correctness: every hidden input (small edge cases plus a large timing input) must pass.
Your output must have the same tokens as the CPU program's output. Numeric tokens may differ by at most
atol + rtol*|expected|with rtol = 1e-09 and atol = 1e-11; every other token must be identical. Any mismatch, crash or timeout is rejected. - GPU execution is checked: a port that computes its answer on the CPU is rejected even when its output is correct.
- Speed: The timing input uses degree P in 4..7 on an E x E mesh with E ~ 3072/(P+1) (about 9.4M nodes) and 620-720 SSP-RK3 steps.
/app/inputs/timing_example.inhas the shape and size of the hidden timing input. Your port is timed against a reference GPU port on it; the faster your port, the higher its score. /app/inputs/holds public input examples for understanding the input format.