With Platform LSF, is there a command that will wait for either a specific job or all my submitted jobs to finish before returning? In other words, I am looking for the LSF equivalent of the wait
built-in command in bash.
2 Answers
If you give the -K
option to bsub
, it will wait for the job to complete before returning. You can then background several bsub
commands in the shell and use the shell's wait
command to wait for them. Example:
#!/bin/bash
bsub -K -o out.1 sleep 10 &
bsub -K -o out.2 sleep 5 &
wait
-
2
bwait
Example:
bsub -J 'myjobname' -o bsub.log bash -c 'date && sleep 10'
bwait -w 'ended(myjobname)'
The bwait
waits until the corresponding bsub
finished.
The same method also works for jobs arrays where -K
is not supported:
bsub -J 'myjobname[1-40]' -o 'bsub%I.log" 'sleep $JOBINDEX && echo $JOBINDEX'
bwait -w 'ended(myjobname)'
Besides ended()
there is also done()
and exit()
, which make bwait
only exit successfully if the exit status is 0
or not 0
respectively, and otherwise fail with:
Wait condition is never satisfied
because LSF has different job states for both cases.
Related documentation:
- https://www.ibm.com/support/knowledgecenter/en/SSWRJV_10.1.0/lsf_command_ref/bwait.1.html
- https://www.ibm.com/support/knowledgecenter/SSWRJV_10.1.0/lsf_command_ref/bsub.w.1.html#bsub_option_w
bsub -I
This is another good alternative to -K
if you only have one job. E.g.:
bsub -I 'echo a;sleep 1;echo b;sleep 1;echo c'
echo done
prints stdout live to the terminal, and only runs echo done
once the job finishes.
Documented at: https://www.ibm.com/docs/en/spectrum-lsf/10.1.0?topic=options-i