https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83017
Bug ID: 83017 Summary: DO CONCURRENT not parallelizing Product: gcc Version: 6.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: cfztol at hotmail dot com Target Milestone: --- I found a strange behaviour, which I think is a bug. I'm trying to split a loop with DO CONCURRENT and compile flag -ftree-parallelize-loops=2 . However, whether parallelization actually happens depends on whether I use a computed vector index in an assignment or a constant index. The indexing happens inside a pure function, so I believe that should not affect the outer do concurrent loop (?) Here's my test code ! compile: ! gfortran -Ofast -march=native -ftree-parallelize-loops=2 -o main main.f90 ! run; ! time ./main program main use, intrinsic :: iso_fortran_env implicit none integer, parameter :: nsplit = 4 integer(int64), parameter :: ne = 2000000000 integer(int64) :: stride, low(nsplit), high(nsplit), i real, dimension(nsplit) :: pi stride = ceiling(real(ne)/nsplit) do i = 1, nsplit high(i) = stride*i end do do i = 2, nsplit low(i) = high(i-1) + 1 end do low(1) = 1 high(nsplit) = ne pi = 0 do concurrent (i = 1:nsplit) pi(i) = sum(compute( low(i), high(i) )) end do print *, "PI", 4*sum(pi) print *, "PI", 4*atan(1.0) contains pure function compute( low, high ) result( tmp ) integer(int64), intent(in) :: low, high real, dimension(nsplit) :: tmp integer(int64) :: j, k tmp = 0 ! With this loop no parallelization happens do j = low, high k = mod( j, nsplit ) + 1 tmp(k) = tmp(k) + (-1)**(j+1) / real( 2*j-1 ) end do ! With this loop the code is parallelized (apparent from time study) ! do j = low, high, 4 ! nsplit is equal to 4 ! k = 1 ! tmp(k) = tmp(k) + (-1)**(j+1) / real( 2*j-1 ) ! k = 2 ! tmp(k) = tmp(k) + (-1)**(j+2) / real( 2*j+1 ) ! k = 3 ! tmp(k) = tmp(k) + (-1)**(j+3) / real( 2*j+3 ) ! k = 4 ! tmp(k) = tmp(k) + (-1)**(j+4) / real( 2*j+5 ) ! end do end function end program main