      PROGRAM PROB08
C
C     PROBLEM 08
C
C  REFERENCE:  PROBLEMS TO TEST PARALLEL AND VECTOR LANGUAGES
C              CSD-TR 516, COMPUTER SCIENCE, PURDUE UNIVERSITY
C              JOHN R. RICE, MAY 1, 1985
C
C              REVISED BY JOHN R. RICE AND J. JING, OCT. 1, 1990
C
C
C      *************************************************
C      *      Adapted for FORTRAN D benchmarking       *
C      *    by  T. HAUPT  (haupt@sccs.npac.syr.edu)    *
C      *                                               *
C      *    Northeast Parallel Architectures Center    *
C      *   at Syracuse University, Syracuse, NY, USA   *
C      *************************************************
C
C
C       VERSION SEQUENTIAL-1.00  (PLAIN FORTRAN77)
C       ==================================================
      INTEGER KASES,NK,MK
      PARAMETER (KASES=4)
      INTEGER N(KASES),M(KASES)
      DATA N / 8192,65536,131072,65536/
      DATA M /3,4,4,8/
      REAL SUMD
      REAL TARRAY(2),TIME1,TIME2

      DO 50 K = 1, KASES

      TIME1=DTIME(TARRAY)
      DO MANY=1,150

      NK=N(K)
      MK=M(K)
      CALL DOIT(NK,MK,SUMD)
      ENDDO
      TIME2=DTIME(TARRAY)

      PRINT *,'PROBLEM 08 WITH N,M  =',NK,MK
      PRINT *,'GIVES SUM OF DIFFERENCES = ',SUMD


      PRINT *, 'TIME',TIME2,' SECONDS'
      PRINT *, 'USER:',TARRAY(1),' SYSTEM:',TARRAY(2)

   50 CONTINUE
      STOP
      END

      SUBROUTINE DOIT(NK,MK,SUMD)
      INTEGER NK,MK
      REAL SUMD
      INTEGER NDIM,MDIM,I,J,N
      PARAMETER (NDIM=131072)
      PARAMETER (MDIM=8)
      REAL X(NDIM),DIFF(NDIM,MDIM)

         DO I = 1, NK
            X(I) = .2*I+.01*COS(FLOAT(I))
            DIFF(I,1) = SIN(X(I))
         ENDDO

         SUMD = 0
         N=NK

         DO J = 2, MK
            N = N-1

           DO I = 1, N
             DIFF(I,J) = (DIFF(I+1,J-1)-DIFF(I,J-1))/(X(I+J-1)-X(I))
             SUMD = SUMD+DIFF(I,J)
           ENDDO
        ENDDO


      RETURN
      END









