Skip to content

Commit 4414cf6

Browse files
authored
Merge pull request #11103 from drwootton/mpi_bcast_zerodivide
Fix divide by zero error in calculate_num_nodes_up_to_level using MPI_Bcast with 2 tasks
2 parents df4235a + a74927f commit 4414cf6

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

ompi/mca/coll/adapt/coll_adapt_topocache.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ static ompi_coll_tree_t *create_topology(
5959
{
6060
int fanout = ompi_comm_size(comm) - 1;
6161
ompi_coll_tree_t *tree;
62-
if (fanout < 1) {
62+
if (fanout <= 1) {
6363
tree = ompi_coll_base_topo_build_chain(1, comm, root);
6464
} else if (fanout <= MAXTREEFANOUT) {
6565
tree = ompi_coll_base_topo_build_tree(ompi_comm_size(comm) - 1, comm, root);

ompi/mca/coll/base/coll_base_topo.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,12 @@ static int calculate_num_nodes_up_to_level( int fanout, int level )
5959
{
6060
/* just use geometric progression formula for sum:
6161
a^0+a^1+...a^(n-1) = (a^n-1)/(a-1) */
62-
return ((pown(fanout,level) - 1)/(fanout - 1));
62+
if (1 == fanout) {
63+
return level;
64+
}
65+
else {
66+
return ((pown(fanout,level) - 1)/(fanout - 1));
67+
}
6368
}
6469

6570
/*

0 commit comments

Comments
 (0)