Monte Carlo fleet sizing with best-fit-decreasing truck loading
/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
Monte Carlo fleet sizing for D depots. For every depot d and demand scenario
s = 0..S-1 the program builds a truck loading plan and reports the fleet statistics per
depot. Everything is generated with the SplitMix64-based hash hh of the CPU source
(make_depot, gen_item):
- Depot profile: truck capacity
cap(from the input), a mix of 4 hazard classes, a penalty matrixpen[c][g](pen[c][c] = 0; off-diagonal entries are either-1, meaning a class-cshipment may never ride in a class-gtruck, or1 .. max(1, cap/16)), and a 3-component size mixture (parcels[1, cap/12], cartons[cap/12, cap/3], pallets[cap/4, 4cap/5], bounds clamped to at least 1). - Scenario:
n_sshipments withn_sin[n - n/8, n + n/8]; shipmentigets its class and size fromhh(sb, 6, i).
Per scenario:
- Order the shipments by decreasing size, then increasing class, then increasing index.
- Best-fit loading. A truck takes the class
gof its first shipment. For the next shipment (sizez, classc) every classgwithpen[c][g] >= 0is considered: among the open trucks of classgthe one with the smallest residual capacityr >= zgives the score(r - z) + pen[c][g]. The smallest score wins, ties go to the smallerg, and among the trucks of classgwith exactly residualrthe one that most recently reached residualr(most recently opened or loaded) is used (LIFO). If no truck qualifies a new truck of classcis opened. Trucks are numbered in opening order; a truck with residual 0 is closed. The penaltypen[c][g]is paid whenc != gand the truck becomes mixed. - Statistics: number of trucks, the Martello-Toth
L2lower bound of the plain bin packing problem (class rules ignored), total penalty, number of mixed trucks, a 10-bucket histogram of truck fillmin(9, 10 * load / cap), and the assignment hashsum_i mix64(i * 0x9E3779B97F4A7C15 ^ (truck << 32) ^ sb)(mod2^64).
Per depot the scenarios are aggregated: total shipments and trucks, the maximum and the
90th percentile (sorted[(S-1)*9/10]) of trucks per scenario, summed bound, number of
scenarios with trucks equal to the bound, penalties, mixed trucks, fill histogram and
sum_s hash_s * (2s+1); the final line aggregates the depots (sum_d H_d * (2d+1)).
Input format
D S SEED
cap_1 n_1
...
cap_D n_D
1 <= D <= 64, 1 <= S <= 20000, D * S <= 200000, 8 <= cap <= 4095,
0 <= n <= 200000; SEED is an unsigned 64-bit integer.
Output format
One line per depot:
depot d cap <cap> items <N> bins <B> max <Bmax> p90 <B90> lb <LB> opt <k> pen <P> mixed <M> fill <f0> ... <f9> hash <H>
then total bins <B> lb <LB> opt <k> pen <P> mixed <M> hash <H>. All values are integers
and must match exactly.
Hidden inputs
Correctness inputs (10 files) include scenarios with 0 and 1 shipments, the smallest truck
capacities (8, 9 and up to 24), capacities around powers of two (64/65, 1023/1024), one scenario
with n = 200000 and cap = 4095, 2000 scenarios of 40 shipments, seeds 0 and 2^64-1, and
random depots with n <= 15000. The timing input has the shape and size of /app/inputs/timing_example.in.
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:
/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.