      program main
      include 'mpif.h'
      integer n,i,istart,iend,isum,isum1
      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=10000
      call mpi_bcast(n,1,MPI_INTEGER,0,MPI_COMM_WORLD,ierr)
      istart=n*myrank/nprocs+1
      iend=n*(myrank+1)/nprocs
      isum=0
      do i=istart, iend
         isum=isum+i
      end do
      call mpi_reduce(isum,isum1,1,MPI_INTEGER,MPI_SUM,0,
     *                MPI_COMM_WORLD,ierr)
      if (myrank.eq.0) write(6,*) 'sum =', isum1
      call mpi_finalize(ierr)
      stop
      end
