      PROGRAM HOST05
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 MIMD/iPSC860-1.00-HOST   (F77+mp)
C       ==================================================
C
      INCLUDE 'picl_def.h'
      INTEGER KASES,NS,NT
      PARAMETER (KASES=4)
      INTEGER N(KASES),M(KASES)
      DATA N / 64,64,256,128 /
      DATA M / 128,1024,256,4092/
      INTEGER NABOVE
      REAL AVER,AVERTOP,LOWABO
      LOGICAL GENIUS
      INTEGER IGEN
      DOUBLE PRECISION HOST_SEC, NODE_SEC, STARTTIME
      INTEGER*4 TIMESIZE, TIMETYPE
      DATA TIMESIZE,TIMETYPE /8,10/
      INTEGER*4 ME,HOST,ALLNODES
      INTEGER*4 NPROCS,TOP,ORD,DIR
      INTEGER*4 INITTYPE
      DATA INITTYPE /1/
      DATA TOP,ORD,DIR,ALLNODES /1,1,1,-1/
C -----------------------------------------------------------
C           parameters of the initial broadcast
C -----------------------------------------------------------
      INTEGER*4 MSG(2),MSGSIZE
      DATA MSGSIZE /8/
      EQUIVALENCE (MSG(1),NS),(MSG(2),NT)
C -----------------------------------------------------------
C      parameters of messages with partial results
C -----------------------------------------------------------
      INTEGER*4 AVETYPE,TOPTYPE,ABOVTYP,GENTYPE,LOWTYPE,SUMTYPE
      INTEGER*4 AVETYP1
      DATA AVETYPE,TOPTYPE,ABOVTYP,GENTYPE,LOWTYPE,SUMTYPE,AVETYP1
     *     /21,22,23,24,25,26,27/

      WRITE(6,*) 'enter the number of processors'
      READ(5,*) NPROCS
      CALL open0(NPROCS,ME,HOST)
      CALL load0("node05",ALLNODES)
      CALL setarc0(NPROCS, TOP, ORD, DIR)


      DO 50 K = 1, KASES

      STARTTIME=clock0()

      DO MANY=1,200
      NS=N(K)
      NT=M(K)
         CALL bcast0(MSG,MSGSIZE,INITTYPE,HOST)
         CALL recv0(AVER,4,AVETYP1)
         CALL gsum0(IGEN,1,2,GENTYPE,HOST)
         CALL gsum0(AVERTOP,1,4,TOPTYPE,HOST)
         CALL gmin0(LOWABO,1,4,LOWTYPE,HOST)
         CALL gsum0(NABOVE,1,2,ABOVTYP,HOST)
         IF(IGEN.GT.0) THEN
            GENIUS=.TRUE.
         ELSE
            GENIUS=.FALSE.
         ENDIF
         AVERTOP=AVERTOP/NABOVE


      ENDDO
      HOST_SEC=clock0()-STARTTIME

      CALL recv0(NODE_SEC,TIMESIZE,TIMETYPE)

      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

      PRINT *, 'TIME ON NODE 0 =',NODE_SEC,' SECONDS'
      PRINT *, 'TIME ON HOST 0 =',HOST_SEC,' SECONDS'

   50 CONTINUE

C     stop processes on nodes
C
      NS=-1
      CALL bcast0(MSG,MSGSIZE,INITTYPE,HOST)
      CALL close0(1)
      STOP
      END



