All-pairs shortest paths with negative arcs by blocked Floyd-Warshall
/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
All-pairs shortest path distances in one dense, clustered directed graph whose arc weights can
be negative, followed by summaries of the full distance matrix. The CPU program uses a blocked
Floyd-Warshall on int32 distances (64 x 64 tiles: diagonal tile, then its row and column of
tiles, then all other tiles as a min-plus product). Any method that produces the same distances
is fine.
Graph. Vertices are 0 .. N-1. With mix64 the SplitMix64 finaliser of the CPU source and
sA = mix64(SEED+1), sB = mix64(SEED+2), sC = mix64(SEED+3), sD = mix64(SEED+4)
(all arithmetic mod 2^64):
- cluster of
u:cl(u) = mix64(sB ^ u) mod C; - potential of
u:pot(u) = mix64(sD ^ u) mod (PRANGE + 1); - cluster
amay send arcs to clusterbwhena == b, or whenmix64(sC ^ (a << 32 | b)) mod 1000 < ARC_PM; - for
u != vleth = mix64(sA ^ (u << 32 | v))andr = h mod 1024. Ifcl(u) == cl(v)the arcu -> vexists whenr < P_INand has costc = 1000 + (h >> 10) mod 1000. Otherwise it exists when the clusters may send arcs andr < P_OUT, with costc = 3000 + (h >> 10) mod 2000. The arc weight isc + pot(u) - pot(v).
All costs are positive, so every cycle has positive weight (the potentials cancel around a
cycle) even though about half of all arc weights can be negative when PRANGE is large.
d(u, u) = 0; d(u, v) is the minimum weight of a directed path from u to v, or
"unreachable" when there is none. Reachable distances satisfy
|d| <= (N-1)*5000 + 2^20 < 2^28, so int32 with a large "no arc" value (the CPU uses 2^29
and treats any final value >= 2^28 as unreachable) is exact.
Input format
One line: N SEED C P_IN P_OUT ARC_PM PRANGE with 1 <= N <= 32768, SEED unsigned 64-bit,
1 <= C <= 1024, 0 <= P_IN, P_OUT <= 1024, 0 <= ARC_PM <= 1000, 0 <= PRANGE <= 2^20.
Output format
n N clusters C
unreachable U negative NEG
diameter D at I J (or: diameter none)
most_negative V at I J (or: most_negative none)
distance_sum S
rowsum_hash H
matrix_hash M
row r sum s (4 lines, r = 0, N/3, 2N/3, N-1 with integer division)
U: ordered pairs(i, j)with no path.NEG: reachable pairs withd < 0.diameter: the largest reachabled(i, j)withi != j; ties go to the smallesti, then the smallestj;nonewhen no pairi != jis reachable.most_negative: the smallestd(i, j) < 0with the same tie rule;nonewhen no distance is negative.rowsum_i= sum of the reachabled(i, j)overj(signed 64-bit);S= sum of all row sums.H= sum overiofmix64(rowsum_i ^ (i << 40)) * (2i + 1)mod 2^64 (row sum taken as its two's-complement 64-bit pattern).M= sum over all(i, j)ofmix64((i * 0x100000001B3 + j) ^ (code << 32))mod 2^64 wherecodeisd(i, j)as a 32-bit two's-complement pattern, or0x7FFFFFFFwhen unreachable.
Hex values are 16 lowercase digits.
Hidden inputs
Correctness inputs (16): N = 1, 2, 33, 65, 96, 127, 200, 257, 500, 1056, 2048 with: a graph
without arcs, a complete digraph without potentials, a single cluster, 128 tiny clusters with a
sparse cluster graph, a very sparse graph with long chains (P_IN = 25, P_OUT = 4),
clusters that cannot reach each other (ARC_PM = 0), C = 1024, and PRANGE from 0 to
2^20; plus five random graphs with 2 <= N <= 1300 and any parameter values in range.
The timing input has N from 12,500 to 13,800, C 6-12, P_IN 700-1000, P_OUT 80-200,
ARC_PM 400-800 and PRANGE from 2^18 to 2^20 (roughly 9-29% of all arcs present,
about half of all distances negative).
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: One graph with 12,500 to 13,800 vertices (a dense int32 distance matrix of about 0.7 GB), 6-12 clusters, roughly 9-29% of all arcs present and potentials up to 2^20, so about half of all distances are negative. 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.