Weighted onion peeling with exact threshold crossings
/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 a sequence of generated undirected multigraphs, the program runs a synchronous weighted onion peeling (a generalised k-core decomposition) several times per graph, each time with freshly drawn edge weights, and reports the coreness and onion-layer structure.
Graph (all randomness from the counter-based hash mix64, the SplitMix64 finaliser in the CPU
source). n = 2^L vertices. Band vertices take the internal ids at the top of the range: B bands, band q has a length in
[BL/2, BL] and a reach c_q in [1, BC]; the remaining nbg internal ids are background vertices.
The edge slots are, in this order:
- Background:
D * nbgedges whose two endpoints are drawn asfloor(nbg * x^2)from two uniform 32-bit valuesx(heavy-tailed degrees, the low internal ids are hubs). - Dense groups:
Pgroups; groupphas a size in[GS/2, GS](at least 2) and a target degree in[GD/2, GD]; itssize * degree / 2edges join random pairs of its members, which are random background vertices. - Bands: the
i-th vertex of bandqis joined to itsi+1 .. i+c_q-th vertices. - Attachments: both ends of every band are joined to a random background vertex.
Internal ids are scrambled by a fixed bijection of [0, n). Self-loops are dropped; parallel edges
are kept and count separately everywhere (degree and strength).
Queries. For each query q = 0 .. Q-1 every edge slot gets a weight in 1..7 (from a per-query
seed) and c = 3 + (q mod 4). The key of a vertex is min(strength, c * degree), where strength is
the total weight and degree the number of its edges whose other end has not been removed yet.
Peeling. Repeat until every vertex is removed: let k be the smallest key of the remaining
vertices (a new level); the frontier is every remaining vertex with key <= k. Then run rounds:
all frontier vertices are removed simultaneously (their coreness is k, their onion layer is the
global round index, counted from 0 over all levels of the query), the keys of their remaining
neighbours drop, and the next frontier is the set of remaining vertices whose key went from > k
to <= k during this round (edges between two vertices removed in the same round do not count).
The level ends when a round produces an empty frontier. Coreness and layers are exact integers; the
result does not depend on the processing order inside a round.
Input format
G
L D SEED P GS GD B BL BC Q (one line per graph, G lines)
Output format
Per graph:
graph i n N edges E (E = edges after dropping self-loops)
then three lines per query:
query q c C maxkey K0 levels NL rounds R maxcore M size S lastrounds X busiest k:r
corehist h_0 h_1 ... h_t
hash corelayer H1 levels H2
K0is the largest initial key,NLthe number of levels,Rthe total number of rounds,Mthe largest coreness andSthe number of vertices with corenessM,Xthe number of rounds of the last level,k:rthe level with the most rounds (the first one on ties).corehist: bucket 0 counts coreness 0, bucketb >= 1counts coreness in[2^(b-1), 2^b); printed up to the last non-empty bucket.H1 = sum over v of mix64(v * 0xD6E8FEB86659FD93 ^ (coreness << 32) ^ layer)(v = final vertex id),H2 = sum over levels i of mix64((i << 44) ^ (k_i << 22) ^ rounds_i), both modulo 2^64.
Hidden inputs
- Correctness inputs: up to 3 graphs per input,
1 <= L <= 14,0 <= D <= 16,0 <= P <= 32,1 <= GS <= 2048(andGS <= n),1 <= GD <= 120,0 <= B <= 32,2 <= BL,B * BL <= n/2,1 <= BC <= 6,1 <= Q <= 8. They include isolated vertices only, a graph of only bands, a graph of only dense groups, the maximum of 32 groups and 32 bands, and eight queries per graph. - Timing input: 3 graphs with
L = 23(about 70 million edges each, multigraph CSR about 1.2 GB on the GPU),Din[6, 10],Pin[4, 10]withGSin[5000, 9000]andGDin[120, 260],Bin[4, 16]withBLin[3000, 6000]andBCin[3, 6],Q = 4. Each query has a few hundred levels and thousands of rounds, most of them with tiny frontiers (band ends), plus a few rounds that remove hundreds of thousands of vertices at once. SEED < 2^63. AlwaysP <= 32,B <= 32,L <= 23.
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: Three power-law multigraphs with 2^23 vertices and about 70 million edges each (dense groups of thousands of vertices, bands of thousands of vertices), each peeled four times with fresh weights; every peeling has a few hundred levels and thousands of mostly tiny rounds.
/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.