Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
31 Views

Ifort bug in sum of complex number

The following looks to be a bug in the ifort compiler. The example program is:

module srdt_mod
implicit none

type simple_struct
  complex(8) c
  real(8) r
end type

type special_struct
  type(simple_struct) s
end type

contains

subroutine calc(srdt)
implicit none
complex(8) sm
type(simple_struct) srdt
type(special_struct), allocatable :: eles(:)

allocate(eles(17))  !16 does not crash
sm = (1.0d0, 1.0d0)
eles%s%c = sm
sm = sum(eles%s%c) 
print *, 'Sum: ', sm

end subroutine
end module

!--------------

program prog
use srdt_mod
implicit none
type(simple_struct) srdt
call calc(srdt)
end program

 

Running the program gives:

> ifort prog.f90; ./a.out 
forrtl: severe (174): SIGSEGV, segmentation fault occurred
Image              PC                Routine            Line        Source             
a.out              0000000000404983  Unknown               Unknown  Unknown
libpthread-2.17.s  00007F045884E680  Unknown               Unknown  Unknown
a.out              000000000040378E  Unknown               Unknown  Unknown
a.out              0000000000403632  Unknown               Unknown  Unknown
libc-2.17.so       00007F04584943D5  __libc_start_main     Unknown  Unknown
a.out              0000000000403529  Unknown               Unknown  Unknown
 

Notes:

1) Bug appears with ifort V17, V18, V19.

2) If eles is allocated to size 16 there is no problem

3) If "-g" debug is used on the compile line there is no problem.

0 Kudos
5 Replies
Highlighted
Valued Contributor I
31 Views

This is an optimization problem. -O0 and -O1 work, -O2 and higher fails. The funny thing is that the code works also with kind type 4 instead of 8, and also with kind type 16. Also removal of the unused argument srdt makes the segfault go away. Looks like that is really an Intel bug. Also adding debug symbols (-g) makes the bug go away.

0 Kudos
Highlighted
New Contributor II
31 Views

The program runs OK with ifort V11.

0 Kudos
Highlighted
Beginner
31 Views

I know this issue is reported for the Intel compiler; however, I was curious how gfortran would behave. I just tested out this code with gfortran 7.3.0 on a Linux machine. I can confirm that the code works fine, regardless of the optimization level

0 Kudos
Highlighted
Black Belt
31 Views

The optimizer bug is also present in the Windows version of the 18.0.5 compiler. Please file a formal report at https://supporttickets.intel.com/?lang=en-US .

The following version displays the same kind of optimizer bug and involves a much smaller array.

subroutine calc(srdt)
implicit none
type(simple_struct) srdt
type(special_struct), allocatable :: eles(:)
integer i,n

n = 2
allocate(eles(n))

do i=1,n/2
   eles(2*i-1)%s%c = i*(1.d0,1.d0)
   eles(2*i)%s%c   = i*(1.d0,-1.d0)
end do

print *, 'Sum: ', sum(eles%s%c)

end subroutine

 

0 Kudos
Highlighted
Beginner
31 Views

OK it has been reported.

0 Kudos