diff --git a/src/vt/vrt/collection/balance/temperedlb/temperedlb.cc b/src/vt/vrt/collection/balance/temperedlb/temperedlb.cc index 3fffd7881c..9b9ea1f721 100644 --- a/src/vt/vrt/collection/balance/temperedlb/temperedlb.cc +++ b/src/vt/vrt/collection/balance/temperedlb/temperedlb.cc @@ -1895,6 +1895,8 @@ void TemperedLB::swapClusters() { auto const this_node = theContext()->getNode(); + // Iddentify and perform beneficial cluster swaps + int n_rank_swaps = 0; for (auto const& [try_rank, try_clusters] : other_rank_clusters_) { bool found_potential_good_swap = false; @@ -1902,28 +1904,32 @@ void TemperedLB::swapClusters() { // proxy_[try_rank].template send<&TemperedLB::tryLock>(this_node, 100); // continue; // } - + + // Iterate over source clusters for (auto const& [src_shared_id, src_cluster] : cur_clusters_) { auto const& [src_cluster_bytes, src_cluster_load] = src_cluster; + // Iterate over target clusters for (auto const& [try_shared_id, try_cluster] : try_clusters) { auto const& [try_cluster_bytes, try_cluster_load] = try_cluster; + // Decide whether swap is beneficial double c_try = criterion( std::make_tuple(src_shared_id, src_cluster_bytes, src_cluster_load), std::make_tuple(try_rank, try_shared_id, try_cluster_bytes, try_cluster_load) ); if (c_try > 0.0) { + // Try to perform swap found_potential_good_swap = true; - // request lock proxy_[try_rank].template send<&TemperedLB::tryLock>(this_node, c_try); + n_rank_swaps; break; } } if (found_potential_good_swap) { break; - } - } - } + } // try_clusters + } // cur_clusters_ + } // other_rank_clusters // We have to be very careful here since we will allow some reentrancy here. constexpr int turn_scheduler_times = 10;