Question

I'm running some array jobs on a PBS system (although hopefully no knowledge of PBS systems is needed to answer my question!). I've got 24 runs, but I want to split them up into 5 sub-jobs each, so I need to run my script 120 times.

After giving the PBS option of -t 1-120, I can get the current job-array ID using $PBS_ARRAYID. However, I want to create some output files. It would be best if these output files used the ID that it would have had if there were only 24 runs, together with a sub-run identifier (e.g. output-1a.txt, output-1b.txt ... output-1e.txt, output-2a.txt).

What I therefore need is a way of calculating a way to get the ID (in the range 1-24) together with the sub-run identifier (presumably in a set of if-statements), which can be used in a shell-script. Unfortunately, neither my maths nor my Unix knowledge is quite good enough to figure this out. I assume that I'll need something to do with the quotient/remainder based on the current $PBS_ARRAYID relative to either 120 or 24, but that's as far as I've got...

Was it helpful?

Solution

You just need a little modular division. A quick simulation of this in Ruby would be:

p = Array.new; (1..120).each {|i| p[i] = "Run #{1+(i/5)}-#{((i%5)+96).chr}" }

What this says is simply that the run should start at 1 and increment after each new section of five, and that the trailing sub-run should be the ascii character represented by 96 plus the position of the sub-run (eg, 97 == 'a').

Here it is in Bash:

#!/bin/bash

chr() {
  local tmp
  [ ${1} -lt 256 ] || return 1
  printf -v tmp '%03o' "$1"
  printf \\"$tmp"

}

for ((i = 0; i < ${#ARP[*]}; i++))
do
    charcode=$((($i % 5)+97))
    charachter=$(chr "$charcode")
    echo "Filename: output-$((($i/5)+1))$charachter"
done

I just used ARP as the name of the array, but you can obviously substitute that. Good luck!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top