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 has the shape and size of
/app/inputs/timing_example.in.
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 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 is rejected. - GPU execution is checked: a port that computes its answer on the CPU is rejected even when its output is correct.
- Speed:
/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.