This program run Ok on the Macintosh or on LINUX with the -g option, but fails with the -O option on LINUX. dir/junk2> gfortran -w -O -o timefun timefun.f dir/junk2> timefun < timefun.in 1t i m e f u n c t i o n d a t a number of time functions (ntfn) = 1 max number of points in time functions (nptm) = 2 time function number = 1 number of time points = 2 time value function 0.00000 0.0000000E+00 1.00000 0.1000000E+01 "" error time is larger than in the time function 2 2 1 1 1.00000000000000 1.00000000000000 STOP 0 dir/junk2> gfortran -w -g -o timefun timefun.f dir/junk2> timefun < timefun.in 1t i m e f u n c t i o n d a t a number of time functions (ntfn) = 1 max number of points in time functions (nptm) = 2 time function number = 1 number of time points = 2 time value function 0.00000 0.0000000E+00 1.00000 0.1000000E+01 STOP 0 dir/junk2> cat timefun.in 1 2 1 2 0. 0. 1. 1. dir/junk2> cat timefun.f program main implicit real*8 (a-h,o-z) save common /sol/ numnp,neq,nwk,nwm,nwc,numest,midest,maxest,nste,ma common/const/ dt,dta,acoef(21),dtod,iope common a(1000) dt=0.1d0 dta=0.1d0 nste=10 itwo=2 read (5,1010) ntfn,nptm if (idatwr.le.1) write (6,2250) ntfn,nptm c if (ntfn.eq.0) go to 15 m2=n1 + ntfn m3=m2 + ntfn*nptm*itwo m4=m3 + ntfn*nptm*itwo m5=m4 + ntfn*nste*itwo m6=m5 + ntfn*itwo - 1 c call timfun (a(m5),a(n1),a(m2),a(m3),a(m4),ntfn,nptm) 15 continue stop 1010 format (16i5) 2250 format (1h1,35ht i m e f u n c t i o n d a t a //4x, 148h number of time functions (ntfn) =,i5//4x, 248h max number of points in time functions (nptm) =,i5) end subroutine timfun (rgst,ipnt,timv,rv,rg,ntfn,nptm) c c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . c . . c . subroutine to calculate time function values at all time points . c . the time function values are stored in rg . c . . c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . c implicit real*8 (a-h,o-z) save c common /isubst/ isub,nsubst,nsub,ntuse,negls,negnls,numnps, 1 nodcon,nodret,idofs(6),ndofs,neqs,nwks,maxes, 2 mas,nstape,iloa(9),krsizm,neqc common /sol/ numnp,neq,nwk,nwm,nwc,numest,midest,maxest,nste,ma common /var/ ng,modex,iupdt,kstep,itemax,ieqref,ite,kpri, 1 iref,iequit,ipri,kplotn,kplote common/const/ dt,dta,acoef(21),dtod,iope common /adinai/ opvar(7),tstart,irint,istote common /prcon/ idatwr,ipric,npb,idc,ivc,iac,ipc,ipnode(3,15) c dimension rg(ntfn,1),timv(nptm,1),rv(nptm,1),ipnt(1),rgst(1) c c write(6,*)tstart,dt,dta,nptm,ntfn,nste do 100 l=1,ntfn read (5,1000) ll,npts if (ll - l) 80,90,80 80 write (6,2000) stop c 90 if (idatwr.le.1) write (6,2002) l,npts ipnt(ll)=npts read (5,1020) (timv(i,ll),rv(i,ll),i=1,npts) if (idatwr.gt.1) go to 95 write (6,2004) (timv(i,ll),rv(i,ll),i=1,npts) 95 if (npts.le.nptm) go to 100 write (6,2100) l,npts,nptm stop 100 continue c nt=13 if (nsubst.gt.0) nt=15 rewind nt do 200 l=1,ntfn rgst(l)=rv(1,l) npts=ipnt(l) time=tstart + dt timep=tstart + dta i=0 k=1 120 i=i + 1 if (i-npts) 190,130,130 130 write (6,2010) write(6,*)i,npts,ntfn,l,time,timep stop c 190 ddr=rv(i+1,l) - rv(i,l) ddt=timv(i+1,l) - timv(i,l) if (ddt) 110,120,150 110 write (6,2020) stop 150 slope=ddr/ddt 180 if (timv(i+1,l)-time) 120,140,140 140 rg(l,k)=rv(i,l) + slope*(timep-timv(i,l)) timep=time + dta time=time + dt k=k + 1 if (nste-k) 195,180,180 195 write (nt) rgst(l),(rg(l,k),k=1,nste),npts, 1 (rv(j,l),timv(j,l),j=1,npts) 200 continue c return c 1000 format (2i5) 1020 format (8f10.0) 2000 format (43h "" error time functions out of order ) 2002 format (/25h time function number =,i5/ 1 25h number of time points =,i5//4x, 2 25h time value function/) 2004 format (3x,f12.5,2x,e15.7) 2010 format (53h "" error time is larger than in the time function) 2020 format (42h "" error time points are out of order ) 2100 format (///28h *** i n p u t e r r o r -// 1 30h detected by subroutine timfun/ 2 30h while reading time functions // 3 5x,23h time function number =,i5/ 4 5x,36h number of points in this function =,i5, 5 17h is greater than/ 6 5x,36h the max number of points requested=,i5, 7 49h as specified on the time function control card. // 4 12h *** s t o p) c end
I suggest running the code through ftnchek and fixing potential problems. These looks suspicious Warning in module MAIN in file show_bug.f: Variables used before set IDATWR used at line 15 file show_bug.f; never set N1 used at line 18 file show_bug.f; never set Warning: Common block ISUBST Elements used but never set: NSUBST Warning: Common block ADINAI Elements used but never set: TSTART Warning: Subprogram TIMFUN argument data type mismatch at position 2: Dummy arg IPNT in module TIMFUN line 35 file show_bug.f is type intg Actual arg A(N1) in module MAIN line 24 file show_bug.f is type real*8 Warning: Subprogram TIMFUN argument arrayness mismatch at position 1: Dummy arg RGST in module TIMFUN line 35 file show_bug.f is whole array Actual arg A(M5) in module MAIN line 24 file show_bug.f is array element and at position 2: Dummy arg IPNT in module TIMFUN line 35 file show_bug.f is whole array Actual arg A(N1) in module MAIN line 24 file show_bug.f is array element and at position 3: Dummy arg TIMV in module TIMFUN line 35 file show_bug.f is whole array Actual arg A(M2) in module MAIN line 24 file show_bug.f is array element Warning: Subprogram TIMFUN argument usage mismatch at position 1: Dummy arg RGST in module TIMFUN line 35 file show_bug.f is modified Actual arg A(M5) in module MAIN line 24 file show_bug.f may be same as arg 5: A(M4) and at position 2: Dummy arg IPNT in module TIMFUN line 35 file show_bug.f is modified Actual arg A(N1) in module MAIN line 24 file show_bug.f may be same as arg 1: A(M5) and at position 3: Dummy arg TIMV in module TIMFUN line 35 file show_bug.f is modified Actual arg A(M2) in module MAIN line 24 file show_bug.f may be same as arg 2: A(N1)
In pulling the routines out, I forgot to set n1=1 and zero the others, but it does not affect the results. The rest of the warning messages indicate that ftnchek does not know how to correctly handle a program that does its own dynamic memory management. In this case, there is enough information for ftnchek to tell that the program is correct - if it analyzed the program and did the math symbolically. I suspect that it is impossible to make ftnchek happy with this type of program.
Hmm, -fno-tree-loop-im fixes it for some reason
Hmm, this worked in 4.0.0.
Here is the slightly revised version that I tried on 9 compilers on four different system - "gfortran -O" on linux is the only place that it failed. program main implicit real*8 (a-h,o-z) save common /prcon/ idatwr,ipric,npb,idc,ivc,iac,ipc,ipnode(3,15) common /sol/ numnp,neq,nwk,nwm,nwc,numest,midest,maxest,nste,ma common/const/ dt,dta,acoef(21),dtod,iope common a(1000) n1=1 dt=0.1d0 dta=0.1d0 nste=10 itwo=2 idatwr=0 read (5,1010) ntfn,nptm write (6,2250) ntfn,nptm c if (ntfn.eq.0) go to 15 m2=n1 + ntfn m3=m2 + ntfn*nptm*itwo m4=m3 + ntfn*nptm*itwo m5=m4 + ntfn*nste*itwo m6=m5 + ntfn*itwo - 1 c call timfun (a(m5),a(n1),a(m2),a(m3),a(m4),ntfn,nptm) 15 continue stop 1010 format (16i5) 2250 format (1h1,35ht i m e f u n c t i o n d a t a /4x, 148h number of time functions (ntfn) =,i5/4x, 248h max number of points in time functions (nptm) =,i5) end subroutine timfun (rgst,ipnt,timv,rv,rg,ntfn,nptm) c c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . c . . c . subroutine to calculate time function values at all time points . c . the time function values are stored in rg . c . . c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . c implicit real*8 (a-h,o-z) save c common /isubst/ isub,nsubst,nsub,ntuse,negls,negnls,numnps, 1 nodcon,nodret,idofs(6),ndofs,neqs,nwks,maxes, 2 mas,nstape,iloa(9),krsizm,neqc common /sol/ numnp,neq,nwk,nwm,nwc,numest,midest,maxest,nste,ma common /var/ ng,modex,iupdt,kstep,itemax,ieqref,ite,kpri, 1 iref,iequit,ipri,kplotn,kplote common/const/ dt,dta,acoef(21),dtod,iope common /adinai/ opvar(7),tstart,irint,istote common /prcon/ idatwr,ipric,npb,idc,ivc,iac,ipc,ipnode(3,15) c dimension rg(ntfn,1),timv(nptm,1),rv(nptm,1),ipnt(1),rgst(1) c c write(6,*)tstart,dt,dta,nptm,ntfn,nste do 100 l=1,ntfn read (5,1000) ll,npts if (ll - l) 80,90,80 80 write (6,2000) stop c 90 if (idatwr.le.1) write (6,2002) l,npts ipnt(ll)=npts read (5,1020) (timv(i,ll),rv(i,ll),i=1,npts) if (idatwr.gt.1) go to 95 write (6,2004) (timv(i,ll),rv(i,ll),i=1,npts) 95 if (npts.le.nptm) go to 100 write (6,2100) l,npts,nptm stop 100 continue c nt=13 rewind nt do 200 l=1,ntfn rgst(l)=rv(1,l) npts=ipnt(l) time=tstart + dt timep=tstart + dta i=0 k=1 120 i=i + 1 if (i-npts) 190,130,130 130 write (6,2010) write(6,*)i,npts,ntfn,l,time,timep stop c 190 ddr=rv(i+1,l) - rv(i,l) ddt=timv(i+1,l) - timv(i,l) if (ddt) 110,120,150 110 write (6,2020) stop 150 slope=ddr/ddt 180 if (timv(i+1,l)-time) 120,140,140 140 rg(l,k)=rv(i,l) + slope*(timep-timv(i,l)) timep=time + dta time=time + dt k=k + 1 if (nste-k) 195,180,180 195 write (nt) rgst(l),(rg(l,k),k=1,nste),npts, 1 (rv(j,l),timv(j,l),j=1,npts) 200 continue c return c 1000 format (2i5) 1020 format (8f10.0) 2000 format (43h "" error time functions out of order ) 2002 format (/25h time function number =,i5/ 1 25h number of time points =,i5/4x, 2 25h time value function) 2004 format (3x,f12.5,2x,e15.7) 2010 format (53h "" error time is larger than in the time function) 2020 format (42h "" error time points are out of order ) 2100 format (///28h *** i n p u t e r r o r -// 1 30h detected by subroutine timfun/ 2 30h while reading time functions // 3 5x,23h time function number =,i5/ 4 5x,36h number of points in this function =,i5, 5 17h is greater than/ 6 5x,36h the max number of points requested=,i5, 7 49h as specified on the time function control card. // 4 12h *** s t o p) c end
Dale, I've compiled your new code with both 4.0 and 4.1 with -O0, -O1, -O2, and -O3. It runs and a comparison of the output shows the results that you expect. How old is your version(s) of gfortran? Can you add -fdump-tree-all to the command line for the case that fails, and send me the *.original and *.optimized files?
(In reply to comment #6) > How old is your version(s) of gfortran? Mine is last night's compiler: gcc version 4.1.0 20050811 (experimental) and I can reproduce Dale's issue and found it to be lim which is causing it but how I have not looked.
Subject: Re: [4.1 Regression] program works correctly with -g option but fails with -O option on LINUX On Thu, Aug 11, 2005 at 10:38:59PM -0000, pinskia at gcc dot gnu dot org wrote: > > ------- Additional Comments From pinskia at gcc dot gnu dot org 2005-08-11 22:38 ------- > (In reply to comment #6) > > How old is your version(s) of gfortran? > Mine is last night's compiler: gcc version 4.1.0 20050811 (experimental) > and I can reproduce Dale's issue and found it to be lim which is causing > it but how I have not looked. > OK. This may be a regression. I accidently used the wrong gfortran compilers. I need to find my newest builds and run some more tests. troutmask:sgk[242] gfc41 --version GNU Fortran 95 (GCC 4.1.0 20050610 (experimental)) troutmask:sgk[243] gfc40 --version GNU Fortran 95 (GCC 4.0.1 20050527 (prerelease))
I don't see anything suspicious after lim. But without lim (store motion), almost no other loop optimizers are able to do anything on this testcase (everything is a global variable), so perhaps the problem is somewhere else.
I found that using the -ffloat-store option fixed the problem.
Ok, then it is a dup of 323 then. *** This bug has been marked as a duplicate of 323 ***