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~3~~CalledByGraph proc~most_popular~3 most_popular proc~mg_load_balance_parents~3 mg_load_balance_parents proc~mg_load_balance_parents~3->proc~most_popular~3 proc~mg_load_balance~3 mg_load_balance proc~mg_load_balance~3->proc~most_popular~3 proc~mg_tree_from_amrvac mg_tree_from_amrvac proc~mg_tree_from_amrvac->proc~mg_load_balance_parents~3 proc~mg_setup_multigrid mg_setup_multigrid proc~mg_setup_multigrid->proc~mg_tree_from_amrvac proc~mg_update_refinement mg_update_refinement proc~mg_update_refinement->proc~mg_tree_from_amrvac proc~amr_coarsen_refine amr_coarsen_refine proc~amr_coarsen_refine->proc~mg_update_refinement proc~improve_initial_condition improve_initial_condition proc~improve_initial_condition->proc~mg_setup_multigrid proc~main main proc~main->proc~mg_setup_multigrid proc~main->proc~improve_initial_condition proc~resettree_convert resettree_convert proc~main->proc~resettree_convert proc~settree settree proc~main->proc~settree proc~timeintegration timeintegration proc~main->proc~timeintegration proc~resettree resettree proc~resettree->proc~amr_coarsen_refine proc~resettree_convert->proc~amr_coarsen_refine proc~settree->proc~amr_coarsen_refine program~agile agile program~agile->proc~main proc~timeintegration->proc~resettree

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