Clock-type spin model with diagonal couplings, 4-colour Metropolis
/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
Metropolis Monte Carlo of a q-state spin model (2 <= q <= 8, spins 0..q-1) on an
L x L periodic lattice (L even). The energy is
H = sum over horizontal and vertical neighbour pairs J1[b(s_i, s_j)]
+ sum over both diagonal neighbour pairs J2[b(s_i, s_j)]
+ h * (number of sites with spin 0)
with b(a, c) = min(d, q - d), d = (a - c) mod q. All couplings are integers.
Random numbers come from the SplitMix64 finaliser mix64 (see the CPU source) with
base(seed, stream) = mix64(seed XOR stream * 0xD1B54A32D192ED03) and the value for index
i in a stream being mix64(base + i * 0x9E3779B97F4A7C15) (64-bit wraparound).
- Initial state:
s_i = value(stream 0, i) mod q, site indexi = y*L + x. - Sweep
sw(0-based) visits the 4 coloursc = 0..3; colourcis the set of sites withx mod 2 = c & 1andy mod 2 = c >> 1. Sites of one colour do not interact, so each colour is updated as a whole using stream1 + 4*sw + c. For siteiwith randomr: proposals' = (s + 1 + (r mod 2^32) mod (q-1)) mod q;dEis the integer energy change; accept whendE <= 0or(r >> 32) < thr[dE], wherethr[1] = wandthr[d] = floor(thr[d-1] * w / 2^32)(64-bit unsigned). - After every sweep with
(sw + 1) mod measure == 0the total energyEand the number of zero spinsZare measured.
Input format
R
seed L q w h sweeps measure J1[0] .. J1[q/2] J2[0] .. J2[q/2] (R lines)
Output format
One line per run:
run E_SUM E2_SUM Z_SUM ACCEPTED HASH H_0 .. H_{q-1}
E_SUM is the signed sum of the measured energies, E2_SUM the sum of E*E modulo 2^64,
Z_SUM the sum of the measured zero counts, ACCEPTED the total number of accepted moves,
HASH = sum_i mix64(8*i + s_i) mod 2^64 over the final state and H_k the final number of
spins equal to k.
Hidden inputs
1 <= R <= 5,2 <= L <= 2048(even),2 <= q <= 8,1 <= w <= 2^32 - 1,-8 <= h <= 8,-8 <= J1[d], J2[d] <= 8,0 <= sweeps <= 200in correctness inputs,1 <= measure <= 50.- Edge cases:
L = 2(neighbours coincide),q = 2,sweeps = 0,w = 1andw = 2^32-1, frustrated diagonal couplings, one run withL = 2048. - The timing input has 4 runs with
768 <= L <= 1536, about 4.5e9 site updates each, and5 <= measure <= 20.
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 4 runs on L x L lattices with L between 768 and 1536 and about 4.5e9 site updates per run, measuring the energy every 5 to 20 sweeps. 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.