      program main
      include 'mpif.h'
      integer n,i,istart,iend
      double precision isum,isum1,time1,time2
      integer nprocs,myrank,ierr,istat(MPI_STATUS_SIZE)
      call mpi_init(ierr)
      call mpi_comm_size(MPI_COMM_WORLD,nprocs,ierr)
      call mpi_comm_rank(MPI_COMM_WORLD,myrank,ierr)
      if (myrank.eq.0) n=10000000
      call mpi_bcast(n,1,MPI_INTEGER,0,MPI_COMM_WORLD,ierr)
      time1=mpi_wtime()
      istart=n*myrank/nprocs+1
      iend=n*(myrank+1)/nprocs
      isum=0.0d0
      do i=istart, iend
         isum=isum+dble(i)
      end do
      call mpi_reduce(isum,isum1,1,MPI_DOUBLE_PRECISION,MPI_SUM,0,
     *                MPI_COMM_WORLD,ierr)
      time2=mpi_wtime()
      if (myrank.eq.0) then
         write(6,*) 'sum =', isum1
         write(6,*) 'time =', time2-time1, '(sec)'
      end if
      call mpi_finalize(ierr)
      stop
      end
