The code below fails with segmentation error unless the arrays "f" and "e" have the same dimension using the Intel Fortran compiler. Appreciate if someone can explain why the array "f" cannot be larger (and much larger) than the array "e." Gfortran does not fail.

---

program test_arrfunc1

! Test of array-valued functions, Aug. 12, 2014.

! Red Hat Enterprise Linux Workstation release 6.5 (Santiago)

! $ ifort --version

! ifort (IFORT) 14.0.1 20131008

! Copyright (C) 1985-2013 Intel Corporation. All rights reserved.

! $ ifort -traceback test_arrfunc1.f90

! $ ./a.out

! forrtl: severe (174): SIGSEGV, segmentation fault occurred

! Image PC Routine Line Source

! a.out 000000000046E269 Unknown Unknown Unknown

! a.out 000000000046CBE0 Unknown Unknown Unknown

! a.out 000000000043E872 Unknown Unknown Unknown

! a.out 0000000000423363 Unknown Unknown Unknown

! a.out 0000000000402FCB Unknown Unknown Unknown

! libpthread.so.0 0000003E9440F710 Unknown Unknown Unknown

! a.out 0000000000476286 Unknown Unknown Unknown

! a.out 0000000000402CCA MAIN__ 46 test_arrfunc1.f90

! a.out 0000000000402BA6 Unknown Unknown Unknown

! libc.so.6 0000003E9401ED1D Unknown Unknown Unknown

! a.out 0000000000402A99 Unknown Unknown Unknown

!

! Works when "real(kind=dp),dimension(np) :: f" is defined. Output is here:

! $ ./a.out

! f 1.00000000000000 2.00000000000000 3.00000000000000

! 4.00000000000000 5.00000000000000 6.00000000000000

! 7.00000000000000 8.00000000000000 9.00000000000000

! 10.0000000000000

implicit none

integer,parameter :: i4b = selected_int_kind(9)

integer,parameter :: dp = kind(0.0d0)

integer(kind=i4b) :: i

integer(kind=i4b),parameter :: np = 10

real(kind=dp),dimension(np) :: e

! real(kind=dp),dimension(np) :: f ! works

real(kind=dp),dimension(10000) :: f ! fails

e = (/(i, i=1,np)/) ! generate some values

! call array-valued function

f = arrfunc1(e,np)

print *,'f',f(1:np)

contains

function arrfunc1(e,np)

implicit none

integer,parameter :: i4b = selected_int_kind(9)

integer,parameter :: dp = kind(0.0d0)

integer(kind=i4b),intent(in) :: np

real(kind=dp),dimension(np),intent(in) :: e

real(kind=dp),dimension(np) :: arrfunc1

arrfunc1 = e

end function arrfunc1

end program test_arrfunc1

---

Thanks!