Allocation greater than 4GB failed for derived types


The following program causes a segmentation fault using the PGI fortran compiler 5.2-4 in AMD64 opteron (16GB memory) on line:

allocate(grandTableau(0:grandeTaille - 1))

It does not depend on compilation options (-i8 or -tp k8-64 or -tp amd64).

program kkraboum

  type ensemble
     integer, dimension(:), pointer :: petitTableau => null()
  end type ensemble

  type(ensemble), dimension(:), allocatable :: grandTableau
  real, dimension(:), allocatable :: tabReel
  integer :: i
  integer, parameter :: tailleTabReel = 2000000000
  integer, parameter :: grandeTaille = 64000000
  integer, parameter :: petiteTaille = 5
  type(ensemble) :: donnee
  integer :: longueur

  write(*,*) "Test ..."
  write(*,*) "Test tableau simple", tailleTabReel
  allocate(tabReel(0:tailleTabReel - 1))
  write(*,*) " -> allocation OK"
  do i = 0, tailleTabReel - 1, 100
     tabReel(i) = real(i)
  end do
  write(*,*) "suivant ... (appuyez sur entre)"
  write(*,*) "Allocation grand tableau"
  allocate(grandTableau(0:grandeTaille - 1))
  write(*,*) "Allocation OK"

  write(*,*) "Allocation petits tableaux"
  do i = 0, grandeTaille - 1, 1
     allocate(grandTableau(i)%petitTableau(0:petiteTaille - 1))
  end do
  write(*,*) "Allocation OK"
  do i = 0, grandeTaille - 1, 1
  end do
end program kkraboum


You need to compile with “-i8 -Mlarge_arrays” in order to use arrays that are larger than 2Gb. (See page 31 of the 5.2-4 release notes For large static arrays and common blocks, you’ll also need to add “-mcmodel=medium”. Note that I was able to compile and run the program on our 16Gb system without problem when the program was compiled with “-i8 -Mlarge_arrays”.

Hope this helps,