      PROGRAM HOST01
C
C     PROBLEM 1
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,K,NK
      PARAMETER (KASES=6)
      INTEGER N(KASES)
      REAL TN
      REAL A,B,H
      DATA A,B / 0.0,1.0 /
      DATA N /  8192, 65536,
     X          131072, 262144, 524288, 1048576/
      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     ---- parameters of the initial broadcast ------------
      INTEGER*4 MSG(3),MSGSIZE
      DATA MSGSIZE /12/
      EQUIVALENCE (MSG(1),NK),(MSG(2),A),(MSG(3),H)
C     ---- parameters of messages with partial results ----
      INTEGER*4 PARTTYPE
      DATA PARTTYPE /20/


      WRITE(6,*) 'enter the number of processors'
      READ(5,*) NPROCS
      CALL open0(NPROCS,ME,HOST)
      CALL load0("node01",ALLNODES)
      CALL setarc0(NPROCS, TOP, ORD, DIR)
C
C               LOOP OVER KASES
C
      DO  K = 1, KASES
         NK=N(K)
      STARTTIME=clock0()
         DO MANY=1,100

         H = (B-A)/(NK-1)
         CALL bcast0(MSG,MSGSIZE,INITTYPE,HOST)
         CALL gsum0(TN,1,4,PARTTYPE,HOST)
         TN = H*((EXP(A)+EXP(B))/2.+TN)

         ENDDO
      HOST_SEC=clock0()-STARTTIME

      CALL recv0(NODE_SEC,TIMESIZE,TIMETYPE)

         PRINT 30,A,B,NK
   30    FORMAT ('PROBLEM 1 WITH A,B,N = ',2F10.3,5X,I8)
         PRINT 40,TN
   40    FORMAT ('GIVES TN =',F10.6)

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

      ENDDO

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



