During job execution, it can be useful to find out the amount of time remaining for your PBS job. This allows you to decide if you want to gracefully dump restart files and exit before PBS kills the job.
If you have an MPI code, you can call MPI_WTIME and see if the elapsed wall time has exceeded some threshold in order to decide if the code should go into the shutdown phase.
For example:
include "mpif.h"
real (kind=8) :: begin_time, end_time
begin_time=MPI_WTIME()
do work
end_time = MPI_WTIME()
if (end_time - begin_time > XXXXX) then
go to shutdown
endif
In addition, the following library has been made available on NAS compute systems for the same purpose:
/u/scicon/tools/lib/pbs_time_left.a
To use this library in your Fortran code, you need to:
Modify your Fortran code to define an external subroutine and an integer*8 variable
external pbs_time_left
integer*8 seconds_left
Call the subroutine in the relevant code segment where you want the check to be performed
call pbs_time_left(seconds_left)
print*,"Seconds remaining in PBS job:",seconds_left
Note: The return value from pbs_time_left is only accurate to within a minute or two.
Compile your modified code and link with the above library using, for example: