Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Segmentation fault

mathieu52
Beginner
314 Views
Hi,

The following program creates segmentation fault
under ifort 8.1, ifort 9.0 but not under ifc 7.0
PROGRAM BUGSEARCH
CALL gls_corstep_tile(1044574)
CONTAINS
SUBROUTINE gls_corstep_tile(Jend)
integer, intent(in) :: Jend
integer, parameter :: r8 = selected_real_kind(12,300) ! 64-bit
real(r8), dimension(Jend) :: var1
! real(r8), dimension(1044574) :: var1
Print *, 'The program has finished'
END SUBROUTINE gls_corstep_tile
END PROGRAM
The segmentation fault does not happen if 1044574 is replaced by a smaller value and if the value of Jend is replaced directly by its value.

The problem happen under linux 2.4.20-8 and linux 2.6.8-2-686-smp

Mathieu
0 Kudos
1 Reply
Steven_L_Intel1
Employee
314 Views
You are exceeding the stack limit for the large automatic array. Try this instead:


PROGRAM BUGSEARCH
CALL gls_corstep_tile(1044574)
CONTAINS
SUBROUTINE gls_corstep_tile(Jend)
integer, intent(in) :: Jend
integer, parameter :: r8 = selected_real_kind(12,300) ! 64-bit
real(r8), allocatable, dimension(:) :: var1
! real(r8), dimension(1044574) :: var1
allocate (var1(jend))
Print *, 'The program has finished'
END SUBROUTINE gls_corstep_tile
END PROGRAM


This will use dynamic allocation for the variable and should allow much larger allocations without worrying about stack size. The array will be automatically deallocated on exit of the subroutine.
0 Kudos
Reply