Fixed-point multi-species MD with a two-zone pair force
/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
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 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 has 64^3 cells, 1.7-2.1 million particles (half in compressed blobs) and runs 32 MD steps.
/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.