      subroutine cbsu3_2hbnhit_mpi(my_id) ! Bernd Berg Dec 7 2008.
C MPI checkerboard: nhit Cabibbo-Marinari heatbath update attempts
C (accepted or rejected). nhit has to be defined in mc.par.
      include '../../Libs/Fortran/implicit.sta'
      include 'mpif.h'
      include '../../Libs/Fortran/constants.par'
      include '../../Libs/Fortran_par/latmpi.par'
      include '../../Libs/Fortran_par/mc.par'
      parameter(i1=1,i2=2,i3=3)
      include '../../Libs/MPI_par/common_cblat.f'
      include '../../Libs/MPISU3/common_cbsu3.f'
      include '../../Libs/MPISU3/common_2cbsu3.f'
      include '../../Libs/MPI_par/common_mpi.f'
      dimension staple(n18),bstaple(n18), aa(n18)
      ltest=.true.
      ltest=.false.
      if(ltest) then
        write(iud2,'(/,"cbsu3_2mchb_mpi: lbcex =",L2)') lbcex
        write(iud2,'(16x,"act =",G15.6)') act
        if(my_id.eq.0) write(iuo,'(/,"cbsu3_2mchb_mpi:")')
      endif
c
      if(ltest) then ! -------------------------------------------
        if(my_id.eq.0) write(iuo,'(/,"cbsu3_2mchb_mpi: stop ltest.",/)')
        write(iud2,'(/,"cbsu3_2mchb_mpi: stop ltest.",/)')
        close(iud2)
        call mpi_finalize(ierr)
      stop "cbsu3_2mchb_mpi: ltest."
      endif ! ----------------------------------------------------
c
      amin=act
      amax=act
      if(acpt.lt.half) a0prop=zero ! Initialization for acpt=zero.
      iacpt=0
      myp1=my_id+1  ! Process number my_id+1.
      ismpi=my_id+1 ! The same (unify!).
C
      do id=1,nd     ! Loop over links. Update of checkerboard 1:
        do isc=1,msc ! Loop over sites of checkerboard 1.
          ilat0=iba1(isc,id)
          call cbsu3_bstaple1(my_id,ilat0,id,isc,staple,bstaple) ! Bet.
          call su3mult_m_m_m(staple,a1su3(1,isc,id),aa)
          trace=aa(1)+aa(5)+aa(9)
          act=act-trace/three ! Update 1,2 subgroup:
          call su3_b2nhitupdt(nhit,i1,i2,iacpt,a1su3(1,isc,id),bstaple)
          call su3_b2nhitupdt(nhit,i2,i3,iacpt,a1su3(1,isc,id),bstaple)
          call su3_b2nhitupdt(nhit,i3,i1,iacpt,a1su3(1,isc,id),bstaple)
          call su3mult_m_m_m(staple,a1su3(1,isc,id),aa) 
          call su3reunit(a1su3(1,isc,id)) ! Reunitarize link.
          trace=aa(1)+aa(5)+aa(9) ! Add new value to act:
          act=act+trace/three
          amin=min(amin,act)
          amax=max(amax,act)
        end do
        if(lbcex) then ! Gather boundaries:
          call cbsu3_bnd1a_mpi(id,my_id) ! Gather corners:
          if(ndmpi.gt.1) call cbsu3_bnd1b_mpi(id,my_id) 
        endif
      end do
C
      do id=1,nd     ! Loop over links. Update of checkerboard 2:
        if(ltest) write(iud2,'("2. id =",2I6)') id,msc
        do isc=1,msc ! Loop over sites of checkerboard 2.
          ilat0=iba2(isc,id)
          call cbsu3_bstaple2(my_id,ilat0,id,isc,staple,bstaple) ! Get.
          call su3mult_m_m_m(staple,a2su3(1,isc,id),aa)
          trace=aa(1)+aa(5)+aa(9)
          act=act-trace/three ! Update 1,2 subgroup:
          call su3_b2nhitupdt(nhit,i1,i2,iacpt,a2su3(1,isc,id),bstaple)
          call su3_b2nhitupdt(nhit,i2,i3,iacpt,a2su3(1,isc,id),bstaple)
          call su3_b2nhitupdt(nhit,i3,i1,iacpt,a2su3(1,isc,id),bstaple)
          call su3mult_m_m_m(staple,a2su3(1,isc,id),aa) 
          call su3reunit(a2su3(1,isc,id)) ! Reunitarize link.
          trace=aa(1)+aa(5)+aa(9) ! Add new value to act:
          act=act+trace/three
          amin=min(amin,act)
          amax=max(amax,act)
        end do
        if(lbcex) then ! Gather boundaries:
          call cbsu3_bnd2a_mpi(id,my_id) ! Gather corners:
          if(ndmpi.gt.1) call cbsu3_bnd2b_mpi(id,my_id) 
        endif
      end do
      acpt=acpt+iacpt          ! Accepted updates.
      a0prop=a0prop+2*3*nd*msc ! Number of proposals.
      a_min=min(a_min,amin)
      a_max=max(a_max,amax)
c
      return
      end
