Skip to content

Instantly share code, notes, and snippets.

@4piu
Created January 2, 2026 19:10
Show Gist options
  • Select an option

  • Save 4piu/4d2e0694359a9c2d198aa5c4a5409fb8 to your computer and use it in GitHub Desktop.

Select an option

Save 4piu/4d2e0694359a9c2d198aa5c4a5409fb8 to your computer and use it in GitHub Desktop.
Avoid QoS error when submitting large number of slurm tasks. The script dispatch new task when previous one is completed.
#!/usr/bin/env bash
set -euo pipefail
if [[ $# -lt 1 ]]; then
echo "Usage: $0 COMMAND_FILE" >&2
exit 1
fi
CMD_FILE=$1
MAX_JOBS=${MAX_JOBS:-20}
SLEEP_SECONDS=${SLEEP_SECONDS:-60}
if [[ ! -f "$CMD_FILE" ]]; then
echo "Command file not found: $CMD_FILE" >&2
exit 1
fi
current_job_count() {
squeue -h -u "$USER" | wc -l
}
while IFS= read -r cmd || [[ -n "$cmd" ]]; do
trimmed=${cmd//[[:space:]]/}
[[ -z "$trimmed" ]] && continue
stripped=${cmd#${cmd%%[![:space:]]*}}
[[ ${stripped:0:1} == "#" ]] && continue
while (( $(current_job_count) >= MAX_JOBS )); do
sleep "$SLEEP_SECONDS"
done
echo "Submitting: $cmd"
if ! eval "$cmd"; then
echo "Submission failed: $cmd" >&2
exit 1
fi
sleep 1
done <"$CMD_FILE"
echo "All commands from $CMD_FILE submitted."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment