subroutine DomainDecomp(nElems,nDomains,offSetElem)
! From https://www.hopr-project.org/externals/Meshformat.pdf, Algorithm 4
implicit none
integer,intent(in) :: nElems
integer,intent(in) :: nDomains
integer,intent(out) :: offsetElem(0:nDomains)
! Local
integer :: nLocalElems
integer :: remainElems
integer :: iDom
nLocalElems = nElems/nDomains
remainElems = nElems-nLocalElems*nDomains
do iDom = 0,nDomains-1
offSetElem(iDom) = iDom*nLocalElems+min(iDom,remainElems)
enddo
offSetElem(nDomains) = nElems
endsubroutine DomainDecomp