program sum
      include 'mpif.h'
 
      integer i, n, noprocs, nid, error
      real  sum, Gsum

      call MPI_Init(error)
      call MPI_Comm_rank(MPI_COMM_WORLD, nid, error)
      call MPI_Comm_size(MPI_COMM_WORLD, noprocs, error)
 
      if (nid .eq. 0) then
         write(6,*)'Please enter the number of terms N:'
         read(5,*)n
      end if
      call MPI_Bcast(n,1,MPI_INTEGER,0,MPI_COMM_WORLD,error)
      sum = 0.0
      do 10 i = nid, n-1, noprocs
         if (mod(i,2) .ne. 0) then
            sum = sum - 1.0 / (i + 1)
         else
            sum = sum + 1.0 / (i + 1)
         end if
   10 continue
      call MPI_Reduce(sum,Gsum,1,MPI_REAL,MPI_SUM,0,MPI_COMM_WORLD,
     &   error)
      if (nid .eq. 0) then
         write(6,*)'An estimate of ln(2) is',Gsum
      end if
      call MPI_Finalize(error)

      stop
      end