subroutine nubeam_mpi_timer(zcptim_start)

  !  get cpu timing statistics, with mpi_reduce 
  !  to set cpbmin and cpbmax on the root (myidd.eq.0) process

  use nbi_mpi_com
  use nbi_com
  implicit none

  real(fp), intent(in) :: zcptim_start   ! cpu time at start of timed interval

  !------------------------------------
  ! local:

  real(fp) :: zcptim_end,zcptim
  integer :: mpierr
  !------------------------------------


#ifndef __MPI
      integer myid_debug, numproc_debug
      if(debug_mpi.and.nltest_output) then
         myid_debug=myidd
         numproc_debug=numprocd
      endif
#endif

      call nbi_mpi_com_init

#ifndef __MPI
      if(debug_mpi.and.nltest_output) then
         myidd=myid_debug       ! do not redefine  myidd and nuprocd for 
         numprocd=numproc_debug ! debugging of mpi version by serial code 
      endif
#endif

  call cpu_time(zcptim_end)
  zcptim = zcptim_end - zcptim_start
 
  cpbroot = 0.0
  cpbmin = 0.0
  cpbmax = 0.0

  if(myidd.eq.0) then
     cpbroot = zcptim
  endif

#ifdef __MPI
  mpierr=0
  cpbmin=0.0d0
  cpbmax=0.0d0

  call mpi_reduce(zcptim,cpbmin,1,MPI_REAL8,MPI_MIN,0,nbi_comm,mpierr)
  if(mpierr.ne.0) &
       call errmsg_exit('mpi error at nubeam_mpi_timer mpi_reduce(cpbmin)')

  call mpi_reduce(zcptim,cpbmax,1,MPI_REAL8,MPI_MAX,0,nbi_comm,mpierr)
  if(mpierr.ne.0) &
       call errmsg_exit('mpi error at nubeam_mpi_timer mpi_reduce(cpbmax)')
  
#else
  cpbmin = cpbroot
  cpbmax = cpbroot
#endif

end subroutine nubeam_mpi_timer
