! A coupler model subroutine for Multi-Process Handshaking utility
! to facilitate a plug & play style programming using single executable.
! Written by Yun (Helen) He and Chris Ding, NERSC/LBNL, December 2000.


      subroutine cpl5_1 (CPL_World)

      use MPH_all
      implicit none

      integer CPL_World, myProc, myProc_global
      integer local_sum, global_sum

      call MPI_COMM_RANK (MPI_COMM_WORLD, myProc_global, ierr)
      call MPI_COMM_RANK (CPL_World, myProc, ierr)
      if (myProc==0) call MPH_redirect_output ('cpl')
      write(*,*) myProc, ' in cpl === ', myProc_global, ' in global'
      write(*,*) 'MPH_global_proc_id()=', MPH_global_proc_id() 
      write(*,*)'my comp_id=', MPH_get_component_id("coupler")


!------ Do MPI operations in local world -------

      call MPI_REDUCE (myProc, local_sum, 1, MPI_INTEGER, 
     &                 MPI_SUM, 0, CPL_World, ierr)
      call MPI_REDUCE (myProc_global, global_sum, 1, 
     &                 MPI_INTEGER, MPI_SUM, 0, CPL_World, ierr)
      if (myProc == 0) then
         write(*,*)' sum of local ranks in cpl is ', local_sum
         write(*,*)' sum of global ranks in cpl is ', global_sum
      endif

      end subroutine
