most_popular Function

private pure function most_popular(list, work, n_cpu)

Determine most popular rank in the list. In case of ties, assign the rank with the least work.

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: list(:)

List of MPI ranks

integer, intent(in) :: work(0:n_cpu-1)

Existing work per rank

integer, intent(in) :: n_cpu

Return Value integer


Called by

proc~~most_popular~~CalledByGraph proc~most_popular most_popular proc~mg_load_balance mg_load_balance proc~mg_load_balance->proc~most_popular proc~mg_load_balance_parents mg_load_balance_parents proc~mg_load_balance_parents->proc~most_popular

Source Code

  pure integer function most_popular(list, work, n_cpu)
    integer, intent(in) :: list(:)
    !< List of MPI ranks
    integer, intent(in) :: n_cpu
    integer, intent(in) :: work(0:n_cpu-1)
    !< Existing work per rank
    integer             :: i, best_count, current_count
    integer             :: my_work, best_work

    best_count   = 0
    best_work    = 0
    most_popular = -1

    do i = 1, size(list)
       current_count = count(list == list(i))
       my_work       = work(list(i))

       ! In case of ties, select task with lowest work
       if (current_count > best_count .or. current_count == best_count .and. &
          my_work < best_work) then
          best_count   = current_count
          best_work    = my_work
          most_popular = list(i)
       end if
    end do

  end function most_popular