Conformer clustering with an exact integer superposition-RMSD predicate
/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
Conformer-ensemble clustering, as done after a conformer search or an MD run, with an exact integer RMSD predicate.
- Ensemble generation (see
gen_conformer). A base molecule ofAatoms lies in a ball of radius 5 A (integer coordinates in units of 0.01 A). There areF = 8..16conformational families; a family puts each of the four "arms" (atom index blocksk*4/A) into one of three rotamer states (an integer-quaternion rotation). Conformerigets a family (skewed choice), a per-arm small torsion jitter whose size depends on the family's flexibility, per-atom noise and a random global rotation. All rotations are applied with integer quaternions and floor division. Each conformer is then centred exactly: per axis,floor(sum/A)is subtracted from every atom and 1 more from the firstsum mod Aatoms, so every coordinate sum is 0.G_i= sum of squared coordinates. - All pairs, exact RMSD cutoff tests. For a pair
(i, j)the correlation sumsS_ab = sum_k X_i[k][a] * X_j[k][b]give Horn's symmetric 4x4 key matrixK; the minimal RMSD over proper rotations satisfiesRMSD^2 = (G_i + G_j - 2 lambda_max(K)) / A. HenceRMSD <= c(c in 0.01 A) iff the integer matrixB = (G_i + G_j - A c^2) I - 2Kis not positive definite, decided with Sylvester's criterion (leading minorsd1..d4 > 0;d3,d4in 128-bit integers,d4via the 2x2-minor Laplace expansion). No floating point is involved. Pairs withRMSD <= c2form the neighbour graph, pairs withRMSD <= c1the tight graph. - Taylor-Butina clustering of the
c2graph: conformers in order of decreasing degree (ties: smaller index); an unassigned conformer becomes a centroid and takes all its unassigned neighbours. - Summaries: pair counts, degree histogram, number of clusters and singletons, how many
conformers share their centroid's family, an assignment hash
sum_j mix64((j << 32) ^ centroid(j) ^ 0x5EED)(mod 2^64), and the 12 largest clusters with their tight-member count (members withinc1of the centroid).
Input format
One line: N A c1 c2 SEED with 0 <= N <= 70000, 1 <= A <= 64, 0 <= c1 <= c2 <= 4000,
SEED an unsigned 64-bit integer.
Output format
conformers N atoms A families F cutoffs c1 c2
pairs within_c1 <n1> within_c2 <n2> maxdeg <d>
deghist h0 .. h16 (h0: degree 0, h1: degree 1, h_b: degree in [2^(b-1), 2^b), h16: >= 32768)
clusters <n> singletons <n> samefamily <n> hash <h>
cluster k centroid c family f size s tight t samefam m deg d (k < 12; size desc, centroid asc)
Hidden inputs
Correctness inputs (12 files) include N = 0, N = 1, a single pair, A = 1 (all RMSDs
zero), A = 2, c1 = c2, c1 = 0 with a huge c2, seeds 0 and 2^64-1, and random inputs with
N <= 1500. The timing input has N = 64000 conformers of A = 64 atoms (about 2.05e9
pairs), c1 in [40, 60] and c2 in [110, 140].
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 64000 conformers of 64 atoms (about 2.05e9 pairs, each needing a 64-atom 3x3 correlation and up to two exact 4x4 definiteness tests) with cutoffs c1 in [0.40, 0.60] A and c2 in [1.10, 1.40] A.
/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.