#!/usr/bin/env bash set -euo pipefail cd "$(dirname "${BASH_SOURCE[0]}")" CONFIGS=(pb_scint fe_scint w_scint_ecal pb_lar) RUNS_PER_CONFIG=4 NEVENTS=10000 MAX_PARALLEL=16 EXE="$(pwd)/build/run_sampling" OUTDIR="$(pwd)/sampling_batch_output" WORKROOT="$OUTDIR/.work" mkdir -p "$WORKROOT" run_one() { local config="$1" idx="$2" local workdir="$WORKROOT/${config}_${idx}" mkdir -p "$workdir" ( cd "$workdir" "$EXE" "$config" "$NEVENTS" mv "sampling_${config}_${NEVENTS}events_hits.root" "$OUTDIR/sampling_${config}_10k_${idx}.root" ) rmdir "$workdir" } export -f run_one export EXE NEVENTS OUTDIR WORKROOT jobs=() for config in "${CONFIGS[@]}"; do for idx in $(seq 0 $((RUNS_PER_CONFIG - 1))); do jobs+=("$config $idx") done done printf '%s\n' "${jobs[@]}" | xargs -P "$MAX_PARALLEL" -L 1 bash -c 'run_one "$1" "$2"' _ rmdir "$WORKROOT"