Determine most popular rank in the list. In case of ties, assign the rank with the least work.
| Type | Intent | Optional | 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 |
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