Saturating-count stress centrality on undirected multigraphs
/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
For each generated undirected multigraph the program computes a stress centrality for every vertex.
A graph with n = 2^L vertices is built from a 64-bit seed by drawing m = n * D raw
directed endpoint pairs with a counter-based hash (SplitMix64 mix64). Self-loops are
dropped; each surviving draw is turned into an unordered pair. The multiplicity
w({a,b}) of a pair is the number of raw draws that land on it, capped at 255. These
multiplicities are "tie weights": a single hop across a pair of multiplicity w counts as
w distinct walks, so the number of shortest walks is weighted by edge multiplicity.
For every source s the program runs a layered (unweighted-hop) BFS and computes, with
saturating integer arithmetic capped at CAP = 2^20:
sigma_s(v)= number of shortests -> vwalks (each hop multiplied by the edge multiplicity), accumulated over BFS-DAG predecessors, saturated atCAP.- In a reverse pass over vertices in strictly decreasing BFS distance,
R_s(v) = sum over BFS-DAG children w of w({v,w}) * (1 + R_s(w)), saturated atCAP.R_s(v)is the total number of shortestv -> twalks over all proper BFS-DAG descendantst. stress_s(v) = sigma_s(v) * R_s(v)forv != s(this is the number of shortests -> twalks throughv, summed over allt).
The stress of a vertex is stress(v) = sum over all sources s of stress_s(v) (an exact
64-bit sum of the capped per-source products; the sum is order independent).
Per graph it reports:
n, the number of distinct undirected edges,stressdigest=sum_v mix64(mix64(v+1) XOR (stress(v) * 0x9E3779B97F4A7C15))(mod 2^64, order independent),- the top 5 vertices by
(stress descending, id ascending), with their stress and degree (number of distinct neighbours).
Input format
G
L_1 D_1 seed_1
...
L_G D_G seed_G
G graphs; graph g has n = 2^{L_g} vertices and m = n * D_g raw edge draws.
Output format
Per graph one header line
graph <g> n <n> edges <distinct_edges> stressdigest <digest>
followed by up to 5 lines
top <v> stress <value> deg <degree>
(fewer if fewer than 5 vertices have non-zero stress; none for empty graphs).
Hidden inputs
Correctness inputs (8 files) include L = 0 (a single vertex, no edges), L = 1,
tiny graphs (L = 2..4) where counts saturate, sparse and dense cases
(D from 1 to 12), and medium graphs up to L = 11 (2048 vertices). The timing input has
24 graphs with L = 13 (8192 vertices) and D = 6. Ranges used by the grader:
0 <= L <= 13, 0 <= D <= 12, seeds are arbitrary 63-bit integers. All arithmetic is
integer; path counts and dependencies are saturated at 2^20 before being combined.
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 24 undirected multigraphs, each with 2^13 = 8192 vertices and 6 raw edge draws per vertex (self-loops dropped, parallel edges kept as integer multiplicities); every vertex is used as a BFS source.
/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.