考虑这个 Fortran 程序:
program main
implicit none
double complex :: a(51,51),b(51,51)
Integer::i,j
real(8)::ht=0.01
real(8) T1,T2
do i=1,51
do j=1,51
a(i,j)=cmplx(Sin(0.01*i),Cos(0.01*j))
end do
end do
call cpu_time(T1)
do i=1,23497
b(:,:)=(0.,1.)*ht/2.*a(:,:)
end do
call cpu_time(T2)
write(*,*) sum(b)
print '("Time = ",f12.9," seconds.")', T2-T1
end program main
输出是
(-12.4321907340245,3.30723047182099)
Time = 0.052991000 seconds.
如果我们注释掉write(*,*) sum(b)
,输出是
Time = 0.000000000 seconds.
似乎循环没有执行,为什么会这样?