#!/usr/bin/env bash

# This script executes rolling training for multiple model architectures
# Models: h3, hyena, lc, mha, s4

# Set how many models to run in parallel
MAX_MODEL_PARALLEL=1

MODELS=("h3" "hyena" "lc" "mha" "s4")

echo "Starting rolling training for all models: ${MODELS[@]}"
echo "==========================================="

# Run each model's rolling training script
for MODEL in "${MODELS[@]}"; do
  echo "Starting rolling training for model: $MODEL"
  
  # Concurrency check: if we already have $MAX_MODEL_PARALLEL jobs running, wait
  while [ "$(jobs -p | wc -l)" -ge "$MAX_MODEL_PARALLEL" ]; do
    sleep 5
  done
  
  # Ensure the script is executable
  chmod +x "./rolling_train_equities_${MODEL}.sh"
  
  # Execute the corresponding rolling train script for this model
  "./rolling_train_equities_${MODEL}.sh" &
  
  # Sleep to ensure scripts don't start at exactly the same time
  sleep 2
done

# Wait for all model training jobs to finish
wait

echo "All model rolling training jobs have completed."

# Usage:
# chmod +x rolling_train_all_models.sh
# ./rolling_train_all_models.sh 