Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
29299 Discussions

run-time error with ifort 9.1 when passing functions

gtokic
Beginner
1,479 Views
Hi everybody,

I came across this issue when using different ifort compilers. I normally use ifort 10.0.023 in which case the following code compiles and runs normally. However, I had to change to a parallel computer where ifort 9.1. is installed and this time the code compiles normally but has run-time segmentation fault. I don't see where the error might be in the code, I don't know is it because of the fact that the functions are being passed as arguments or what.

If anybody has any ideas what the problem might be, it would be really helpful. The code is attached below. The run time error apparently occurs when function func isn't recognized in function hx. I compile with ifort -r8 -o test_ts fp_test_ts.f90.

[plain]module utl
 implicit none
 contains
  function cft(a,b,n,func)
     implicit none
     real,intent(in)    :: a,b
     integer,intent(in) :: n
     real               :: cft(0:n)
     interface
       function func(x)
         implicit none
         real,intent(in) :: x(:)
         real            :: func(size(x))
       end function func
     end interface
     real :: th(0:n)
     th = b-a
     cft = func(th)
   end function cft
end module utl

module test_mod
 implicit none
 real             :: ts(1)
 contains
  function FCD(func,t1,t2,M,N) result(Amn)
    implicit none
    real, intent(in)      :: t1,t2     
    integer,intent(in)    :: M,N 
    complex               :: Amn(-M:M,0:N)
    interface
      function func(x,t)
        real,intent(in)   :: x(:),t(:)
        real              :: func(size(t),size(x))
      end function func
    end interface   
    complex,parameter     :: i = (0.,1.)
    real                  :: tD(0:M)
    complex               :: FN(0:M,0:M)
    integer               :: j,k
    tD  = (t2-t1)*(/ (j, j=0,M) /)
    forall (j = 0:M,k = 0:M) FN(j,k) = -i*j*k
    Amn(0:M,:) = matmul(FN,Cn(tD,N))
    Amn(-1:-M:-1,:) = conjg(Amn(1:M,:))
   contains
 !----------------------------------------------------------------------------- 
    function Cn(t,N)
      use utl,  only : cft
      implicit none
      real,intent(in),dimension(:)   :: t 
      integer,intent(in)             :: N
      real                           :: Cn(size(t),0:N),x(0:N)
      integer                        :: k1      
      forall (k1 = 0:N) x(k1) = 1.0*k1/(N+1)
      do k1 = 1,size(t)
      	ts = t(k1)
        Cn(k1,:) = cft(x(0),x(N),N,hx) 
      end do
    end function Cn  
  !-----------------------------------------------------------------------------  
    function hx(x)
      implicit none
      real,intent(in),dimension(:)  :: x
      real,dimension(size(x))       :: hx 
      real                          :: dum(1,size(x))
      print *,' **** hx'
      print *,' ts = ',ts
      print *,' func(0.1,0.1) = ', func( (/0.1/), (/0.1/) )
      dum = func(x,ts)
      hx = dum(1,:)
    end function hx      
  end function FCD 
end module test_mod
!*****************************************************************************
program test_prog
use test_mod, only : FCD implicit none integer,parameter :: M = 1, N = 10 real,parameter :: a=0.0,b=1.0 complex :: Amn(-M:M,0:N) Amn = FCD(func,a,b,M,N) print *, 'Amn = ',Amn contains function func(x,t) implicit none real,intent(in) :: x(:),t(:) real :: func(size(t),size(x)) integer :: i do i = 1,size(t) func(i,:) = sin(t(i))*cos(x) end do end function end program test_prog[/plain]



The error I get is the following:

forrtl: severe (174): SIGSEGV, segmentation fault occurred
Image PC Routine Line Source
test_ts 0000000000403775 Unknown Unknown Unknown
test_ts 0000000000403453 Unknown Unknown Unknown
test_ts 0000000000403250 Unknown Unknown Unknown
test_ts 0000000000402C2E Unknown Unknown Unknown
test_ts 00000000004027D3 Unknown Unknown Unknown
test_ts 00000000004026AA Unknown Unknown Unknown
libc.so.6 00002B406E87F154 Unknown Unknown Unknown
test_ts 00000000004025E9 Unknown Unknown Unknown



I found a similar discussion on forum http://software.intel.com/en-us/forums/showthread.php?t=51159 where Steve said that there is a bug in the process of being fixed. Is this the case of the same/similar bug that has been fixed in newer versions of ifort?

Thanks,
Grgur
0 Kudos
6 Replies
Steven_L_Intel1
Employee
1,479 Views
I don't see anything wrong with the code. It could be there was a bug in 9.1 that you encountered - it isn't an issue I remember, not that that means anything. The issue you linked to is completely different - "segmentation fault" has an infinite number of possible causes. If you build with -traceback, is there more meaningful information as to where the error occurs?
0 Kudos
gtokic
Beginner
1,479 Views
Hi Steve,

