Fixed-point multi-species MD with a two-zone pair force
/app/cpu/main.cpp is a multicore CPU program (C++17, OpenMP). It is built as
/app/bin/cpu_baseline with g++ -O3 -march=native -fopenmp -std=c++17 and run as
cpu_baseline INPUT_FILE
It reads one input file and writes its result to stdout.
What the program computes
A deterministic, integer-only molecular-dynamics run. N particles live in a periodic cube
of side 2^32: positions are uint32 and wrap naturally, and separations are
(int32)(x_i - x_j) (the minimum image). The box is divided into G = 2^LOGG cells per axis;
the cell width rc = 2^(32 - LOGG) is also the interaction cutoff (d^2 < rc^2).
Initial state, per-species tables (strength A_ab in [1, 64], zero crossing C_ab in
[8192, 57344], inverse-mass shift MS_a in {0,1,2}) are generated from the seed with the
SplitMix64 finaliser mix64 (half the particles uniform, half in K compressed blobs).
For every pair within the cutoff:
w = 65536 - (d^2 >> (2*CS - 16)) // CS = 32 - LOGG
fm = A_ab * w * (w - C_ab) / 1048576 // C++ integer division (truncates toward zero)
F_i += (dx, dy, dz) * fm // int64
so the force is repulsive at short range and attractive near the cutoff. Each step:
build the cell list, compute all forces from the current positions, then for every particle
and axis: v += F / 2^(DS + MS_a) (truncating division), v -= v / 32, clamp to
[-VMAX, VMAX] with VMAX = 2^(CS - VSH), then x += v (mod 2^32).
After every step the program prints the number of interacting unordered pairs and
ke = sum (vx^2 + vy^2 + vz^2) >> 16 (per-particle shift, then sum). At the end it prints
hashes and sums of the final state and four sample particles. The whole trajectory must be
reproduced bit for bit.
Input format
One line: N LOGG S T DS VSH K SEED (integers; SEED is unsigned 64-bit).
Output format
step s pairs P ke E (T lines, s = 1..T)
position_hash H velocity_hash H (16 hex digits each)
position_sum SX SY SZ (mod 2^64)
momentum PX PY PZ
particle i x X Y Z v VX VY VZ (4 lines when N > 0)
Hidden inputs
0 <= N <= 2.2e6,4 <= LOGG <= 7,1 <= S <= 4,1 <= T <= 40,16 <= DS <= 26,2 <= VSH <= 5,0 <= K, and whenK > 0the blobs hold at most about 10^4 particles each.- Correctness inputs include
N = 0,N = 1,N = 2,S = 1, a single dense blob,LOGG = 7with few particles (mostly empty cells) and runs of up to 40 steps. - The timing input uses
LOGG = 6, 6.5-8 particles per cell on average,K = N/5000blobs andT = 32. The attractive shell makes the blobs condense, so the number of interacting pairs grows several-fold during the run.
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 CPU source is the specification: when this text and the code disagree, the code wins.
How you are scored
- 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. - Grading runs on one H100 in a fresh container without network. Inputs are generated with a new random seed at grading time, so they cannot be known in advance.
- Correctness: every hidden input (small edge cases plus the timing input) must pass. Your output must be identical to the CPU program's output (trailing whitespace ignored). Any mismatch, crash or timeout gives reward 0.
- Speed: The timing input has 64^3 cells, 1.7-2.1 million particles (half in compressed blobs) and runs 32 MD steps. Your port and our GPU reference are each run on it
once to warm up and then 5 times, interleaved; the time is the wall clock of the whole process
(including CUDA initialisation, input parsing and output). When correct,
reward = min(2, t_reference / t_yours)using the medians. /app/inputs/holds a few public inputs./app/bin/run_public.shcompiles your port with the flags above and compares it against the CPU baseline on each of them.