Line data Source code
1 : module m_divide_most_evenly 2 : use m_judft 3 : contains 4 148 : subroutine divide_most_evenly(n_total, n_parts, start_idx, psize) 5 : implicit none 6 : integer, intent(in) :: n_total, n_parts 7 : integer, allocatable, intent(inout) :: start_idx(:), psize(:) 8 : 9 : integer :: i, big_size, small_size, end_idx 10 : 11 148 : if(allocated(start_idx)) deallocate(start_idx) 12 148 : if(allocated(psize)) deallocate(psize) 13 592 : allocate(start_idx(n_parts), psize(n_parts)) 14 : 15 148 : if(n_parts == 0) call judft_error("You need more than 0 parts") 16 148 : if(n_parts > n_total) call judft_error("You can't have more n_parts, than n_total") 17 : 18 148 : small_size = floor((1.0*n_total)/n_parts) 19 148 : big_size = small_size +1 20 : 21 148 : end_idx = 0 22 296 : do i = 1,n_parts 23 148 : psize(i) = merge(big_size, small_size,i <= mod(n_total, n_parts)) 24 148 : if(psize(i) == 0) then 25 0 : write (*,*) "n_total, n_parts", n_total, n_parts 26 0 : call judft_warn("some band_packs have 0 bands") 27 : endif 28 148 : start_idx(i) = end_idx + 1 29 296 : end_idx = start_idx(i) + psize(i) - 1 30 : enddo 31 148 : end subroutine divide_most_evenly 32 : end module m_divide_most_evenly