      PROGRAM PROB06
C
C     PROBLEM 6
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,K,NK
      PARAMETER (KASES=4)
      INTEGER N(KASES)
      REAL SOLUT
      DATA N / 8196,16384,65536,262144/
      REAL TARRAY(2),TIME1,TIME2
C
C               LOOP OVER KASES
C
      DO  K = 1, KASES
         NK=N(K)
      TIME1=DTIME(TARRAY)
         DO MANY=1,20
         CALL DOIT(NK,SOLUT)
        ENDDO
      TIME2=DTIME(TARRAY)

         PRINT *,'PROBLEM 6 WITH N = ',NK
         PRINT *,'GIVES SOLUTION =', SOLUT
      PRINT *, 'TIME',TIME2,' SECONDS'
      PRINT *, 'USER:',TARRAY(1),' SYSTEM:',TARRAY(2)

      ENDDO

      STOP
      END



      SUBROUTINE DOIT(NK,SOLUT)
      INTEGER NK
      REAL SOLUT
      INTEGER MAXD
      PARAMETER (MAXD=262144)
      DOUBLE PRECISION  L(MAXD),D(MAXD),T(MAXD),X(MAXD),Y(MAXD),U(MAXD)
      INTEGER I,II,K,LIMIT
C
      DO  I = 1, NK
c         L(I) = .88-.1*SIN(I*12.36)
c         D(I) = 1.+.01*COS(I*8.11)
c         U(I) = .75+.2*SIN(I*36.12+3.2)
         L(I) = 1.0d00
         D(I) = 0.5d00
         U(I) = 0.5d00
         Y(I) = 1.0d00
         X(I) = 0.0
         T(I) = 0.0
      ENDDO
C
C
C      LIMIT = LOG BASE 2 OF N
C
         LIMIT = 1.44269504*ALOG(FLOAT(NK))+.01
         K = 1
C
C                                 MAIN LOOP
C
         DO II = 1, LIMIT

            DO I = 1, NK
               L(I) = L(I)/D(I)
               U(I) = U(I)/D(I)
               Y(I) = Y(I)/D(I)
            ENDDO
C
C                         T IS A TEMPORARY ARRAY
C                   COMPUTE AND ASSIGN TO D, COMPUTE Y
C
            DO I = 1, K
               D(I) = 1.0 -U(I)*L(I+K)
               T(I) = Y(I)-U(I)*L(I+K)
            ENDDO
            DO  I = K+1, NK-K
               D(I) = 1.0 -L(I)*U(I-K)-U(I)*L(I+K)
               T(I) = Y(I)-L(I)*Y(I-K)-U(I)*L(I+K)
            ENDDO
            DO  I = NK-K+1, NK
               D(I) = 1.0 -L(I)*U(I-K)
               T(I) = Y(I)-L(I)*Y(I-K)
            ENDDO

C
C                          ASSIGN TO Y, COMPUTE L
C
            DO I = 1, K
               Y(I) = T(I)
               T(I) = 0.
            ENDDO
            DO I = K+1, NK
               Y(I) = T(I)
               T(I) = -L(I)*L(I-K)
            ENDDO
C
C                          ASSIGN TO L, COMPUTE U
C
            DO I = 1, NK-K
               L(I) = T(I)
               T(I) = U(I)*U(I+K)
            ENDDO
            DO I = NK-K+1, NK
               L(I) = T(I)
               T(I) = 0.
            ENDDO
C
C                          ASSIGN TO U
C
            DO I = 1, NK
               U(I) = T(I)
            ENDDO

            K = 2*K

      ENDDO

      DO I = 1, NK
        X(I) = Y(I)/D(I)
      ENDDO
      SOLUT = 0
      DO I = 1, NK
        SOLUT = SOLUT+X(I)
      ENDDO

      RETURN
      END
