|
forums.silverfrost.com Welcome to the Silverfrost forums
|
View previous topic :: View next topic |
Author |
Message |
mecej4
Joined: 31 Oct 2006 Posts: 1892
|
Posted: Sun Nov 18, 2018 5:34 pm Post subject: Incorrect results for sum(vector expression) |
|
|
FTN95 8.30.279 produces incorrect results or aborts with floating point errors for the following correct code. The value on line-21 was chosen to make the result to be exactly 0.
Code: | program tfu
implicit none
integer, parameter :: double=kind(0.d0), NX=16
real(double) :: x(NX),F
integer :: i,n
!
n = NX
Do i = 1, n, 4
x(i) = 1.0D0
x(i+1) = 3.0D0
x(i+2) =-1.0D0
x(i+3) = 0.0D0
End Do
print 10,x
F = sum (( x(:n-3:2) + 1.0D1*x(2:n-2:2))**2 &
+ 5.0D0*(x(3:n-1:2) - x(4:n:2))**2 &
+ (x(2:n-2:2) - 2.0D0*x(3:n-1:2))**4 &
+ 1.0D1*(x(:n-3:2) - x(4:n:2))**4) &
- 14195d0
print 20,F
10 format ('X = [',16F5.1,']')
20 format('F = ',F10.1,', expected value = 0.0')
End Program |
The results from various runs:
Code: |
OPTION RESULT
/check -11040.0
/checkmate -11040.0
- default - Floating point divide by zero
/opt Floating point divide by zero
/64 /check -11040.0
/64 *** AMD backend failure
/64 /opt -16929.0
|
|
|
Back to top |
|
|
JohnCampbell
Joined: 16 Feb 2006 Posts: 2560 Location: Sydney
|
Posted: Mon Nov 19, 2018 4:26 am Post subject: |
|
|
mecej4,
What an example !!
Where did you get this code from ?
What would happen if N is not a multiple of 4 ?
If this is an example of Fortran on WWW they didn't learn Fortran where I did.
I thought I would confirm your results. I am using FTN95 Ver 8.20.0
I also adapted your example to try and understand the implied loops in the array section. Code: | program tfu
implicit none
integer, parameter :: double=kind(0.d0), NX=16
real(double) :: x(NX),F, Acum
integer :: i,n,k
!
n = NX
Do i = 1, n, 4
x(i) = 1.0D0
x(i+1) = 3.0D0
x(i+2) =-1.0D0
x(i+3) = 0.0D0
End Do
print 10,x
acum = 0
do k = 0,n-4,2
acum = acum &
+ ( x(k+1) + 1.0D1*x(k+2) )**2 &
+ 5.0D0*( x(k+3) - x(k+4) )**2 &
+ ( x(k+2) - 2.0D0*x(k+3) )**4 &
+ 1.0D1*( x(k+1) - x(k+4) )**4
end do
acum = acum - 14195d0
print 30,acum
F = sum (( x(:n-3:2) + 1.0D1*x(2:n-2:2))**2 &
+ 5.0D0*(x(3:n-1:2) - x(4:n:2))**2 &
+ (x(2:n-2:2) - 2.0D0*x(3:n-1:2))**4 &
+ 1.0D1*(x(:n-3:2) - x(4:n:2))**4) &
- 14195d0
print 20,F
10 format ('X = [',16F5.1,']')
20 format ('F = ',F10.1,', expected value = 0.0')
30 format ('A = ',F10.1,', expected value = 0.0')
End Program |
I can confirm that I got the same results as you report.
(acum = 0 in all cases)
In the past, FTN95 has demonstrated errors when the available registers are not sufficient to convert a single statement. This looks like a likely possibility.
John |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7934 Location: Salford, UK
|
Posted: Mon Nov 19, 2018 8:51 am Post subject: |
|
|
Thank you for the bug report. I have logged this for investigation. |
|
Back to top |
|
|
mecej4
Joined: 31 Oct 2006 Posts: 1892
|
Posted: Mon Nov 19, 2018 9:24 am Post subject: |
|
|
John: Thanks for testing, and for the F77 version.
JohnCampbell wrote: |
Where did you get this code from ? What would happen if N is not a multiple of 4 ?
|
During the last few months, I replaced an older laptop with a new desktop PC, and thought of exploiting its power to uncover bugs that I suspected to be present in FTN95's code generation and optimisation, particularly for F95 language features. I wanted to use medium size (< 100K lines) packages that came with test examples and known results.
This particular example code came into being as follows. I took the PNED code from http://www.cs.cas.cz/luksan/subroutines.html and translated the code from F77 to F90 using VAST79. For some of the test problems, the F77 and F90 versions did not give the same results. I pruned the F90 code to obtain the example code above (TNEDU test, case NEXT = 3). The PNED example had N=1000; I reduced N to 16 to enable checking with pencil and paper, and ended up with the example code.
VAST79 produced code with syntax errors in this case, but I was able to correct those with the help of FTN95.
Yes, N has to be a multiple of 4; the example code serves only to demonstrate the compiler errors.
I found it amusing that in a couple of runs FTN95 aborted with FP divide by zero, when there is no apparent need to do any division at all.
Incidentally, FTN95 7.20 did better at compiling the example than 8.30 did. |
|
Back to top |
|
|
John-Silver
Joined: 30 Jul 2013 Posts: 1520 Location: Aerospace Valley
|
Posted: Mon Nov 19, 2018 10:48 am Post subject: |
|
|
I too tried testing.
I also put together a speadsheet to check tht the total was what you were expecting !
I found that the error seems to be in the 3rd and 4th expressions involving **4
the 3rd sub-expression in th formul�a for 'F' gives a result but it's wrong !
the ERROR occurs in the 4th sub-expression
Try this code where I've just seperated the 4 parts of the expression for 'F' .....
Code: | !
program tfu1b
implicit none
integer, parameter :: double=kind(0.d0), NX=16
real(double) :: x(NX),F
real(double) :: F1,F2,F3,F4,F5
real(double) :: F3A,F4A
!real(double) ::F1a
integer :: i,n
!
n = NX
Do i = 1, n, 4
x(i) = 1.0D0
x(i+1) = 3.0D0
x(i+2) =-1.0D0
x(i+3) = 0.0D0
End Do
print 10,x
!F = sum (( x(:n-3:2) + 1.0D1*x(2:n-2:2))**2 &
! + 5.0D0*(x(3:n-1:2) - x(4:n:2))**2 &
! + (x(2:n-2:2) - 2.0D0*x(3:n-1:2))**4 &
! + 1.0D1*(x(:n-3:2) - x(4:n:2))**4) &
! - 14195d0
!F1a = sum ( x(:n-3:2) )
!print 21,F1a
F1 = sum ( ( x(:n-3:2) + 1.0D1*x(2:n-2:2))**2 )
print 31,F1
F2 = sum ( 5.0D0*(x(3:n-1:2) - x(4:n:2))**2 )
print 32,F2
F3 = sum ( (x(2:n-2:2) - 2.0D0*x(3:n-1:2))**4 )
print 33,F3
F3A = sum ( ( (x(2:n-2:2) - 2.0D0*x(3:n-1:2))**2 )**2 )
print 330,F3A
F4A = sum ( 1.0D1* ( ( x(:n-3:2) - x(4:n:2) )**2 )**2 )
print 340,F4A
F4 = sum ( 1.0D1* ( x(:n-3:2) - x(4:n:2) )**4 )
print 34,F3
F5 = 14195d0
print 35,F5
F = F1 + F2 + F3 + F4 - F5
print 36,F
!print 20,F
10 format ('X = [',16F5.1,']')
!20 format('F = ',F10.1,', expected value = 0.0')
!21 format('F1a = ',F10.1,', component 1a of total'/)
31 format('F1 = ',F10.1,', component 1 of total')
32 format('F2 = ',F10.1,', component 2 of total')
33 format('F3 = ',F10.1,', component 3 of total')
34 format('F4 = ',F10.1,', component 4 of total')
35 format(/'F5 = ',F10.1,', constant of total')
36 format(//'F4 , TOTAL = ',F10.1,', Expected Value = 0.0 ')
330 format('F3A = ',F10.1,', (using double square for quadruple power) component 3 of total')
340 format('F4A = ',F10.1,', (using double square for quadruple power) component 4 of total')
End Program |
You'll see I tried also a 'double square' to replace the quadruple power but for the 3rd expression it also gives thye (same) wrong answer
The sub-exressions (by my spreadsheet calc) SHOULD give:
F1 3847
F2 80
F3 2548
F4 7720
The test program above run in 32bit (v8.3 perso with the 279 dlls ) gives for me:
F1 3847
F2 80
F3 1500 !!!! WRONG answer !
F3A (using double square in place of quadruple power) 1500 !!! same WRONG answer !
F4A (using double square) FAILs HERE ! no value
Also fails in F4 (quadruple power) before including F3A and F4A ! _________________ ''Computers (HAL and MARVIN excepted) are incredibly rigid. They question nothing. Especially input data.Human beings are incredibly trusting of computers and don't check input data. Together cocking up even the simplest calculation ... " |
|
Back to top |
|
|
mecej4
Joined: 31 Oct 2006 Posts: 1892
|
Posted: Mon Nov 19, 2018 1:26 pm Post subject: |
|
|
Thanks, John Silver. Guided by your feedback, I constructed a shorter example, and this exposes a couple of different bugs in the compiler.
Code: | program tfu0
implicit none
integer, parameter :: NX = 16
real :: x(NX),f,c,d
integer :: i, n = NX
x = [(1.0, 3.0, -1.0, 0.0, i=1,n/4)]
print 10,x
c = sum ((x(2:n-2:2) - 2.0*x(3:n-1:2))**4)
d = sum ((x(:n-3:2) - x(4:n:2))**4)
F = c + 10.0*d - 10268.0
print 20,c,d,F
10 format ('X = [',16F5.1,']')
20 format('c,d = ',2F10.1,' (expected: 2548.0, 772.0)',/' F = ', &
F10.1,', expected value = 0.0')
End Program tfu0 |
The results from FTN95 V 8.30.279:
Code: | -default- FP div by zero
/debug FP div by zero, line-12
/check Internal compiler error
/checkmate Access violation, line-12
/64 Incorrect results for c (1500), d (-576), F (-14528)
/64 /debug -ditto-
/64 /check Incorrect results for c (600), d (0), F (-9668)
/64 /checkmate -ditto- |
With the older V 7.20, this program gives correct results except when /opt is chosen. |
|
Back to top |
|
|
John-Silver
Joined: 30 Jul 2013 Posts: 1520 Location: Aerospace Valley
|
Posted: Wed Nov 21, 2018 1:42 am Post subject: |
|
|
results for 'F' are actually correct but based on the wrong c & d results ! _________________ ''Computers (HAL and MARVIN excepted) are incredibly rigid. They question nothing. Especially input data.Human beings are incredibly trusting of computers and don't check input data. Together cocking up even the simplest calculation ... " |
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 7934 Location: Salford, UK
|
Posted: Wed Jul 31, 2019 2:12 pm Post subject: |
|
|
This bug has now been fixed for the next release of FTN95. |
|
Back to top |
|
|
John-Silver
Joined: 30 Jul 2013 Posts: 1520 Location: Aerospace Valley
|
Posted: Wed Jul 31, 2019 5:34 pm Post subject: |
|
|
what was the problem ? _________________ ''Computers (HAL and MARVIN excepted) are incredibly rigid. They question nothing. Especially input data.Human beings are incredibly trusting of computers and don't check input data. Together cocking up even the simplest calculation ... " |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|