subroutine fm_calc_sc_heads(self)
use mp, only: iproc, sum_allreduce
implicit none
class(fieldmat_type), intent(inout) :: self
integer :: ik, is, ic, it
!AJ There may be a problem here is any supercell has no assigned head.
!AJ This is the case (I think) for 1,1; but it shouldn't actually cause
!AJ a problem as 1,1 shouldn't be communicated anyway as only one process
!AJ is involved in it.
self%heads = 0
do ik=1,self%naky
do is=1,self%kyb(ik)%nsupercell
if(self%kyb(ik)%supercells(is)%is_head) then
do ic=1,self%kyb(ik)%supercells(is)%ncell
it = self%kyb(ik)%supercells(is)%cells(ic)%it_ind
self%heads(it,ik) = iproc
end do
end if
end do
end do
call sum_allreduce(self%heads)
end subroutine fm_calc_sc_heads