Newman-Ziff incremental bond-percolation ensemble on a small-world graph
/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
The program runs a Newman-Ziff incremental bond-percolation study on a single generated graph, averaged over many random bond orderings.
The shared graph. From the 64-bit seed the program builds E undirected edges over
V nodes. A per-seed percentage lp = 30 + (seed-hash mod 41) of the edges are local
(ring neighbours: endpoint b = (a + 1 + k) mod V with a small hop k), the rest are
long-range (both endpoints hashed uniformly in [0, V)). Endpoint a, the hop and the
long-range endpoint all come from a SplitMix64 hash of the edge index, so every process can
build edge j independently. Self-loops and repeated edges may occur and simply act as
no-op unions. All R realizations share this same edge set.
A realization. Realization r adds the E edges in its own order, obtained by a
Fisher-Yates shuffle of 0..E-1 driven by a SplitMix64 stream keyed by (seed, r). Bonds
are added one at a time into a union-find (union by size, full path compression). After
adding bonds the program maintains two integer quantities:
largest= size of the current largest cluster;M2= sum over clusters ofsize^2(the second moment of the cluster-size distribution; starts atVwith all singletons and increases by2*sa*sbon each merge of clusters of sizessaandsb). This is an integer susceptibility proxy.
Checkpoints. There are S occupation checkpoints at bond counts
sc[s] = floor(E*(s+1)/S) for s = 0..S-1 (so sc[S-1] = E). When the number of added
bonds reaches sc[s], the current largest and M2 are recorded. If sc[s] = 0 (possible
when E < S or E = 0) the initial state is recorded.
Aggregation. For each checkpoint s the program sums over all realizations:
sumL[s] = sum of largest, sumL2[s] = sum of largest^2, sumM2[s] = sum of M2.
After all bonds are added it also computes, per realization, a partition checksum
sum over nodes v of mix64((v * GAMMA) XOR size_of_component(v)) and sums it over
realizations into hash. (largest, M2 and this checksum depend only on the final
partition, so they are independent of union tie-breaks and path-compression order.)
Input format
One configuration on a single line:
R V E S seed
with R >= 1, V >= 1, E >= 0, S >= 1, and seed an unsigned 64-bit integer.
Output format
R V E S
s sc[s] sumL[s] sumL2[s] sumM2[s] (one line for each s = 0..S-1)
hash H
All values are non-negative integers (sums taken modulo 2^64).
Hidden inputs
Correctness inputs (one configuration each) cover: E = 0 (no bonds), V = 1 and V = 2,
S > E, a single checkpoint, sparse and dense graphs, and random configurations with
V in [8, 600], E in [0, 3V], R in [1, 40], S in [1, 24]. The timing input
is a single configuration with R about 1,000,000, V about 4096, E = 3V, S = 32.
S never exceeds 64.
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 be identical to the CPU program's output (trailing whitespace ignored). 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 configuration with R about 1,000,000 realizations of a shared graph with V about 4096 nodes and E about 12288 edges, each realization adding every edge in its own random order and sampling S = 32 occupation checkpoints. 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.