#!/usr/bin/env bash
# Lock-free vs lazy when threads outnumber CPUs (1024 keys, 500 ms, 5 reps).
# Usage: CPUS=0,1 ./run_oversub.sh > results/oversub_2vcpu.txt
# Thread i is pinned to entry i of the repeated list, so with CPUS=0,1
# threads 3 and up share the two CPUs.
set -eu
cd "$(dirname "$0")"
CPUS=${CPUS:-0,1}
BUILD_DIR=${BUILD_DIR:-$(mktemp -d)}
mkdir -p "$BUILD_DIR"
L="$CPUS,$CPUS,$CPUS,$CPUS"
gcc -std=c11 -O2 -Wall -Wextra -Werror -pthread -o "$BUILD_DIR/bench" bench.c lf.c lazy.c glock.c
echo "# nproc=$(nproc) $(uname -r) $(grep -m1 'model name' /proc/cpuinfo | cut -d: -f2 | sed 's/^ //') $(gcc --version | head -1)"
echo "# oversubscription: CPU list $L, 500 ms, 5 reps"
for rep in 1 2 3 4 5; do
    for wl in r90 u50; do
        for impl in lockfree lazy; do
            for t in 1 2 4 8; do
                taskset -c "$CPUS" "$BUILD_DIR/bench" $impl $wl 1024 $t 500 $rep "$L"
            done
        done
    done
done
