When working with a test code related to a compiler bug (for details, see this recent thread: http://forums.silverfrost.com/viewtopic.php?p=23660), I thought that I had found another compiler bug: a small change in the program, namely, changing two variables from 32-bit integers to 64-bit integers, seemed to make the resulting EXE hang. It turns out that the program had become about twenty times slower (800 times slower than with Gfortran).
Here is the test program:
program fbug
implicit none
integer, parameter :: N8 = selected_int_kind(15)
integer, parameter :: HundredMill = 100000000
integer(N8) :: i, j ! could be plain integers, instead
integer(N8) :: s
s = 0_N8
do i = 1, 30
do j=1,HundredMill
s = s + j
end do
write(*,*)i,s
end do
write (*,*) 's =', s
end
Here are some timing results from this program:
gftn -m32 -O2 0.047 s
gftn -m64 -O2 0.047 s
ftn95 /opt 40.89 s
ftn95 /opt /64 2.199 s
The GCC versions were 4.8 (32-bit) and 6.2 (64-bit), and I used FTN95 8.10, all on a laptop with an i5-4200U CPU and running Windows 10 64-bit.
I think that one has to be careful about using 64-bit integers with 32-bit FTN95. The use of X87 instructions for performing 8-byte integer arithmetic is probably the root cause of the slow-down.
Changing the DO loop index variables to 32-bit integers (by removing '(N8)' on Line 5) improves the timings, but there is room for much improvement.
gftn -m32 -O2 3.118 s
gftn -m64 -O2 1.256 s
ftn95 /opt /64 2.221 s
ftn95 /opt 16.594 s
It is curious that the same change (removing '(N8)') that helped speed up the EXE compiled with FTN95 caused the EXE compiled with GFortran to slow down significantly. Please note that with '(N8)' in place, the GFortran compiler is smart enough to optimize away the inner loop, which explains the apparent high speed of the EXE that it produces.