Reduction operation

 

PROGRAM REDUCE
      INCLUDE 'mpif.h'
      INTEGER imsg(4)
      REAL a(9)

      CALL MPI_INIT(IERR)
      CALL MPI_COMM_SIZE(MPI_COMM_WORLD, mprocs, ierr)
      CALL MPI_COMM_RANK(mpi_COMM_WORLD, myrank, ierr)

      ista = myrank *3 +1
      iend = ista +2
      DO i=ista,iend
         a(i) = i
      ENDDO
      sum = 0.0
      DO i = ista,iend
         sum = sum + a(i)
      ENDDO
      CALL MPI_REDUCE(*********************************)
      sum = tmp
      IF(myrank = = 0) THEN
        print*, 'sum =', sum
      ENDIF


      CALL MPI_FINALIZE(ierr)

      END