[comp.sys.dec] Optimizer bug in f77 v2.1 on DS3100

matter@milton.u.washington.edu (Matthew Trunnell) (07/06/90)

We have been having a continuing series of problems with the Fortran
compliler on the DS3100.  We are running UWS2.1 and I have just installed
v2.1 of the f77 which was supposed to fix some bugs in the earlier unsupported
release of v2.1 and v2.0.

The problem appears unpredictably with either -O2 or -O3 optimization
specified.  The symptom is that the executible runs fine but gives the wrong
numbers with the higher optimization.  Even I could write a compiler to
produce fast code if the answers didn't matter...

Here is a sample of the problem.  The source code (included below) was written
by a student with no claims of being a programmer, so I have not entirely
ruled out the possibility that some of the difficulty arises from non-standard
language use.

-----------------------------------------------------------------------------
snapper% f77 -o test parker.f
snapper% f77 -o test2 -O2 parker.f
snapper% test
 tau   3.604890
 ttime         113
   7.1585506E-02  0.0000000E+00
   6.3956492E-02 -0.0000000E+00
snapper% test2
 tau   3.604890
 ttime         113
   7.1585506E-02  0.0000000E+00
   5.2087046E-03 -0.0000000E+00
snapper%
-----------------------------------------------------------------------------

Incidentally, the unoptimized result above agrees with every other compiler I
have tried.

There seems to be some sensitivity to the position of comments and
never-executed lines in the source code.


Has anyone had similar problems?  Is there some way of assuring that accurate
code will be generated?

Thanks for your time.

matter
-----------------------------------------------------------------------------
Matthew Trunnell Ec-2                              matter@ocean.washington.edu
-----------------------------------------------------------------------------

Here is the source for parker.f:


      program test



c      ********* variables ***********
      real u0(0:400),u1(0:400),v0(0:400),v1(0:400)
      real b0(0:400),b1(0:400)
      real f,n,alpha,vee,dt,dz,s,s1,z
      real nu,kappa,ds,tau0
      real ff,ral,nn,m0,t,tau,sal
      real m,interval,d1b,d2b,d3b,nc
      integer i,j,ns,nt,depth,ttime,looktime,looktau
c
c      ************ data ************
      data f,n,nu /1.0,2.0,.01/
      data depth /10/
      data dz,dt /.025,.005/
      alpha=15.
      kappa=0.
      vee=-1.
      looktau=5

c      ********* setting some values ************
      ral=2.0*3.14159*alpha/360.0
      ff=f*cos(ral)
      ds=(2.*nu/ff)**.5
      nn=n*n*sin(ral)
      nc=n*n*cos(ral)
      tau0=ff/(nn*sin(ral))
      s=ff*tau0
      s1=(1.+s)/s
      tau=tau0*(1.+2.*kappa/(vee*ds*tan(ral)))**-1
      m0=-vee*ds/2.0
      sal=sin(ral)
      ns=int(depth/dz)
      looktime=int(tau*looktau)
      ttime=int(30.*tau)+5
      print*,'tau',tau
      print*,'ttime',ttime
      nt=int(ttime/dt)
      interval=1./dt
c      ********** Ekman Initial Condition **********
100   do 110 i=0,ns
        z=dz*float(i)
        u0(i)=-vee*sin(z/ds)*exp(-z/ds)
        v0(i)=vee*(1.-cos(z/ds)*exp(-z/ds))
        b0(i)=0.
110   continue
c
c      ******* timeloop *******
300   do 1000 i=0,300
        t=float(i)*dt
c
c      ****** solving the difference equations *******
400     do 500 j=1,ns-1
          d1b=nu*(u0(j+1)-2.*u0(j)+u0(j-1))/dz**2
          u1(j)=u0(j)+dt*(ff*(v0(j)-vee)-sal*b0(j)+d1b)
          d2b=nu*(v0(j+1)-2.*v0(j)+v0(j-1))/dz**2
          v1(j)=v0(j)+dt*(-ff*u0(j)+d2b)
          d3b=kappa*(b0(j+1)-2.*b0(j)+b0(j-1))/dz**2
c---------------------------------------------------------------------c
c  The following never-true IF statement prevents the uopt from
c  choking.
c---------------------------------------------------------------------c
c         if(d3b.ne.0.)stop("SPAM")
c         b1(j)=b0(j)+dt*(nn*u0(j)+d3b)
          b1(j)=b0(j)+dt*(nn*u0(j))
500     continue
c
c      ******* boundary conditions *********
        u1(0)=0.
        v1(0)=0.
        b1(0)=0.
        u1(ns)=u1(ns-1)
        v1(ns)=v1(ns-1)
        b1(ns)=b1(ns-1)
c
c      ****** branch to read transport values or not *********
        if(mod(i,interval).eq.0)then
          goto 520
        else
          goto 700
        endif
c
c      ****** read values to transport output file *********
520     m=0.
600     do 610 j=0,ns-1
          m=m+dz*(u0(j)+u0(j+1))/2.0
610     continue
        write(6,*)m,d3b
c      ****** resetting the variables before the next timestep *****
700     do 800 j=0,ns
          u0(j)=u1(j)
          v0(j)=v1(j)
          b0(j)=b1(j)
800     continue
c
c      ******* closing the timeloop *******
1000  continue
      end