      PROGRAM PROB05
C
C     PROBLEM 5
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 SIMD/DECmpp-1.00
C       ==================================================
C
      INTEGER KASES,NS,NT
      PARAMETER (KASES=5)
      INTEGER N(KASES),M(KASES)
      DATA N / 64,1024,64,256,128 /
      DATA M / 128,64,1024,256,4092 /
      INTEGER NABOVE
      REAL AVER,AVERTOP,LOWABO
      LOGICAL GENIUS
      INTEGER ITIME
      REAL TIME

      DO 50 K = 1, KASES

      CALL mpTIMERstart()

      DO MANY=1,200
      NS=N(K)
      NT=M(K)
      CALL DOIT(NS,NT,AVER,AVERTOP,GENIUS,NABOVE,LOWABO)

      ENDDO
      ITIME=mpTIMERelapsed()

      PRINT 60, NS,NT
  60  FORMAT ('PROBLEM 5 WITH ',I6,' STUDENTS AND ',I6,' TESTS')
      PRINT *,'AVERAGE TEST SCORE .....:',AVER
      PRINT *,'# SCORES ABOVE AVERAGE..:',NABOVE
      PRINT *,'AVERAGE ABOVE ..........:',AVERTOP
      PRINT *,'LOWEST SCORE ABOVE .....:',LOWABO
      PRINT *,'THERE IS GENIUS ........:',GENIUS

      TIME=FLOAT(ITIME)/1000
      PRINT *, 'DECmpp ELAPSED TIME:',TIME,' SECONDS'

   50 CONTINUE

      STOP
      END

      SUBROUTINE DOIT(NS,NT,AVER,AVERTOP,GENIUS,NABOVE,LOWABO)
      INTEGER NABOVE
      REAL AVER,AVERTOP,LOWABO
      LOGICAL GENIUS
      REAL, ARRAY(NT,NS) :: SCORES
      LOGICAL, ARRAY(NT,NS) :: ABOVE


         SCORES=60.0+40.0*SIN(SPREAD([1:NT],2,NS)*
     +          SPREAD([1:NS],1,NT)*0.0006321)

         SSUM=SUM(SCORES)
         AVER=SSUM/(NS*NT)
         WHERE(SCORES.GT.AVER)
           ABOVE=.TRUE.
           SCORES=SCORES*1.1
         ELSEWHERE
           ABOVE=.FALSE.
         ENDWHERE

         NABOVE=COUNT(ABOVE)
         AVERTOP=SUM(SCORES,MASK=ABOVE)/NABOVE
         LOWABO=MINVAL(SCORES,MASK=ABOVE)

       GENIUS=ANY(ALL(ABOVE,DIM=1))

      RETURN
      END



