!-------------------------------------------------------
! Multiple Program Multiple Data Test Program
!   Test2 : Rank1 - nprocs-1 (Recv->Send data)
!-------------------------------------------------------
      program teat2
      use mpi
c
      integer ierr,nprocs,myrank,icolor,key
      integer nprocs2,myrank2
      integer STATUS(MPI_STATUS_SIZE)
      integer i,n,n2
      real(8),allocatable :: c(:)
c
      call MPI_Init(ierr)
      call MPI_Comm_Size(MPI_COMM_WORLD,nprocs,ierr)
      call MPI_Comm_Rank(MPI_COMM_WORLD,myrank,ierr)
      n = 8192
      n2= n/(nprocs-1)
c
      if(myrank.eq.0) then
        icolor = 0
        key = 0
      else
        do i = 1,nprocs-1
          icolor = 1
          key = i - 1
        enddo
      endif
      call MPI_Comm_Split(MPI_COMM_WORLD,icolor,key,MPI_COMM2,ierr)
      call MPI_Comm_Size(MPI_COMM2,nprocs2,ierr)
      call MPI_Comm_Rank(MPI_COMM2,myrank2,ierr)
c
      if(myrank.ne.0) then
        allocate(c(n2))
        call MPI_Recv(c,n2,MPI_REAL8,0,1,
     +                MPI_COMM_WORLD,STATUS,ierr)
        do i = 1,n2
          c(i) = c(i)*2.0d0
        enddo
        call MPI_Send(c,n2,MPI_REAL8,0,2,
     +                  MPI_COMM_WORLD,ierr)
        deallocate(c)
      endif
c
      call MPI_Finalize(ierr)
      stop
      end
