Best-improvement 2-opt to a local optimum on a batch of zoned tour instances
/app/cpu/main.cpp is a multicore CPU program (C++17, OpenMP). It is built as
/app/bin/cpu_baseline with g++ -O3 -march=native -fopenmp -std=c++17 and run as
cpu_baseline INPUT_FILE
It reads one input file and writes its result to stdout.
What the program computes
P independent closed-tour instances are each improved by best-improvement 2-opt until
no improving move remains (a 2-opt local optimum) or a step cap is reached.
Instance p is derived from h = mix64(SEED ^ ((p+1) * 0xD1B54A32D192ED03)) (see
make_inst in the CPU source): n points (NMIN <= n <= NMAX) with integer coordinates in
[0, 65535], either uniform or clustered, each with a zone z in [0, K) (1 <= K <= 6),
a symmetric zone surcharge table ZT (zero diagonal, entries in [0, ZMAX]) and a
long-edge threshold L. The cost of the edge between points a and b is
e = floor(sqrt(dx^2 + dy^2)) (exact integer square root)
c(a,b) = e + ZT[z_a][z_b] + (e > L ? (e - L) >> 1 : 0)
The initial tour t[0..n-1] is a hashed Fisher-Yates shuffle of 0..n-1. With
t[n] = t[0], a move (i, j) with 0 <= i, i + 2 <= j <= n - 1 and (i, j) != (0, n-1)
replaces edges (t[i], t[i+1]) and (t[j], t[j+1]) by (t[i], t[j]) and (t[i+1], t[j+1]),
i.e. it reverses t[i+1..j] in place (position 0 never moves). Its change in tour length is
delta(i, j) = c(t[i], t[j]) + c(t[i+1], t[j+1]) - c(t[i], t[i+1]) - c(t[j], t[j+1])
Every step evaluates all moves of the current tour and applies the one with the smallest
delta, ties broken by the smallest i, then the smallest j. The search stops when the
smallest delta is >= 0, or after CAP * n steps (the instance is then counted as capped).
Every step changes the tour, so the exact step sequence matters for the output.
Input format
One line: P NMIN NMAX ZMAX CAP SEED (SEED is an unsigned 64-bit integer).
Output format
instances P steps TS capped TC len0 A len1 B hash H
inst p n N len0 a len1 b steps s tour T traj R (for p < min(P, 12))
len0/len1 are the initial and final tour lengths (sums of c over the tour's n edges),
steps the number of applied moves, TS, A, B their sums over instances and TC the
number of capped instances. T = sum over positions q of mix64((q << 32) ^ t[q] ^ 0x5851F42D4C957F2D)
for the final tour, and R = sum over steps k = 1, 2, ... of mix64((k << 40) ^ (i << 20) ^ j ^ ((-delta) << 44))
for the move (i, j, delta) applied at step k (32-bit -delta, all sums modulo 2^64).
H combines every instance's result as in the CPU source.
Hidden inputs
0 <= P <= 400, 3 <= NMIN <= NMAX <= 4000, 0 <= ZMAX <= 100000, 1 <= CAP <= 1000.
Correctness inputs include P = 0, tours with n = 3 (no legal move), n = 4, 5, many
small instances, ZMAX = 0, ZMAX = 100000 (surcharges dominate), CAP = 1 (the step cap
is reached) and instances with n up to 900. The timing input has 110-130 instances with
n uniform in [600, 1800] and CAP = 50 (the cap is never reached there; a random tour
needs about 1.35 n steps).
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 CPU source is the specification: when this text and the code disagree, the code wins.
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. - This sandbox has no GPU.
nvccworks here for compiling. To run on the GPU, use/app/bin/gpu_run [--repeat N] [--quiet] SOURCE.cu INPUT_FILE...: it compiles the file with the flags above on a remote H100 worker, runs it on each input, and prints stdout, exit code and wall-clock time. Grading also runs your code on an H100 worker, one job per GPU at a time. Inputs are generated with a new random seed at grading time, so they cannot be known in advance. - 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.
- Speed: The timing input has 110-130 instances with n uniform in [600, 1800] (about 1.35 n steps each, every step scanning all moves). 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 a few public inputs./app/bin/run_public.shcompiles your port with the flags above and compares it against the CPU baseline on each of them.