Discrete-ordinates (Sn) transport source iteration with an invented kernel
/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
The program solves a 2D steady radiation-transport problem with the discrete-ordinates (Sn) method and source iteration, for a fixed number of outer iterations (no convergence stop). It reports summary statistics of the scalar flux.
Quadrature (invented). M ordinates are placed on the unit circle at angles
theta_k = 2*pi*(k + 0.5)/M with direction cosines (mu_k, eta_k) = (cos, sin) and
weights w_k = (1 + 0.3*cos(2*theta_k + 0.7)) normalised to unit total weight.
Material (invented). Each cell has a total cross-section sigma_t in [0.6, 1.4], a
scattering cross-section sigma_s0 = c*sigma_t with c in [0.35, 0.70], a linearly
anisotropic moment sigma_s1 = a*sigma_s0 with a in [-0.25, 0.25], and a distributed
external source q in [0, 1], all from a SplitMix64 counter hash of the seed.
Scattering kernel (invented, P1). The per-ordinate source is
Q_k = q + sigma_s0*phi0 + 3*sigma_s1*(mu_k*phi1x + eta_k*phi1y)
with flux moments phi0 = sum_k w_k psi_k, phi1x = sum_k w_k mu_k psi_k,
phi1y = sum_k w_k eta_k psi_k.
Sweep (step differencing). On the unit grid, each ordinate's angular flux is solved cell by cell in upwind order:
psi_k(i,j) = ( Q_k(i,j) + |mu_k|*psi_x_up + |eta_k|*psi_y_up )
/ ( sigma_t(i,j) + |mu_k| + |eta_k| )
with vacuum inflow (0) on the boundary. The upwind neighbours are the already-swept
cells in the ordinate's travel direction. Each outer iteration sweeps all ordinates and
recombines the moments in a fixed ordinate order. All reductions use a fixed order
(thread-count independent).
Input format
NX NY M SI seed
One line: grid NX, NY >= 1, ordinate count M >= 8, source iterations SI >= 1, and a
64-bit seed.
Output format
nx <NX> ny <NY> ordinates <M> source_iters <SI>
sum_phi0 <sum of scalar flux>
sum_phi0_sq <sum of squared scalar flux>
max_phi0 <max scalar flux>
phi0 <i> <j> <phi0(i,j)> (8 sampled cells)
Floating-point fields use %.10e. Comparison is numeric with rtol = 1e-6,
atol = 1e-8.
Hidden inputs
Correctness inputs (10 files) include 1 x 1, the 1D lines 1 x 40 and 40 x 1,
2 x 2, squares 16, 64, 200, a random rectangle with sides in [80, 200], and
128 x 96, 160 x 240, with M in [16, 64] and SI in [8, 20]. The timing input
is a 1600 x 1600 grid with 64 ordinates and 70 source iterations.
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-06 and atol = 1e-08; 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 1600 x 1600 grid with 64 ordinates and 70 source iterations (the invented P1-anisotropic scattering kernel and a distributed external source).
/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.