      PROGRAM NODE11
C
C     PROBLEM 11
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-NODE   (F77+mp)
C       ==================================================
C
      INCLUDE 'picl_def.h'
      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(1),MSGSIZE
      DATA MSGSIZE /4/
      EQUIVALENCE (MSG(1),NK)
C -----------------------------------------------------------
C      parameters of messages with partial results
C -----------------------------------------------------------
      INTEGER*4 PARTTYPE
      DATA PARTTYPE /20/
      INTEGER NK,NFMOM
      PARAMETER (NFMOM = 4)
      REAL TFMOM(NFMOM)
      REAL PI
      DATA PI / 3.1415926 /
      INTEGER NMAX,I,K
      PARAMETER (NMAX=262144)
      DIMENSION DATA(NMAX),COSWT(NMAX)
      CALL open0(NPROCS,ME,HOST)
      CALL setarc0(NPROCS,TOP,ORD,DIR)

  100 CONTINUE
      STARTTIME=clock0()
      CALL bcast0(MSG,MSGSIZE,INITTYPE,HOST)
      IF(NK.GT.0) THEN
        IF (ME.LT.NPROCS) THEN

         DO I = ME+1, NK, NPROCS
            DATA(I) = -I*10.0+1080*SIN(1+I*0.0623)
            DATA(I) = AMAX1(0.0,AMIN1(1000.,DATA(I)))
            DATA(I) = ALOG(DATA(I)+1.0)
         ENDDO

         TFMOM(1) = SUM(DATA,NK)/NK
         DO  K = 2, NFMOM
            DO I = ME+1, NK, NPROCS
               COSWT(I) = COS(PI*I*(K-1)/(NK+1)) * DATA(I)
            ENDDO
            TFMOM(K) = SUM(COSWT,NK)/NK
        ENDDO

      CALL gsum0(TFMOM,NFMOM,4,PARTTYPE,HOST)
      NODE_SEC=clock0()-STARTTIME

      IF(ME.EQ.0) CALL send0(NODE_SEC,TIMESIZE,TIMETYPE,HOST)
      GOTO 100
      ENDIF

      ELSE

      CALL close0(1)
      WRITE(6,*) 'end of the job on node', ME
      STOP

      ENDIF
      END


      FUNCTION SUM (X,N)
      DIMENSION X(N)
      S = 0
      DO 10 I = 1, N
         S = S+X(I)
   10 CONTINUE
      SUM = S
      RETURN
      END





