Attractors of an aliquot-like odd-part divisor map
/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
For a positive integer n write n = 2^k * m with m odd. Define
T(n) = sigma(m) - m + 2*tau(n) + k
where sigma is the sum of divisors and tau the number of divisors (of n, not m).
For example T(1) = 2, T(2) = 5, T(5) = 5, T(12) = 1 + 12 + 2 = 15.
For every start n in the query interval [L, L+W) the program builds the trajectory
x_0 = n, x_{j+1} = T(x_j) and stops at the first j with x_j = x_i for some i < j.
Then mu = i (tail length), lambda = j - i (cycle length) and the attractor is the
smallest value in the cycle x_i .. x_{j-1}. Two special classes exist (they do not
occur for the hidden input ranges but are part of the specification):
- if some
T(x_{j-1}) > 2^60, the start isescapewithmu = j,lambda = 0; - if no repeat occurs among
x_0 .. x_199, the start islongwithmu = 200,lambda = 0.
Input format
Q
L_1 W_1
...
1 <= L, 0 <= W, L + W - 1 <= 10^13.
Output format
Per query:
query L W
sum_mu SMU sum_lambda SLAM hash HASH
max_mu MU at N (or "max_mu - at -" when W = 0)
attractors K
A_1 COUNT_1
...
SMU,SLAM: sums ofmuandlambdaover all starts (decimal, mod 2^64).HASH: sum over starts ofmix64(n XOR mix64(A + (mu << 32) + lambda))mod 2^64, withAthe attractor id (2^64-1for escape,2^64-2for long) andmix64the SplitMix64 finaliser in the CPU source.max_mu: the largestmuand the smallest start achieving it.attractors: number of distinct attractor ids, then one line per id in increasing numeric order (escape/long print as the wordsescape/long, after all numbers).
Hidden inputs
Correctness inputs (8 files, 2 to 5 queries each) include W = 0, W = 1, L = 1,
intervals ending at 10^13, intervals around 2^40, 10^12 and 3^26, and random
intervals with W <= 8000 and L >= 10^9. The timing input has 3 queries with W
uniform in [3.5*10^6, 4.5*10^6] and L uniform in [10^11, 10^13 - W + 1].
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. - Grading runs on one H100 in a fresh container without network. 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 3 intervals of about 4e6 consecutive start values each (about 1.2e7 trajectories), starting at random points between 1e11 and 1e13. 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.