I've tried compiling with traceback, and this time it doesn't compile. This is the error I get, i must say I don't understand much of it.

test_ts: In function `__data_start':
(.data+0x8): multiple definition of `__dso_handle'
/usr/lib64/gcc/x86_64-suse-linux/4.1.0/crtbegin.o:(.data+0x0): first defined here
test_ts: In function `_init':
/usr/src/packages/BUILD/glibc-2.4/cc-nptl/csu/crti.S:25: multiple definition of `_init'
/usr/lib64/gcc/x86_64-suse-linux/4.1.0/../../../../lib64/../lib64/crti.o:/usr/src/packages/BUILD/glibc-2.4/cc-nptl/csu/crti.S:11: first defined here
test_ts: In function `_start':
(.text+0x0): multiple definition of `_start'
/usr/lib64/gcc/x86_64-suse-linux/4.1.0/../../../../lib64/../lib64/crt1.o:init.c:(.text+0x0): first defined here
test_ts: In function `main':
(.text+0xb8): multiple definition of `main'
/opt/intel/fce/9.1.040/lib/for_main.o:(.text+0x0): first defined here
test_ts: In function `_fini':
/usr/src/packages/BUILD/glibc-2.4/cc-nptl/csu/crti.S:37: multiple definition of `_fini'
/usr/lib64/gcc/x86_64-suse-linux/4.1.0/../../../../lib64/../lib64/crti.o:/usr/src/packages/BUILD/glibc-2.4/cc-nptl/csu/crti.S:11: first defined here
test_ts:(.rodata+0x9b08): multiple definition of `_IO_stdin_used'
/usr/lib64/gcc/x86_64-suse-linux/4.1.0/../../../../lib64/../lib64/crt1.o:(.rodata.cst4+0x0): first defined here
test_ts: In function `__data_start':
(.data+0x0): multiple definition of `__data_start'
/usr/lib64/gcc/x86_64-suse-linux/4.1.0/../../../../lib64/../lib64/crt1.o:init.c:(.data+0x0): first defined here
/tmp/ifortHF5NDF.o: In function `MAIN__':
fp_test_ts.f90:(.text+0x0): multiple definition of `MAIN__'
test_ts:(.text+0x100): first defined here
/tmp/ifortHF5NDF.o: In function `test_mod_mp_fcd_':
fp_test_ts.f90:(.text+0x1e6): multiple definition of `test_mod_mp_fcd_'
test_ts:(.text+0x2e6): first defined here
/tmp/ifortHF5NDF.o: In function `utl_mp_cft_':
fp_test_ts.f90:(.text+0xc12): multiple definition of `utl_mp_cft_'
test_ts:(.text+0xd12): first defined here
/tmp/ifortHF5NDF.o: In function `utl._':
fp_test_ts.f90:(.text+0xde2): multiple definition of `utl._'
test_ts:(.text+0xee2): first defined here
/tmp/ifortHF5NDF.o: In function `test_mod._':
fp_test_ts.f90:(.text+0xde4): multiple definition of `test_mod._'
test_ts:(.text+0xee4): first defined here

Is it helpful? I have compiled with ifort -r8 -o -traceback test_ts fp_test_ts.f90.

Grgur

0 Kudos
Steven_L_Intel1
Employee
1,479 Views
You want instead:

ifort -r8 -traceback -o test_ts fp_test_ts.f90
0 Kudos
gtokic
Beginner
1,479 Views
Sorry for that. Now the run-time error shows

forrtl: severe (174): SIGSEGV, segmentation fault occurred
Image PC Routine Line Source
test_ts 0000000000403785 test_modfcd_mp_hx 68 fp_test_ts.f90
test_ts 0000000000403453 utl_mp_cft_ 18 fp_test_ts.f90
test_ts 0000000000403250 test_modfcd_mp_cn 57 fp_test_ts.f90
test_ts 0000000000402C2E test_mod_mp_fcd_ 43 fp_test_ts.f90
test_ts 00000000004027D3 MAIN__ 85 fp_test_ts.f90
test_ts 00000000004026AA Unknown Unknown Unknown
libc.so.6 00002B66161DF154 Unknown Unknown Unknown
test_ts 00000000004025E9 Unknown Unknown Unknown


This is more understandable, and it points to the lines where function func is called. Any ideas?
0 Kudos
Steven_L_Intel1
Employee
1,479 Views
Again, it looks as if it may be a compiler bug since fixed. The solution is obviously to update the compiler.
0 Kudos
gtokic
Beginner
1,479 Views
Thanks Steve, at least I know I didn't go that crazy. I'll try to get it updated.

Grgur
0 Kudos
Reply