Checking the Time Remaining in a PBS Job from a Fortran Code

Article ID: 199
Last updated: 02 Dec, 2025

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:

  1. Modify your Fortran code to define an external subroutine and an integer*8 variable
    external pbs_time_left
    integer*8 seconds_left
  2. 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.

  3. Compile your modified code and link with the above library using, for example:
    LDFLAGS=/u/scicon/tools/lib/pbs_time_left.a 

Contact Us

General User Assistance

Security

  • Report security issues 24x7x365
  • Toll-free: 1-877-NASA-SEC (1-877-627-2732)
  • E-mail: soc@nasa.gov

User Documentation

High-End Computing Capability (HECC) Portfolio Office

NASA High-End Computing Program

Tell Us About It

Our goal is furnish all the information you need to efficiently and effectively use the HECC resources needed for your NASA computational projects.

We welcome your input on features and topics that you would like to see included on this website.

Please send us email with your wish list and other feedback.