Coulomb and short-range exchange matrices from screened s-type Gaussian ERIs
/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 Coulomb matrix J and a short-range exchange matrix K for a random "molecule" described by
contracted s-type Gaussian basis functions, contracted with a random symmetric density
matrix D.
Molecule and basis. NATOM atoms are placed one by one on a grid of 1/256 bohr inside the
cube [0, BOX]^3 by rejection sampling with a minimum separation of 2 bohr (exact integer
test; after 2000 failed tries the last candidate is kept). Each atom gets one of four types,
which fixes its contracted s shells (2-5 shells of 2-6 primitives, exponents growing by a
factor 3 inside a shell, see NSH, SHK, SHA); contraction weights are random, every
basis function is normalised. D[i][j] is random, symmetric, with D[i][i] in [0.4, 1]
and off-diagonal entries decaying like exp(-0.08 R^2). All of this is built sequentially on
the host from a SplitMix64 stream (copy it as is).
Integrals. For primitive pairs (a, b) with exponents alpha, beta:
p = alpha + beta, P = (alpha A + beta B)/p, E_ab = c_a c_b exp(-alpha beta / p |A-B|^2).
For a quartet with rho = p q / (p + q), T = rho |P - Q|^2 and
C = 2 pi^(5/2) / (p q sqrt(p + q)) E_ab E_cd:
(ij|kl) = sum over primitive quartets of C * F0(T)
(ij|kl)_SR = sum over primitive quartets of C * (F0(T) - eta F0(eta^2 T)), eta^2 = omega^2/(omega^2 + rho)
F0(T) = sqrt(pi)/2 * erf(sqrt(T)) / sqrt(T) (1 - T/3 for T < 1e-12)
(ij|kl)_SR is the integral of the attenuated operator erfc(omega r)/r.
Screening and symmetry. Q_ij = sqrt((ij|ij)) for every pair i >= j; pairs with
Q_ij * max(Q) < 1e-12 are dropped, and a unique quartet of pairs (ij), (kl) is
evaluated iff Q_ij * Q_kl >= 1e-12. Each unique quartet (i >= j, k >= l, each unordered
pair of pairs once, including a pair with itself) contributes, with
deg = (i!=j ? 2:1)(k!=l ? 2:1)(ij!=kl ? 2:1), s = deg (ij|kl), t = deg (ij|kl)_SR:
Jt[i][j] += s D[k][l] Jt[k][l] += s D[i][j]
Kt[i][k] += t D[j][l] Kt[j][l] += t D[i][k] Kt[i][l] += t D[j][k] Kt[j][k] += t D[i][l]
J = (Jt + Jt^T) / 4 K = (Kt + Kt^T) / 8
The CPU program rounds every contribution to a 64-bit fixed-point integer with 44 fractional
bits (llrint(value * 2^44)) and sums the integers with wrap-around, which makes its result
independent of the summation order. A port may accumulate differently (for example in FP64);
the tolerance below covers that.
Input format
One line:
NATOM SEED BOX OMEGA
1 <= NATOM <= 1000, SEED unsigned 64-bit, 1 <= BOX <= 200 (bohr, decimal),
0 < OMEGA <= 10 (decimal).
Output format
atoms NATOM basis N
tr_DJ x (sum_ij D_ij J_ij)
tr_DK x
norm_J x (Frobenius norm)
norm_K x
sum_J x (sum of all entries)
sum_K x
row r J_rr x K_rr x Jsum x Kabs x (min(N, 64) rows r = q (N-1)/(n-1); Jsum = sum_j J_rj, Kabs = sum_j |K_rj|)
Numbers are printed with %.12e and compared with rtol = 1e-10, atol = 1e-8. A correct
FP64 port differs from the CPU output by less than about 1e-12 relative (FMA contraction,
other summation orders or plain FP64 accumulation); single-precision Boys functions
everywhere, a missing symmetry factor or a much looser screening threshold do not pass.
Hidden inputs
- Correctness inputs: a single atom, a tight pair with
OMEGA = 0.05, isolated atoms withOMEGA = 5, an overcrowded box, and random molecules of 4-24 atoms with densities from about 0.002 to 0.015 atoms/bohr^3 andOMEGAin[0.1, 2]. - The timing input is one molecule with
NATOMin[130, 150],BOX = (NATOM / 0.0075)^(1/3)times a factor in[0.97, 1.03], andOMEGAin[0.25, 0.45].
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-10 and atol = 1e-08; 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 is one molecule of 130-150 atoms (about 480 contracted s functions) at 0.0075 atoms per cubic bohr, with omega in [0.25, 0.45]; about 1.5e7 quartets survive screening. 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.