Skip to main content

5.18) Array Jobs (cont'd)


Another example, would be if the required inputs to the program are listed in a file, one per line. For example, the lines of the file could contain the name of input files or the random number seeds for a simulation. For each task in the array, we would like to extract the nth line from the file where n is equal to the value of SGE_TASK_ID. Use can be made of some standard UNIX utilities to select the appropriate line. For example:

[bash]
#!/bin/bash
# Use current working directory and current environment
#$ -cwd -V
# request 30 minutes runtime for each tas
#$ -l h_rt=1:00:00
# array job with index 1 to 100, increment 1
#$ -t 1-100:1
#set the file containing data
SEEDFILE=~/data/data.dat
#select line in data.dat corresponding to task number
SEED=$(cat $SEEDFILE | head -n $SGE_TASK_ID | tail -n 1)
./prog $SEED
[/bash]