Multiple Batch Tasks

From CAC Documentation wiki
Jump to navigation Jump to search

Multiple Batch Tasks

You can add the -t switch to tell the scheduler to run multiple copies of your batch file. It's just like telling the printer to print five copies of your document. This example starts ten tasks. Each knows its task number when it starts. They each are scheduled as separate jobs, so they don't have to start at the same time and generally will not start simultaneously.

#PBS -l walltime=02:00,nodes=1
#PBS -N taskTest
#PBS -j oe
#PBS -q test
#PBS -t 1-10

echo I am job ${PBS_JOBID} and task ${PBS_ARRAYID}.

You can start a thousand tasks this way with one command! BUT PLEASE DON'T. You might crash the scheduler! Think about it: if you tried using qsub a thousand times, the scheduler would get flooded. The -t switch just makes it easier to cause such a flood.

A nice feature of -t is that you can specify multiple non-overlapping ranges or ids, as in -t 3-5,7,10-12.

How might I use this switch?

  • Make a list of batch parameters in a file. Use $PBS_ARRAYID to have each task pull that line from the file.
PARAMS=$(awk "{ if (NR==$PBS_ARRAYID) print \$0 }" $INDATA)
  • Work through the entries in a directory, again by line number.
DATAFILE=$(ls -1 *.dat | awk "{ if (NR==$PBS_ARRAYID) print \$0 }")

The qdel, mjobctl, and showq commands do not agree on whether the multiple tasks are separate jobs or part of a job. You may be able to kill all of the jobs with qdel <jobid>, but you may need to specify each task with qdel <jobid>-1, qdel <jobid>-2, and so on. Use a for loop with a sleep in there so the scheduler doesn't get overloaded.

for i in {1..100}; do qdel 1003172-$i; sleep 0.5; done