All-pairs soft-core screened interaction with species-dependent screening
/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
N particles in (roughly) the unit cube, open boundaries, generated from the seed with the
SplitMix64 finaliser mix64 (70% in K Plummer-like clusters, 30% uniform; K = 0 means all
uniform; see the CPU source for the exact generator). Particle i has a charge
q_i in [0.5, 1.5) and one of S species; species a has a screening constant
kappa_a in [KMIN, KMAX] and a softening length e_a derived from EPS.
For every ordered pair i != j, with r = |x_i - x_j|, k = (kappa_i + kappa_j)/2 and
s^2 = r^2 + e_i^2 + e_j^2:
phi_ij = q_i q_j (1 + k r) exp(-k r) / s
F_i += q_i q_j exp(-k r) / s * (k^2 + (1 + k r)/s^2) * (x_i - x_j) (= -grad_i phi_ij)
pot_i = sum_j phi_ij
It prints the total energy E = 0.5 sum_i pot_i, the virial sum_i x_i . F_i, sum_i |F_i|^2,
the sums of |F_x|, |F_y|, |F_z|, the potential summed per species, and pot and F
for 24 sample particles. Everything is computed in double precision.
Input format
One line: N S K KMIN KMAX EPS SEED (N, S, K integers, KMIN, KMAX, EPS decimals, SEED
unsigned 64-bit).
Output format
particles N
energy E
virial V
force_sq_sum F2
force_abs_sum AX AY AZ
species a kappa KAPPA potential P (S lines)
sample i pot P force FX FY FZ (24 lines when N > 0)
Values are printed with %.12e. Outputs are compared numerically with rtol = 1e-6,
atol = 1e-9, so accumulations need double precision (summation order is free).
Hidden inputs
0 <= N <= 150000,1 <= S <= 8,0 <= K <= 60,0 <= KMIN <= KMAX <= 13,1e-4 <= EPS <= 0.02(one correctness case uses2e-4with dense clusters).- Correctness inputs include
N = 0,N = 1,N = 2,S = 1,KMIN = KMAX = 0(unscreened) and a single cluster, withN <= 8000. - The timing input has
Nin about[121000, 139000],Sin[4, 8],Kin[20, 60],KMINin[1, 3],KMAX - KMINin[3, 6],EPSin[3e-4, 3e-3].
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 source generation only. Write /app/gpu/main.cu; compilation,
execution and verification are performed later in a separate verifier environment.
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. - GPU verification uses the backend selected for this run: an H100 attached to the separate verifier, or a remote H100 worker. Hidden inputs use a fresh random seed.
- Correctness: every hidden input (small edge cases plus the 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-06 and atol = 1e-09; every other token must be identical. Any mismatch, crash or timeout gives reward 0. - GPU execution: a separate, untimed CUPTI check must observe completed GPU kernel activity on the hidden timing input. A CPU-only submission receives reward 0 even if its output is correct.
- Speed: The timing input has about 120-140 thousand particles (70% in 20-60 Plummer-like clusters) and 4-8 species with screening constants between 1 and 9. 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 public input examples for understanding the input format.