How to use job dependencies

  • Some users need to submit jobs that take more time than the queue allows. In some cases it is possible to split the single task into multiple sequencial tasks. For this situations SGE allows you to make job dependencies. This is achieved using the qsub -hold comand. The next example will show you how to achive this:

Example

  • First create the dependencies main script submission file:
$ cat dependencies.sh

#!/bin/sh

j=$1
NJOBS=$2
NPROC=$3

jfinal=`expr $j + $NJOBS`
first="true"

while [ $j -lt $jfinal ]; do
   j=`expr $j + 1`
   j1=`expr $j + 1`

cat - > $0.$j << EOF;
#!/bin/bash
#!/bin/bash


# Call MPI environment with #NPROC
#$ -pe mpi $NPROC


# Load modules 
source /etc/profile.d/modules.sh
module load gcc44/openmpi-1.4.1

# Compile application
echo "=== Compiling ===" 
mpicc -o cpi cpi.c 

# Execute application 
echo "=== Running ==="
mpirun -np $NSLOTS cpi
EOF

if [ "X$first" == "Xtrue" ]; then
   JID=`qsub $0.$j | awk '{print $3}'`
   if [ $? == 0 ]; then
            first="false"
               echo "Submitting job for $j (JID=$JID)"
       else
          echo "Problem submitting job for $j"
          exit 1
   fi
else
   OLDJID=$JID
   JID=`qsub -hold_jid $JID $0.$j | awk '{print $3}'`
       if [ $? != 0 ]; then
              echo "Problem submitting job $j"
              exit 1
       else
       echo "Submitting job for j=$j (JID=$JID). Depends on $OLDJID"
       fi
fi

rm -f $0.$j
done
  • Second submit the job (100 tasks with 8 core each on which N*1 starts after N finish's);
./dependencies.sh 1 100 8