From f34825dff95daea6b217363becce2f2dd19291c3 Mon Sep 17 00:00:00 2001 From: Peter Munch Date: Mon, 21 Jun 2021 16:37:23 +0200 Subject: [PATCH] Fix MinimalGranularityPolicy --- source/distributed/repartitioning_policy_tools.cc | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/source/distributed/repartitioning_policy_tools.cc b/source/distributed/repartitioning_policy_tools.cc index d13b788d90..a7e35036f4 100644 --- a/source/distributed/repartitioning_policy_tools.cc +++ b/source/distributed/repartitioning_policy_tools.cc @@ -208,10 +208,17 @@ namespace RepartitioningPolicyTools // the same number of cells; if there is a remainder, we assign the // first processes an additional cell (so that the difference of number of // locally owned cells is never larger than one between processes). - if (i < (i / min_cells) * min_cells + (n_global_active_cells % min_cells)) - return i / (min_cells + 1); - else - return (i - (n_global_active_cells % min_cells)) / min_cells; + const unsigned int n_partitions_with_additional_cell = + n_global_active_cells - min_cells * n_partitions; + + const unsigned int rank = + (i < (min_cells + 1) * n_partitions_with_additional_cell) ? + (i / (min_cells + 1)) : + ((i - n_partitions_with_additional_cell) / min_cells); + + AssertIndexRange(rank, n_partitions); + + return rank; }; for (const auto i : partition.locally_owned_elements()) -- 2.39.5