|
forums.silverfrost.com Welcome to the Silverfrost forums
|
View previous topic :: View next topic |
Author |
Message |
mecej4
Joined: 31 Oct 2006 Posts: 1896
|
Posted: Wed Feb 07, 2024 9:49 pm Post subject: Error in dot_product with /64 /opt |
|
|
When the options /64 and /opt are used to compile code containing invocations of the Fortran intrinsic DOT_PRODUCT, FTN95 V9.0 may generate calls to its RTL function DOT_PRODUCT8@ or it may generate a loop inline for the same purpose. I suspect that in the former case it is not passing the correct arguments to DOT_PRODUCT8@, or the RTL function itself may contain a bug. The user may see the result as zero or an access violation may occur in CLEARWIN64.DLL.
Here is a demonstrator:
Code: | program dotbug
implicit none
integer, parameter :: kdp = kind(0.0d0)
real(kind=kdp), dimension(:,:), allocatable :: ap
integer nbn, l, nn, i
nbn = 6479
l = 0
allocate (ap(1:nbn, 0:l))
do i = 1, nbn
ap(i,l) = 2.1d0*i-1.4d0
end do
call ssq(nbn,ap)
end program
subroutine ssq(nbn,ap)
implicit none
integer, parameter :: kdp = kind(0.0d0), nsdr = 1
integer, intent(in out) :: nbn
real(kind=kdp), dimension(nbn,0:*), intent(in out) :: ap
!
integer :: l
real(kind=kdp), dimension(0:nsdr-1) :: delta
!
l = 0
! The next line may result in a call to the FTN95 library function dot_product8@,
! depending on the compiler options used in addition to /64
delta(l) = dot_product(ap(1:nbn,l),ap(1:nbn,l))
print '(1x,A,i2,i5,es12.2)','SSQ: l,nbn,delta(l) = ',l,nbn,delta(l)
stop
end subroutine ssq |
When this code is compiled with /64 and run, the output is
Code: | SSQ: l,nbn,delta(l) = 0 6479 4.00E+11 |
If I use /64 /opt and run, an access violation occurs in the routine DOT_PRODUCT8$ (at address 60) within CLEARWIN64.DLL. |
|
Back to top |
|
|
JohnCampbell
Joined: 16 Feb 2006 Posts: 2584 Location: Sydney
|
Posted: Thu Feb 08, 2024 6:01 am Post subject: |
|
|
Hi mecej4,
Thanks for this example. I can reproduce your result, even after changing your code !
I replaced "l" with "K', as "l" is the worst variable name to use with the default font !
I tried adding "compiler_version ()", but the bug disappeared.
I also tried
* reporting array dimensions (which show no problem with unusual dimensions)
* and also used a temporary vector ( that did not have the error )
* but your reported error remains in my expanded code
My compiler options were /64 /opt /link
My default compile options were also ( /intl /logl /error_number /implicit_none )
My temporary vector shows dot_product works in another form, so could the error be related to the address of the array section "ap(1:nbn,K)"
I am using FTN95/x64 Ver. 9.00.0 (without any updates)
FTN95 Ver 8.97.2 does not report this error
My expanced code is:
Code: | use iso_fortran_env
implicit none
integer, parameter :: kdp = kind(0.0d0)
real(kind=kdp), dimension(:,:), allocatable :: ap
real*8 :: del
integer nbn, K, nn, i
! write (*,*) compiler_version () ! bug disappers if this line is used
nbn = 6479
K = 0
allocate (ap(1:nbn, 0:K))
do i = 1, nbn
ap(i,K) = 2.1d0*i-1.4d0
end do
WRITE (*,*) 'size(ap) =',size(ap)
del = dot_product ( ap(1:nbn,K), ap(1:nbn,K) )
write (*,*) 'del =',del
call ssq(nbn,ap)
end program
subroutine ssq(nbn,ap)
implicit none
integer, parameter :: kdp = kind(0.0d0), nsdr = 1
integer, intent(in out) :: nbn
real(kind=kdp), dimension(nbn,0:*), intent(in out) :: ap
real(kind=kdp), dimension(nbn) :: vec
!
integer :: K
real(kind=kdp), dimension(0:nsdr-1) :: delta
!
write (*,*) 'delta', lbound(delta), ubound(delta), size(delta)
K = 0
write (*,*) 'ap ', lbound(ap), ubound(ap,1) ! , size(ap)
! The next line may result in a call to the FTN95 library function dot_product8@,
! depending on the compiler options used in addition to /64
vec = ap(1:nbn,K)
delta(K) = dot_product ( vec, vec ) ! this line works
print '(1x,A,i2,i5,es12.5)','vec: K,nbn,delta(K) = ',K,nbn,delta(K)
delta(K) = dot_product (ap(1:nbn,K), ap(1:nbn,K) ) ! this line fails with /64 /opt /link
print '(1x,A,i2,i5,es12.5)','SSQ: K,nbn,delta(K) = ',K,nbn,delta(K)
stop
end subroutine ssq |
|
|
Back to top |
|
|
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8016 Location: Salford, UK
|
Posted: Thu Feb 08, 2024 9:32 am Post subject: |
|
|
mecj4
Thank you for the feedback. This failure has now been fixed for the next release of FTN95. A temporary work-around is to add /inhibit_opt 96.
John
Have you seen my recent pm to you? |
|
Back to top |
|
|
mecej4
Joined: 31 Oct 2006 Posts: 1896
|
Posted: Thu Feb 08, 2024 9:34 am Post subject: |
|
|
John, thanks for trying out the example. It took me many hours to create a reproducer. I noticed this elusive bug in the USGS HST3D groundwater code. Many of my earlier earlier attempts failed because shortening the code (originally about 20,000 LOC) made the bug disappear, and it is time-consuming to probe a program that was, of necessity, compiled without debug support.
As you reported, adding a PRINT or WRITE statement may cause the bug to be suppressed. |
|
Back to top |
|
|
JohnCampbell
Joined: 16 Feb 2006 Posts: 2584 Location: Sydney
|
Posted: Thu Feb 08, 2024 12:29 pm Post subject: |
|
|
mecej4,
The modified code I posted:
showed "delta(K) = dot_product ( vec, vec ) " appeared to work,
but "delta(K) = dot_product (ap(1:nbn,K), ap(1:nbn,K) ) " still failed with a
similar error report.
With these types of error, (which could possibly be a stack corruption) "appeared to work" is no guarantee that the error is avoided, but I hoped could suggest where the bug might be.
I note Paul suggests the bug has been located.
Paul, I have replied to your PM. |
|
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
|