galactica
galactica

Reputation: 1833

SGE grid job dependency

I have a dilemma of streamlining a sequence of SGE grid jobs that have some dependency among them but haven't figured out a correct way of specifying -hold_jid.

Suppose we have jobs like:

job1: qsub -N job1 ... 
job2: qsub -N job2 -hold_jid job1
job3: qsub -N job3 -hold_jid job2

then the order of execution is guaranteed to be job1->job2->job3.

However, suppose within the complicated job2, there is an embedded SGE job, say job2a:

job2a: qsub -N job2a.${timestamp_of_submission}

In this case, I haven't figured out a way to make sure job3 run after job2a completes.

attempt1:

qsub -N job3 -hold_jid job2 ...

Then surely job3 waits until job2 finishes, however, there is no guarantee that job3 will be executed after job2a, which is what i wanted.

attempt2:

qsub -N job3 -hold_jid job2a* ...

then job3 seems to be executed right away since job2a isn't shown in the job array until job2 starts to run. Note I used * above to avoid specifying the exact name of job2a, because the timestamp of submission is hard to guess beforehand.

Anyone knows a way to achieve the dependency chain as job1->job2->job2a->job3? Thanks!

Upvotes: 2

Views: 1619

Answers (1)

Vince
Vince

Reputation: 3395

Have you tried giving -hold_jid a list of job Id:

qsub -N job2
qsub -N job2a
qsub -N job3 -hold_jid job2,job2a.${timestamp_of_submission}

Alternatively, capturing the job Id should also work:

job2a=$(qsub -N job2a.${timestamp_of_submission} | perl -p -e "s/Your job (\d+) .*/\1/g;")
qsub -N job3 -hold_jid job2,${job2a}

EDIT

Based on comment, you need to get list of job id.

So I would suggest the following:

job2list=$(qsub -N job2 | perl -p -e "s/Your job (\d+) .*/\1/g;")

The above stores the job id for job 2.

Then every time you submit a job2a-type job do:

job2a=$(qsub -N job2a.${timestamp_of_submission} | perl -p -e "s/Your job (\d+) .*/\1/g;")
job2list="${job2list},${job2a}"

The above will append job2a job id to the id for job2.

When ready to submit job 3 do:

qsub -N job3 -hold_jid ${job2list}

Upvotes: 1

Related Questions