Ensemble RK4 of damped chemo-mechanical oscillator chains
/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
An ensemble of S independent damped "chemo-mechanical" oscillator chains, each integrated
with the classical fixed-step 4th-order Runge-Kutta method in double precision.
Chain s has L sites. Site i carries a displacement x_i, a velocity v_i and a
concentration c_i:
x_i' = v_i
v_i' = -k_i x_i - a_i x_i^3 - (g_i + e_i c_i) v_i + K (x_{i-1} - 2 x_i + x_{i+1})
c_i' = r_i (x_i^2 / (1 + x_i^2) - c_i) + D (c_{i-1} - 2 c_i + c_{i+1})
with a fixed wall left of site 0 (x_{-1} = 0), a free end right of site L-1
(x_L = x_{L-1}) and zero-flux ends for c (c_{-1} = c_0, c_L = c_{L-1}). The per-chain
constants K, D, the per-site constants k, a, g, e, r and the initial state are drawn from
the seed with the SplitMix64 finaliser mix64 (see urand in the CPU source for the exact
formula; every value is an exact function of (seed, s, i, slot)). The system is purely
dissipative and not chaotic.
For each chain the program records the initial and final energy
E = sum_i (v^2/2 + k x^2/2 + a x^4/4 + K (x_i - x_{i-1})^2/2), the trapezoidal time
integrals of x_{L-1}^2 ("tail") and of the dissipated power sum_i (g_i + e_i c_i) v_i^2,
the final mean concentration and the final sum of displacements. It prints sums of these
over all chains and the full record of 6 evenly spaced sample chains.
Input format
P
S_1 L_1 T_1 DT_1 SEED_1
...
P independent problems. S = number of chains, L = sites per chain, T = number of RK4
steps, DT = step size (decimal), SEED = unsigned 64-bit.
Output format
Per problem, in input order:
problem p systems S sites L steps T
sum_E0 X
sum_Efinal X
sum_tail X
sum_dissipated X
sum_cmean X
sum_xsum_sq X (sum over chains of xsum^2)
weighted_mix X (sum over chains of (s%7+1)*Efinal + (s%5+1)*tail)
sys s Efinal tail dissipated cmean xsum (n = min(S,6) lines, s = j*(S-1)/max(n-1,1), j = 0..n-1)
Values are printed with %.12e. Outputs are compared numerically with rtol = 1e-8,
atol = 1e-11. That is far above the round-off of a correct FP64 port (about 1e-13 here,
including FMA contraction and any summation order), but FP32 state is not accurate
enough: the integration must be carried in double precision.
Hidden inputs
1 <= P <= 4,0 <= S <= 70000,1 <= L <= 64,0 <= T <= 4500,0.005 <= DT <= 0.03.- Correctness inputs include
S = 0,S = 1,L = 1,L = 2,L = 64,T = 0, and many small mixed problems. - The timing input is a single problem with
Sin about[56000, 64000],Lin[48, 64],Tin[3500, 4500]andDTin[0.012, 0.02].
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-08 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 one problem with about 56000-64000 chains of 48-64 sites, 3500-4500 RK4 steps each.
/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.