C***********************************************************
C            Test Program of MPI / test-2
C
C                                H. Matsufuru  20 Jan 2000
C***********************************************************
      PROGRAM TEST2
C
      IMPLICIT REAL*8 (A-H, O-Z)
      INCLUDE 'mpif.h'
C----------Variables----------------------------------------
      DIMENSION A(2)
C------------Main-------------------------------------------
C
      CALL MPI_Init(ierr)
C
      CALL MPI_Comm_size(MPI_COMM_WORLD, Nproc, ierr)
      CALL MPI_Comm_rank(MPI_COMM_WORLD, Nid, ierr)
C
      IF(Nid.EQ.0) READ(*,*) N
      IF(Nid.EQ.0) READ(*,*) A(1),A(2)
C
      CALL MPI_Bcast( N, 1, MPI_INTEGER, 0,
     &                             MPI_COMM_WORLD, ierr )
      CALL MPI_Bcast( A(1), 2, MPI_DOUBLE_PRECISION, 0,
     &                             MPI_COMM_WORLD, ierr )
C
      B = A(1) + A(2)*DBLE(N*Nid)
C
      DO 100 inode = 0, Nproc-1
        IF(inode.EQ.Nid)
     &    WRITE(*,'(A,I4,2F10.4,I4,F10.4)')
     &              'Nid = ', Nid, A(1), A(2), N, B
        CALL MPI_Barrier(MPI_COMM_WORLD, ierr)
 100  CONTINUE
C
      CALL MPI_Reduce( B, Bsum, 1, MPI_DOUBLE_PRECISION,
     &                  MPI_SUM, 0, MPI_COMM_WORLD, ierr )
C
      IF(Nid.EQ.0) WRITE(*,*) 'Sum of B = ',Bsum
C
      CALL MPI_Finalize(ierr)
C
C-----------------------------------------------------------
      STOP
      END
C***********************************************************
C***************************************************END*****
