Running a job after one is completed

I have a scenario where I need to submit a job on a Slurm cluster. This new job should start only after another job with ID 1 has finished running. To achieve this, I attempted to use the command “sbatch -d after:1 job.script”. However, when I checked the status using “scontrol show job 2”, it seems that the dependency is not being recognized, as it displays “Dependency=(null)”.

In an attempt to resolve this issue, I then used the command “scontrol update JobId=2 dependency=after:1”. Despite this, the dependency information still appears as “Dependency=(null)” when I check again using “scontrol show job 2”. This problem only seems to occur when the dependency is a job that is currently running.

Is there a reason why the dependency is being ignored in this case? Are there any alternative approaches I could take to ensure that the new job starts only after the specified job has completed its execution?

I think you should try --dependency=afterok:1 which requires the job to finish successfully before starting job 2. The after:1 syntax should only wait for job1 to start or be cancelled (docs page):

after:job_id[[+time][:jobid[+time]…]]
After the specified jobs start or are cancelled and ‘time’ in minutes from job start or cancellation happens, this job can begin execution. If no ‘time’ is given then there is no delay after start or cancellation.

I’m not actually sure what happens if job1 starts before you submit job2 with after:1. I would have expected it to start right away, but maybe not?

Try -d afterok:1 or -d afterany:1 to see if those work better.

1 Like