      program example65b
      include 'mpif.h'
      parameter (n = 1000000000)
      integer i, rank, size, ierr
      double precision w, x, sum, locpi, pi, f, y, t1, t2
      f(y) = 4.d0/(1.d0+y*y)
      call MPI_INIT(ierr)
      call MPI_COMM_RANK(MPI_COMM_WORLD, rank, ierr)
      call MPI_COMM_SIZE(MPI_COMM_WORLD, size, ierr)
      call MPI_BARRIER(MPI_COMM_WORLD, ierr)
      t1=MPI_WTIME(ierr)
      w = 1.0d0/n
      sum = 0.0d0;
      do i=rank+1, n, size
         x = w*(i-0.5d0)
         sum = sum + f(x)
      end do
      locpi = w*sum
      call MPI_Reduce(locpi, pi, 1, MPI_DOUBLE_PRECISION,
     &                MPI_SUM, 0, MPI_COMM_WORLD, ierr);
      call MPI_BARRIER(MPI_COMM_WORLD, ierr)
      t2=MPI_WTIME(ierr)
      if(rank .eq.0) print *, "N=", n, ", Nproc=", size,
     &                        "pi = ", pi, " Time=", t2-t1
      call MPI_FINALIZE(ierr)
      end
