forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Labelled DO loop and /opt /64 leads to optimisation bug

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> 64-bit
View previous topic :: View next topic  
Author Message
mecej4



Joined: 31 Oct 2006
Posts: 1886

PostPosted: Sat Mar 09, 2024 6:35 pm    Post subject: Labelled DO loop and /opt /64 leads to optimisation bug Reply with quote

The following is what is left after trimming a 25,000 LOC Fortran 95 program to pin down a suspected optimisation bug.

Code:
program labDObug
   implicit none
   integer, parameter :: nx = 5, ny = 1, nz = 1
   integer i, j, k, ij, ik
   integer :: np(nx,ny), ktop(nx)

   np(:,1) = (/ (i, i=1,nx) /)
   ktop = 0
   do j = 1,ny
      iLoop: DO i = 1, nx
         ij = (j-1)*nx + i
         do k = nz, 1, -1
            ik = (k-1)*nx + i
            if (np(ik,j) /= 0) then
               ktop(ij) = k
               cycle iLoop
            endif
         end do !k
      end do iLoop
   end do !j
   print '(1x,10i5)',ktop
end program


The output when the options /opt /64 are used:

Code:
     1    0    0    0    0


The correct output, which is obtained with /64 alone, or in 32-bit compilations with or without /opt:

Code:
     1    1    1    1    1


In this tiny program, replacing "cycle iLoop" by "exit" makes the bug go away.
Back to top
View user's profile Send private message
JohnCampbell



Joined: 16 Feb 2006
Posts: 2554
Location: Sydney

PostPosted: Sun Mar 10, 2024 5:31 am    Post subject: Reply with quote

The following update identifies that ij is not being updated in the do i loop if /opt is selected
Code:
program labDObug
 use iso_fortran_env
   implicit none
   integer, parameter :: nx = 5, ny = 1, nz = 1
   integer i, j, k, ij, ik, n
   integer :: np(nx,ny), ktop(nx)

   write (*,*) 'Vern : ',compiler_version ()
   write (*,*) 'Opts : ',compiler_options ()

   np(:,1) = (/ (i, i=1,nx) /)
   ktop = 0
   n = 0
   do j = 1,ny
      iLoop: DO i = 1, nx
         ij = (j-1)*nx + i
         do k = nz, 1, -1
            n = n+1
            ik = (k-1)*nx + i
            if (np(ik,j) /= 0) then
               ktop(ij) = k
               cycle iLoop
            endif
         end do !k
      end do iLoop
   end do !j
   print '(1x,10i5)',ktop
   print '(1x,10i5)',n,ij

end program
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7927
Location: Salford, UK

PostPosted: Mon Mar 18, 2024 10:28 am    Post subject: Reply with quote

mecej4 and John

Thank you for the feedback. This failure has now been fixed for the next release of FTN95. The optimisation in question is number 30.
Back to top
View user's profile Send private message AIM Address
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> 64-bit All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
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