Fixed-point dissipative particle dynamics with symmetric per-pair RNG
/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 is a fixed-point dissipative particle dynamics (DPD) fluid. N particles
live in a periodic cube of side 2^(LOGG+12) (cell size 2^12, so G = 2^LOGG cells per
axis) with signed 64-bit integer velocities. Initial positions are uniform in the box;
velocities are uniform in [-v0, v0] with v0 = 2^(12-VSH); each particle has one of 4
species. Three length-1024 distance-bucket weight tables wC, wD, wR and a symmetric
4x4 interaction matrix aij are built deterministically from seed.
A cutoff cell list (cutoff d2 < 2^24) is rebuilt each step using minimum-image
displacements. For each neighbour pair (i, j) with bucket k = d2 >> 14:
- draw a symmetric random value
xifrom a counter-based hash keyed by(seed, step, min(i,j), max(i,j))(soiandjget the samexi); - conservative
fC = aij[si][sj] * wC[k]; - dissipative
fD = -(GAMMA*wD[k]) * (dot / 2^12)wheredot = d . dvis the dot product of the displacement and relative velocity; - random
fR = (SIGMA*wR[k]) * xi; - the pair scalar is
fs = fC + fD + fR, and the impulse added to atomiis(fs * d) / FDIVper component (FDIV = 2^FSH).
Then v += force (the sum of per-pair impulses) and x += v (wrapping). Because fs and
xi are symmetric while the displacement/relative-velocity flip sign, and integer division
truncates toward zero, the impulses on i and j are exact negatives: total momentum is
conserved exactly (velocities are 64-bit and nothing is clamped). Per printed step the
program reports total momentum (an invariant) and ksum = sum of v^2 (a kinetic checksum
that evolves as the thermostat balances dissipation and noise). After T steps it reports a
position hash, a velocity hash, total momentum, and six components of four sampled particles.
Input format
One simulation on a single line:
N LOGG T EVERY GAMMA SIGMA FSH VSH seed
N >= 1; LOGG in [2, 19]; T >= 0 steps printing every EVERY; GAMMA >= 0;
SIGMA >= 0; FSH (impulse shift, typically [28, 34]); VSH in [1, 11]; seed
unsigned 64-bit.
Output format
dpd N <N> box 2^<PB> grid <G>^3 steps <T>
step <t> mom <mx> <my> <mz> ksum <K> (for each printed step)
position_hash <hex16> velocity_hash <hex16>
momentum <px> <py> <pz>
particle <i> x <x> <y> <z> v <vx> <vy> <vz> (4 lines)
Momentum components are signed; ksum and the hashes are unsigned 64-bit (mod 2^64).
Hidden inputs
Correctness inputs cover N = 1 (no neighbours), N = 2, T = 0, weaker and stronger
force settings, finer grids, and random configurations with N in [1500, 12000], LOGG
in [3, 6], T in [1, 8], GAMMA in [2, 8], SIGMA in [4, 16], FSH in [30, 33],
VSH in [2, 4]. The timing input uses N = 600,000, LOGG = 5, T about 78,
GAMMA = 4, SIGMA = 8, FSH = 31, VSH = 2.
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 be identical to the CPU program's output (trailing whitespace ignored). 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 DPD simulation of N = 600,000 particles in a 32^3 cell grid (cells hold ~18 particles) run for about 78 steps (printing every ~3 steps), each step summing all pair forces with a symmetric per-pair random draw.
/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.