#!/bin/bash

# 获取脚本所在的绝对路径，确保后续引用都正确
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"

# 可执行文件和结果根目录都基于 SCRIPT_DIR
EXECUTABLE="${SCRIPT_DIR}/bin/speedtest"
RESULTS_ROOT="${SCRIPT_DIR}/results_1"

# 测试类型
names=('dyn_pol')  

# 固定参数
B_VALUES=(0 44)
E_VALUES=(0)

# 要测试的 t 值
T_VALUES=(16384)

# 每个 t 启动的第一个 seed
BASE_SEED=137

# 确保结果根目录存在
mkdir -p "$RESULTS_ROOT"

for name in "${names[@]}"; do
  for t in "${T_VALUES[@]}"; do
    # 计算当前 t 应该跑多少个 seed
    num_seeds=$((1))

    # 为当前 t 建一级目录
    outdir="${RESULTS_ROOT}/${name}/t${t}"
    # outdir="${RESULTS_ROOT}/${name}/t${t}"
    mkdir -p "$outdir"

    echo "=== test=${name}, t=${t}: will run seeds ${BASE_SEED}..$((BASE_SEED + num_seeds - 1)) ==="

    for b in "${B_VALUES[@]}"; do
      for e in "${E_VALUES[@]}"; do
        for ((i=0; i<num_seeds; i++)); do
          seed=$((BASE_SEED + i))
          TEST_NAME="${name}_b${b}_e${e}_t${t}_s${seed}"
          LOG_FILE="${outdir}/${TEST_NAME}.out"
          MEM_FILE="${outdir}/${TEST_NAME}.mem"

          echo "  -> b=${b}, e=${e}, seed=${seed}"
          (
            cd "$outdir"
            /usr/bin/time -v "$EXECUTABLE" "${name}_tbg" "$b" "$e" "$t" "$seed"
          ) \
            1> "$LOG_FILE" \
            2> "$MEM_FILE"
        done
      done
    done

    echo
  done
done

echo "All tests completed. Results in ${RESULTS_ROOT}/"
