Compiling the following fortran90 program takes minutes
program implloop
implicit none
integer, parameter :: dp = selected_real_kind(15)
integer(dp) :: i
real(dp), allocatable :: array(:)
real(dp) :: t1 , t2
call cpu_time(t1)
allocate( array(10**8) )
array = [( sqrt(real(i,dp)) , i = 1 , 10**8 )]
call cpu_time(t2)
write(*,*) t2-t1
end program
It is compiled with GNU Fortran (Debian 6.3.0-18+deb9u1) 6.3.0 20170516.
On the other hand, if compiled using a do-loop,
program implloop
implicit none
integer, parameter :: dp = selected_real_kind(15)
integer(dp) :: i
real(dp), allocatable :: array(:)
real(dp) :: t1 , t2
call cpu_time(t1)
allocate( array(10**8) )
do i = 1 , 10**8
array(i) = sqrt(real(i,dp))
end do
call cpu_time(t2)
write(*,*) t2-t1
end program
it is ready in a second. What is the reason behind this compile-time difference?