I may have found a compiler bug on Linux, for ifort version 17.0.0 on a Debian 'testing' distribution (uname -a: Linux e5470 4.6.0-1-amd64 #1 SMP Debian 4.6.4-1 (2016-07-18) x86_64 GNU/Linux).
The following Fortran code snippet hangs indefinitely within the loop, with CPU at 100%, if compiled with optimization options -O2 -xHost. It works with a previous ifort release; with gfortran; or if the inner loop 'dot_product' is rewritten term by term, as in the listing below.
subroutine k2r_foldinto_WScell(kvec_conventional,nplanes,bzplanes_array,already_inside_before_folding, && kvec_folded) implicit none integer,parameter :: ndimens=3 real(kind(0.d0)),intent(IN) :: kvec_conventional(ndimens) integer,intent(IN) :: nplanes real(kind(0.d0)),intent(IN) :: bzplanes_array(ndimens+1,nplanes) ! Indexed in: xyz d/2, iplane. logical,intent(OUT) :: already_inside_before_folding real(kind(0.d0)) kvec_folded(ndimens), & ! Indexed in: xyz.& kvec_relative(ndimens), && bz_distance_squared, max_bz_distance_squared integer iplane,closest_bz !, idimen already_inside_before_folding = .true. kvec_folded(1:ndimens) = kvec_conventional(1:ndimens) ! Assume initially that no folding is needed. 234 continue max_bz_distance_squared = dot_product( kvec_folded, kvec_folded ) ! Get the search started: distance from Gamma. closest_bz = 0 ! Initial trial assumption that the point is closest to the BZ instance around Gamma, conventionally labeled as 0. do iplane=1,nplanes kvec_relative(1:ndimens) = kvec_folded(1:ndimens) - bzplanes_array(1:ndimens,iplane) ! Intel ifort 17.0.0 bug with -O2 and -mavx: ! bz_distance_squared = dot_product( kvec_relative,kvec_relative ) ! Workaround: bz_distance_squared = kvec_relative(1)*kvec_relative(1) + && kvec_relative(2)*kvec_relative(2) + && kvec_relative(3)*kvec_relative(3) if( bz_distance_squared.lt.max_bz_distance_squared ) then max_bz_distance_squared = bz_distance_squared closest_bz = iplane endif enddo ! iplane if( closest_bz.gt.0 ) then kvec_folded(1:ndimens) = kvec_folded(1:3) - bzplanes_array(1:ndimens,closest_bz) already_inside_before_folding = .false. goto 234 endif end subroutine k2r_foldinto_WScell
Thanks for any possible confirmation/feedback,
--
Alberto.
Zone:
Thread Topic:
Bug Report