Debugging pgf90 array subscript out of bounds

I’ve compiled a F90 main program with array subscript checking enabled (-Mbounds). I get the following error message at runtime:

0: Subscript out of range for array c (spline_module.f90: 19)
subscript=1, lower bound=1, upper bound=-1073798060, dimension=1

I’m trying to figure out how to use pgdbg to pinpoint the error. Can anyone give me some pointers? I can run the code in pgdbg, but I can’t backtrack from the program exit. The subroutine in question executes about 25 times before the error condition occurs.

Hi liamg,

While you can simply set a break point at this line and then click “continue” 25 times, consider adding a counter to the subroutine which counts the number of times it has been called. Use an if statement to test if the counter has reached 25 and then print something. You can set a breakpoint inside the if statement and skip past the working portions.

A very simple example:

        program test
        integer i

        do i=1, 30
          call foo()
        end do
        end program test

        subroutine foo
          integer, save :: count

          count = count + 1;
          print *, "SUB COUNT=", count
          if ( count .eq. 25 ) then
            print *, "SET BREAKPOINT HERE"
          end if
       end subroutine foo

Compile your program with “-O0 -g -Mbounds” and run using pgdbg. Set the break point in the if statement, and run the program. Once halted at the breakpoint, type “where” to get a stack trace. The stack trace will tell you who called your subroutine. You can also use “print” to print the contents of the local variables.

My guess is that your subroutine has an assumed shape array as a dummy argument and it is this array that’s causing the array bounds error. Since the upper bounds value is garbage, the actual array argument could be corrupt. If the actual array is an Allocatable or Pointer, then it might not have been allocated?

Hope this helps,
Mat