      program teatb
      use mpi
c
      integer ierr,nprocs,myrank,icolor,key
      integer nprocs2,myrank2
      integer ist,ied,sum,i,sum2
      integer,parameter :: N=10000

      call MPI_Init(ierr)
      call MPI_Comm_Size(MPI_COMM_WORLD,nprocs,ierr)
      call MPI_Comm_Rank(MPI_COMM_WORLD,myrank,ierr)
c
      if(myrank.eq.0) then
        icolor = 0
        key = 0
      else if(myrank.eq.1) then
        icolor = 0
        key = 1
      else if(myrank.eq.2) then
        icolor = 1
        key = 0
      else if(myrank.eq.3) then
        icolor = 1
        key = 1
      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
      sum=0
      ist=10000+((n-1)/nprocs2+1)*myrank2+1
      ied=10000+((n-1)/nprocs2+1)*(myrank2+1)
!$OMP parallel do reduction(+:sum)
      do i=ist,ied
        sum=sum+i
      enddo
!$OMP end parallel do
      call MPI_Reduce(sum,sum2,1,MPI_INTEGER,MPI_SUM,0,
     + MPI_COMM2,ierr)
      if(myrank2.eq.0) then
        write(6,*) "Sum=",sum2
        itag=1
        call MPI_Send(sum2,1,MPI_INTEGER,0,itag,
     +       MPI_COMM_WORLD,ierr)
      endif
      call MPI_Finalize(ierr)
      stop
      end 
