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

Possible loop optimization bug in 12.0 compilers w/ example

otte
Beginner
601 Views
Hi,
With the latest XE fortran compilers on both Linux and OSX, a simple brute-force sorting code is crashing. This code works fine with previous Intel compiler versions and other compilers:
[fortran]program psort
implicit none

integer, parameter :: nlev = 20
integer :: ia, i, j
integer :: iorig(nlev) = (/ (i*10, i=1,nlev) /)
integer :: icopy(nlev)
integer :: isort(nlev)

icopy(:) = iorig
isort(:) = -1

! sort pressure levels high-to-low
do i=1,nlev
   do j=1,nlev
      if (icopy(j) > isort(i)) then
         isort(i)=icopy(j)
         ia=j
      endif
   enddo
   !  Effectively remove current highest pressure level
   icopy(ia)=-1
enddo

write(*,'(3A8)') "Index", "Array", "Sorted"
do i=1,nlev
   write(*,'(3I8)') i, iorig(i), isort(i)
enddo

end program psort
[/fortran]
The code just takes a positive-only input array (iorig) and creates an array isort that is sorted highest-to-lowest. This routine crashes with the current fortran compilers unless I compile with -g. I don't think there is any problems such as array bounds being exceeded that may be causing the crash.
>ifort psort.f90 -traceback
>./a.out
forrtl: severe (174): SIGSEGV, segmentation fault occurred
Image PC Routine Line Source
a.out 0000000100000C11 _MAIN__ 22 psort.f90
Stack trace terminated abnormally.
>./a.outforrtl: severe (174): SIGSEGV, segmentation fault occurredImage PC Routine Line Source a.out 0000000100000C11 _MAIN__ 23 psort.f90
Stack trace terminated abnormally.
With -g (and with previous compiler versions) it compiles fine:
>ifort psort.f90 -g -traceback
>./a.out
Index Array Sorted
1 10 200
2 20 190
3 30 180
4 40 170
5 50 160
6 60 150
7 70 140
8 80 130
9 90 120
10 100 110
11 110 100
12 120 90
13 130 80
14 140 70
15 150 60
16 160 50
17 170 40
18 180 30
19 190 20
20 200 10
Thanks for your help,
Martin
0 Kudos
3 Replies
Ron_Green
Moderator
601 Views
this looks like a pretty obvious bug in the vectorizer. Let me investigate and start a bug report.

ron
0 Kudos
Ron_Green
Moderator
601 Views
Bug report is DPD200165104

Bug appears in all 12.0 versions. Workaround is to use 11.1 versions or older.

ron
0 Kudos
Ron_Green
Moderator
601 Views
This bug is fixed in the latest Update 3 compiler available on https://registrationcenter.intel.com

Please upgrade to the Intel Fortran Composer XE 2011 Update 3 compiler for this fix.

ron
0 Kudos
Reply