7

When submitting a job script to a PBS queuing system, a walltime is specified automatically or by the user e.g. via

#PBS -l walltime=1:00:00

The question is if this time can be accessed from the job script. Is there an environment variable or some other way to get this walltime.

In the end, the job script should decide from time to time if there is enough time left to do some more work so that the job does not get killed by the queuing system.

Update:

At least if the user has specified the walltime in the resources list, I can propose the following workaround (working for bash)

read _ _ PBS_WALLTIME  <<< `qstat -f $PBS_JOBID | grep "Resource_List.walltime"`

which parses the walltime from the qstat output and places the value in the PBS_WALLTIME variable. Accordingly, the command

echo $PBS_WALLTIME

will yield something like

1:00:00
dastrobu
  • 1,600
  • 1
  • 18
  • 32
  • In PBS 4.2.8 (and possibly other versions), the $PBS_WALLTIME variable stores the wall time in number of seconds, so the `echo` would output `3600` instead of `1:00:00`. – MasterHD Sep 07 '15 at 08:36

2 Answers2

5

This is stored in the environment variable $PBS_WALLTIME.

Of course, that is for TORQUE, I'm not sure which PBS queuing system you are using.

dbeer
  • 6,963
  • 3
  • 31
  • 47
  • That, of course, depends on the cluster I'm using. One runs TORQUE and the other PBS Pro. Unfortunately, even on the TORQUE cluster the $PBS_WALLTIME variable is not defined. So that might not be standard. – dastrobu Apr 12 '13 at 14:34
  • What version of TORQUE is it? – dbeer Apr 12 '13 at 17:20
  • I am not sure, if I can answer that question correctly. How do I obtain the version information? Possibly you're asking for the PBS version which is set to 2.1.10 (taken from the output of `qmgr -c "print server"`). – dastrobu Apr 14 '13 at 20:50
  • Fortunately, that gives the same answer `version: 2.1.10` – dastrobu Apr 16 '13 at 08:07
  • Sorry, I misread the last comment. The TORQUE 2.1.* codebase is extremely old and has a different feature set from almost all other deployments of TORQUE. This functionality was added later. – dbeer Apr 16 '13 at 15:54
  • At least the workaround is sufficient in my case and probably this discussion helps someone else working on a more modern cluster. Thank you for your help. – dastrobu Apr 16 '13 at 20:07
1

I was looking for an answer to this and the comments above gave me an idea that seems to work pretty well. You can use qstat and grab the pertinent information from it with sed:

qstat -f $PBS_JOBID | sed -rn 's/.*Resource_List.walltime = (.*)/\1/p'

Putting this in your PBS script will print out the value and you can use standard bash to store the output of this in a variable:

WALLTIME=$(qstat -f $PBS_JOBID | sed -rn 's/.*Resource_List.walltime = (.*)/\1/p')

You can also use this to get other information that is not available from the PBS_* environment variables such as the amount of memory allocated for the job and probably some other stuff.

StFS
  • 1,639
  • 2
  • 15
  • 31