assign_elements_on_procs Subroutine

public subroutine assign_elements_on_procs(list_length, min_elem, max_elem, num_elem)

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: list_length
integer, intent(out) :: min_elem
integer, intent(out) :: max_elem
integer, intent(out) :: num_elem

Contents


Source Code

    subroutine assign_elements_on_procs(list_length, min_elem, max_elem, num_elem)

        ! Split list_length into nProcessor parts. Note that this is not done based on any hash.

        integer, intent(in) :: list_length
        integer, intent(out) :: min_elem, max_elem, num_elem
        integer :: floor_div_list_length, mod_list_length
        integer :: num_elem_all_procs(0:nProcessors - 1)
        integer :: i

        mod_list_length = mod(list_length, nProcessors)
        floor_div_list_length = (list_length - mod_list_length) / nProcessors

        do i = 0, nProcessors - 1
            num_elem_all_procs(i) = floor_div_list_length
            if (i < mod_list_length) num_elem_all_procs(i) = num_elem_all_procs(i) + 1
        end do

        num_elem = num_elem_all_procs(iProcIndex)

        if (num_elem == 0) then
            if (iProcIndex == 0) call stop_all("assign_elements_on_procs", "There are no states &
                                               &in the trial space.")
            min_elem = 0
            max_elem = 0
            return
        end if

        if (iProcIndex == 0) then
            min_elem = 1
            max_elem = num_elem
        else
            min_elem = 0
            do i = 0, iProcIndex - 1
                min_elem = min_elem + num_elem_all_procs(i)
            end do
            max_elem = min_elem + num_elem_all_procs(iProcIndex)
            min_elem = min_elem + 1
        end if

    end subroutine assign_elements_on_procs