From 7addc83ae997b397f932e2646c0a7b290204dd02 Mon Sep 17 00:00:00 2001 From: David Wootton Date: Tue, 22 Nov 2022 15:28:10 -0500 Subject: [PATCH] Fix divide by zero error in calculate_num_nodes_up_to_level with MPI_Bcast in 2 tasks using --mca coll_adapt_bcast_algorithm 6 and --mca coll_adapt_priority 99 Resolve review comments Signed-off-by: David Wootton (cherry picked from commit a74927fc72294ef75c4c192a98ac95d170b98b60) --- ompi/mca/coll/adapt/coll_adapt_topocache.c | 2 +- ompi/mca/coll/base/coll_base_topo.c | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/ompi/mca/coll/adapt/coll_adapt_topocache.c b/ompi/mca/coll/adapt/coll_adapt_topocache.c index b549d89144c..e114456d12c 100644 --- a/ompi/mca/coll/adapt/coll_adapt_topocache.c +++ b/ompi/mca/coll/adapt/coll_adapt_topocache.c @@ -59,7 +59,7 @@ static ompi_coll_tree_t *create_topology( { int fanout = ompi_comm_size(comm) - 1; ompi_coll_tree_t *tree; - if (fanout < 1) { + if (fanout <= 1) { tree = ompi_coll_base_topo_build_chain(1, comm, root); } else if (fanout <= MAXTREEFANOUT) { tree = ompi_coll_base_topo_build_tree(ompi_comm_size(comm) - 1, comm, root); diff --git a/ompi/mca/coll/base/coll_base_topo.c b/ompi/mca/coll/base/coll_base_topo.c index 9fcc22fd09f..d3a1f11eab5 100644 --- a/ompi/mca/coll/base/coll_base_topo.c +++ b/ompi/mca/coll/base/coll_base_topo.c @@ -59,7 +59,12 @@ static int calculate_num_nodes_up_to_level( int fanout, int level ) { /* just use geometric progression formula for sum: a^0+a^1+...a^(n-1) = (a^n-1)/(a-1) */ - return ((pown(fanout,level) - 1)/(fanout - 1)); + if (1 == fanout) { + return level; + } + else { + return ((pown(fanout,level) - 1)/(fanout - 1)); + } } /*