Segmentation fault

I observe this very strange issue to me.
This is the simple code

PROGRAM matmul_test
  use accel_lib
  
  IMPLICIT NONE
  
  INTEGER :: N, M, L
  DOUBLE PRECISION :: diff, denom, error

  PRINT *, "start"
  CALL testdouble_2 ()
END PROGRAM matmul_test



SUBROUTINE testdouble_2 ()
  USE accel_lib
  IMPLICIT NONE
  INTEGER, PARAMETER :: N = 10
  DOUBLE PRECISION, DIMENSION(N) :: bigC, chiC,chiO
  INTEGER, DIMENSION(N, maxnklm+maxnklp-1) :: indexPdt, tmpPdt
  
  INTEGER :: i, j
  INTEGER, PARAMETER :: maxnklm =3, maxnklp = 3
  INTEGER, DIMENSION(N) :: isfu

  indexPdt = 0
  DO i = 1,N
     isfu(i) = i
  ENDDO

END SUBROUTINE testdouble_2

I compile with

/opt/pgi/linux86-64/10.5/bin/pgf95 main.f90 -ta=nvidia,cc13 -L /opt/pgi/linux86-64/10.5/lib64 -lacml -o aout

[/quote]

When I run it, multiple times, and run the next command right after the first one complete. Sometimes, I get the segmentation fault error or not enough memory. This is so inconsistent. So could any one please give me a solution.

mt@nfat:~/Projects/test_accelerator/test_copy_10.5$ ./aout
start
mt@nfat:~/Projects/test_accelerator/test_copy_10.5$ ./aout
start
Segmentation fault
mt@nfat:~/Projects/test_accelerator/test_copy_10.5$ ./aout
start
Segmentation fault
mt@nfat:~/Projects/test_accelerator/test_copy_10.5$ ./aout
start
/test_copy_10.5$ ./aout
start
0: ALLOCATE: 18446744073676923096 bytes requested; not enough memory

Thanks,
Tuan

Hi Tuan,

maxnklm and maxnklp need to be declared before they are used in indexPdt’s and tmpPdt’s dimension. Otherwise, their initial value isn’t set and you’re using garbage for the dimension.

To fix move the declaration of indexPdt and tmpPdt below manklm.

SUBROUTINE testdouble_2 ()
  USE accel_lib
  IMPLICIT NONE
  INTEGER, PARAMETER :: N = 10
  DOUBLE PRECISION, DIMENSION(N) :: bigC, chiC,chiO
  INTEGER :: i, j
  INTEGER, PARAMETER :: maxnklm =3, maxnklp = 3
  INTEGER, DIMENSION(N, maxnklm+maxnklp-1) :: indexPdt, tmpPdt
  INTEGER, DIMENSION(N) :: isfu

Hope this helps,
Mat

Thanks, Mat. It really helps.

BTW, I thought that as a constant (PARAMETER), their relative location to the array that use them as the dimension is not important.

Tuan