Matrix-free high-order spectral-element Poisson-Helmholtz solve
/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 complete matrix-free spectral-element (SEM) solve of a 3D variable-coefficient Poisson-Helmholtz problem
-div(kappa(x) grad u) + lambda u = f in the unit cube, u = u* on the boundary
with a manufactured solution u* (product of three shifted sines plus GAM*x*y*z), a smooth
coefficient kappa = 1.2 + 0.5 sin(B0 x + B1 y) cos(B2 z) and the matching source f. All
constants (AL, PH, BE, GAM) are drawn from the seed with the SplitMix64-based hash in the
CPU source. The pipeline is:
- Mesh.
E1 x E2 x E3hexahedral elements on a structured vertex grid; every interior vertex coordinate is perturbed by up toAMP/1000of the element width (boundary vertices stay on the cube faces). Elements are trilinear maps of the reference cube. - Discretisation. Continuous Gauss-Lobatto-Legendre (GLL) nodal basis of order
P(P+1nodes per direction, GLL quadrature on the same nodes). The global nodes form anNX x NY x NZlattice (NX = E1*P+1, ...); neighbouring elements share face, edge and vertex nodes. Per element and GLL point the program precomputes the 6 symmetric geometric factorsG = w |J| kappa J^-1 J^-Tand the mass weightw |J|. - Assembly of what must be assembled. The right-hand side (
w |J| fsummed over the elements sharing a node) and the exact diagonal of the assembled operator (used as a Jacobi preconditioner). The operator itself is never assembled:A uis applied matrix-free, element by element, with sum factorisation (Dalong r, s, t, multiply byG, applyD^Talong r, s, t, addlambda w |J| u), followed by direct stiffness summation into the global vector. Boundary nodes carry the Dirichlet lift (u = u*) and their residual rows are masked. - Spectral estimate. 30 steps of power iteration on
D^-1 A(interior nodes, random start vector from the hash) with the generalised Rayleigh quotientlmax. - Solve.
ITERSiterations of Chebyshev-accelerated Jacobi on the interval[bmax/RATIO, bmax],bmax = 1.25*lmax(three-term recurrence, no inner products). The relative residual norm||r_k|| / ||r_0||is recorded atk = 0, ITERS/4, ITERS/2, 3*ITERS/4, ITERS(integer division). - Diagnostics. Relative L2 error against
u*by GLL quadrature over all elements, relative nodal max error, discrete energyx^T A x, the quadrature meansum w |J| u_h, and the solution at 6 hash-chosen global nodes.
Every reduction in the CPU program is done in a fixed order (fixed chunks of 8192 nodes, then the chunk partials in order; per-element partials summed in element order), so its output is independent of the thread count. Floating point is FP64 throughout.
Input format
One line:
P E1 E2 E3 ITERS AMP LAM_MILLI RATIO SEED
P polynomial order, E1 E2 E3 elements per direction, ITERS Chebyshev iterations,
AMP vertex perturbation in thousandths of an element width, lambda = LAM_MILLI/1000,
RATIO = bmax / amin of the Chebyshev interval, SEED an unsigned 64-bit integer.
Output format
mesh E1 E2 E3 order P nodes NG dofs NDOF
lmax <lmax>
res <k> <relative residual> (5 lines, k = 0, ITERS/4, ITERS/2, 3*ITERS/4, ITERS)
l2err <relative L2 error>
maxerr <relative max nodal error>
energy <x^T A x>
mean <sum w|J| u_h>
node <gx> <gy> <gz> <u_h> (6 lines)
All reals are printed with %.10e. Outputs are compared numerically (see the task's
tolerance); the integers in the mesh, res and node lines must match exactly.
Hidden inputs
Correctness inputs (14 files): 2 <= P <= 8, 1 <= E1, E2, E3 <= 10, 0 <= ITERS <= 400,
0 <= AMP <= 150, 0 <= LAM_MILLI <= 10000, 2 <= RATIO <= 100000; they include a single
element with a single unknown, ITERS = 0 and ITERS = 1, an unperturbed mesh, the highest
order P = 8, strongly anisotropic element counts and a 10 x 10 x 10 mesh of order 2.
The timing input has P in {6, 7}, about 22000 elements for P = 7 (36000 for P = 6)
arranged as a near-cube (E1, E2 within one of each other, E3 chosen to hit the element
count), ITERS = 600, 60 <= AMP <= 150, 0 <= LAM_MILLI <= 3000,
1000 <= RATIO <= 8000.
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-07 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 is a near-cubic mesh of about 22000 order-7 elements (or 36000 order-6 elements), i.e. about 7.5-8 million global nodes, with 30 power iterations and 600 Chebyshev iterations (about 630 operator applications).
/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.