FORTRAN Dialects


FORTRAN 77

C     AHL'S SIMPLE BENCHMARK 
C     REMOVE C IN FRONT OF CODE LINES IF YOUR FORTRAN HAS A 
C       UNIX-LIKE TIME FUNCTION
      DOUBLE PRECISION R,S,A
      INTEGER I,N
C     INTEGER ITER,T,TIME
      DOUBLE PRECISION DRAND


      WRITE (*,*)
     1  'ahl.f77-- the Fortran-77 version of Ahls simple benchmark'
C     ITER=DRAND(TIME(0))
C     ITER=0
C     T=TIME(0)
C  10 CONTINUE
C     IF (T .EQ. TIME(0)) GO TO 10
C     T=TIME(0)
C  20 CONTINUE
C     ITER=ITER+1
      R=0.
      S=0.
      DO 30 N=1,100
      A=N
      DO 40 I=1,10
      A=DSQRT(A) 
      R = R + DRAND(0)
   40 CONTINUE
      DO 50 I=1,10
      A = A*A 
      R = R + DRAND(0)
   50 CONTINUE   
      S = S + A
   30 CONTINUE   
C     IF ((TIME(0)-T) .LT. 20) GO TO 20
C     WRITE (*,*) ITER,' iterations'
C     WRITE (*,*) 20./ITER,' seconds per iteration'
      WRITE (*,*) 'Accuracy ',DABS(1010.0D0-S/5.0D0)
      WRITE (*,*) 'Random ',DABS(1000.0D0-R)
      END

Extended F77

C      Ahl's simple benchmark 
C      Remove C in front of code lines if your fortran has a 
C       Unix-like time function
       double precision  r,s,a
       integer i,n
C      integer*4 t,time,iter
       double precision drand


       print *,
      1 'ahl.f-- the Extended Fortran-77 version of Ahls simple benchmark'
C      iter=drand(time(0))
C      iter=0
C      t=time(0)
C      do while (t .eq. time(0))
C      end do
C      t=time(0)
C      do while ((time(0)-t) .lt. 20) 
C        iter=iter+1
         r=0.
         s=0.
         do n=1,100
           a=n
           do i=1,10
             a=dsqrt(a) 
             r = r + drand(0)
           end do
           do i=1,10
             a = a*a 
             r = r + drand(0)
           end do 
           s = s + a
         end do 
C      end do 
C      print *,iter,' iterations'
C      print *,20./iter,' seconds per iteration'
       print *,'Accuracy ',abs(1010.-s/5.)
       print *,'Random ',abs(1000.-r)
       end

VAX FORTRAN

C      Ahl's simple benchmark 
       double precision  r,s,a
       real*4 t1,t
       integer*4 seed
       integer i,n,iter


       print *,
     +  'ahlvax.for-- the VAX Fortran version of Ahls simple benchmark'
       iter=0
       t=secnds(0.0)
       seed=(int(t*256.)+1)
       t1=t
       do while (t .eq. t1)
	t=secnds(0.0)
       end do
       t1=t
       do while ((t-t1) .lt. 20) 
         iter=iter+1
         r=0.
         s=0.
         do n=1,100
           a=n
           do i=1,10
             a=a**0.5 
             r = r + ran(seed)
	   end do
           do i=1,10
             a = a**2 
             r = r + ran(seed)
           end do 
           s = s + a
         end do 
         t=secnds(0.0)
       end do 
       print *,iter,' iterations'
       print *,(t-t1)/iter,' seconds per iteration'
       print *,abs(1010.-s/5.)
       print *,abs(1000.-r)
       end


Copyright © 2001 Eric Korpela
korpela@ssl.berkeley.edu