Restarted GMRES(m) with an invented polynomial preconditioner
/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 generated nonsymmetric sparse linear system A x = b with
restarted GMRES(m), right-preconditioned by an invented polynomial preconditioner,
running a fixed number of restart cycles (no convergence-based stopping).
Operator. For N unknowns each row i has one strong convective link to column
(i+1) mod N and R weak random links. Writing D for the diagonal, the scaled
operator D^{-1}A equals I + CONV*(forward shift) + (weak random links) with
CONV = 0.985 and each weak scaled link drawn uniformly from [-WEAK, WEAK],
WEAK = 0.06. The diagonal is d_i = 2 + u with u a hashed value in [0,1); every
off-diagonal value is d_i times its scaled weight. The right-hand side b_i is a
hashed value of order one. All data come from a SplitMix64-style counter hash of the
seed, so element i is reproducible independently. This operator is strongly
non-normal, so GMRES(m) only partially converges in the fixed budget.
Preconditioner (invented). M^{-1} r is four damped-Jacobi residual-correction
steps started from zero with the fixed relaxation schedule
omega = {0.80, 1.15, 0.60, 1.05}:
z_0 = omega_0 D^{-1} r, then z_k = z_{k-1} + omega_k D^{-1}(r - A z_{k-1}).
GMRES(m). Each of the cycles outer cycles: compute the true residual
r = b - A x, beta = ||r||, v_1 = r/beta; run exactly m Arnoldi steps with
modified Gram-Schmidt (w = A M^{-1} v_j, orthogonalise against v_1..v_j,
normalise to get v_{j+1}); maintain the least-squares solution with Givens
rotations on the (m+1)-by-m Hessenberg; back-substitute and update
x += M^{-1}(V_m y) (right preconditioning).
Floating-point reductions (dot products and norms) are accumulated in a fixed, thread-count-independent order.
Input format
N R m cycles seed
One line. N >= 1 unknowns, R >= 0 weak links per row, restart dimension m >= 1,
cycles >= 1, and a 64-bit seed.
Output format
n <N> nnz <nnz> m <m> cycles <cycles>
residual_norm <||b - A x||_2>
rhs_norm <||b||_2>
sol_norm <||x||_2>
sum_x <sum_i x_i>
sum_abs_x <sum_i |x_i|>
sample <i0> <x_i0>
... (8 sampled solution entries)
Floating-point fields use %.10e. Comparison is numeric with rtol = 1e-5,
atol = 1e-6.
Hidden inputs
Correctness inputs (10 files, one query each) include N = 1, 2, 3, 5 (tiny, where the
basis saturates), N = 100, 1000, 4096, a random N in [30000, 60000], and
N = 120000 and N = 250000, with R in [0, 9], m in [4, 24] and cycles in
[2, 4]. The timing input has the shape and size of /app/inputs/timing_example.in.
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-05 and atol = 1e-06; 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:
/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.