      program gather
c
      include 'mpif.h'
      integer ierr,myrank,nsize
      integer a(100), b
c
      call mpi_init(ierr)
      call mpi_comm_size(MPI_COMM_WORLD,nsize,ierr)
      call mpi_comm_rank(MPI_COMM_WORLD,myrank,ierr)
c
      b=(myrank +1) **2

      call mpi_gather(b,1,MPI_INTEGER,
     &            a(myrank+1),1,MPI_INTEGER,0,MPI_COMM_WORLD,ierr)
c
 100  format(a3,i3,a4,i4)
c
      do 20 i=1,nsize
         if(myrank.EQ.0)then
            write(*,100)'a(',i,') =',a(i)
         end if 
 20   continue
c
      call mpi_finalize(ierr)
      stop
      end
c
c
ccc  Result
c
c % mpirun -np 8 ./a.out
c a(  1 ) =   1
c a(  2 ) =   4
c a(  3 ) =   9
c a(  4 ) =  16
c a(  5 ) =  25
c a(  6 ) =  36
c a(  7 ) =  49
c a(  8 ) =  64
