      program example2
      include 'mpif.h'
      integer ierr,myrank,nprocs,ist,ied
      parameter(n=1000)
      integer sum
      call MPI_INIT(ierr)
      call MPI_COMM_SIZE(MPI_COMM_WORLD,nprocs,ierr)
      call MPI_COMM_RANK(MPI_COMM_WORLD,myrank,ierr)
      ist=((n-1)/nprocs+1)*myrank+1
      ied=((n-1)/nprocs+1)*(myrank+1)
      sum=0
      do i=ist,ied
        sum=sum+i
      enddo
      write(6,6000) myrank,sum
 6000 format("Total of Rank:",i2,i10)
      call MPI_FINALIZE(ierr)
      stop
      end
