Skip to content

Job Dependencies

Use sbatch --dependency to order jobs without waiting manually:

Dependency Start condition
after:JOBID After the predecessor starts or is cancelled; does not guarantee successful output
afterany:JOBID After the predecessor terminates, regardless of outcome
afternotok:JOBID After the predecessor fails
afterok:JOBID After the predecessor completes successfully
singleton After earlier jobs with the same user and job name finish

Diamond Workflow: A → B and C → D

Prepare A.sh, B.sh, C.sh, and D.sh using the job templates, with your account and resources set. Submit from a login node:

sbatch --job-name=A A.sh
# example response: Submitted batch job 17703

sbatch --job-name=B --dependency=afterok:17703 B.sh
# example response: Submitted batch job 17704

sbatch --job-name=C --dependency=afterok:17703 C.sh
# example response: Submitted batch job 17705

sbatch --job-name=D --dependency=afterok:17704:17705 D.sh
# example response: Submitted batch job 17706

Replace the example IDs with those returned by your submissions. B and C wait for A; D waits for both B and C. While B and C run, an example queue could show:

JOBID PARTITION NAME USER     ST TIME NODES NODELIST(REASON)
17704 gh200     B    username R  1:27 1     CLUSTER-NODE-01
17705 gh200     C    username R  1:27 1     CLUSTER-NODE-02
17706 gh200     D    username PD 0:00 1     (Dependency)

B and C use two nodes concurrently; other members’ jobs count toward the same project limit.

Capture Job IDs Automatically

Run this instead of the manual submissions above to avoid duplicate jobs. --parsable returns the ID without the human-readable submission message:

#!/bin/bash
set -euo pipefail
job_a=$(sbatch --parsable --job-name=A A.sh)
job_a=${job_a%%;*}
job_b=$(sbatch --parsable --job-name=B --dependency="afterok:$job_a" B.sh)
job_b=${job_b%%;*}
job_c=$(sbatch --parsable --job-name=C --dependency="afterok:$job_a" C.sh)
job_c=${job_c%%;*}
job_d=$(sbatch --parsable --job-name=D --dependency="afterok:$job_b:$job_c" D.sh)
printf 'Final job: %s\n' "$job_d"

An eligible dependency does not guarantee an immediate start: resources and fair-share priority still apply. If a prerequisite fails, an afterok successor cannot proceed; inspect the failure and cancel or resubmit affected jobs as appropriate. See the sbatch dependency reference.