Skip to content

Commit 56e778a

Browse files
committed
hcoll: Reorder checks for early return in initialization
Check for communicators that do not meet the criteria for hcoll setup before initializing the hcoll library. This prevents crashes due to e.g. MPI_COMM_SELF being created during business card exchange before communication is ready.
1 parent a7ed346 commit 56e778a

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

src/mpid/common/hcoll/hcoll_init.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -132,27 +132,28 @@ int hcoll_comm_create(MPIR_Comm * comm_ptr, void *param)
132132

133133
comm_ptr->hcoll_priv.is_hcoll_init = 0;
134134

135-
if (0 == hcoll_initialized) {
136-
mpi_errno = hcoll_initialize();
137-
MPIR_ERR_CHECK(mpi_errno);
135+
if (0 == hcoll_enable) {
136+
goto fn_exit;
138137
}
139138

140-
if (0 == hcoll_enable) {
139+
num_ranks = comm_ptr->local_size;
140+
if ((MPIR_COMM_KIND__INTRACOMM != comm_ptr->comm_kind) || (2 > num_ranks)
141+
|| comm_ptr->hierarchy_kind == MPIR_COMM_HIERARCHY_KIND__NODE_ROOTS
142+
|| comm_ptr->hierarchy_kind == MPIR_COMM_HIERARCHY_KIND__NODE) {
141143
goto fn_exit;
142144
}
143145

146+
if (0 == hcoll_initialized) {
147+
mpi_errno = hcoll_initialize();
148+
MPIR_ERR_CHECK(mpi_errno);
149+
}
150+
144151
if (MPIR_Process.comm_world == comm_ptr) {
145152
hcoll_comm_world_initialized = 1;
146153
}
147154
if (!hcoll_comm_world_initialized) {
148155
goto fn_exit;
149156
}
150-
num_ranks = comm_ptr->local_size;
151-
if ((MPIR_COMM_KIND__INTRACOMM != comm_ptr->comm_kind) || (2 > num_ranks)
152-
|| comm_ptr->hierarchy_kind == MPIR_COMM_HIERARCHY_KIND__NODE_ROOTS
153-
|| comm_ptr->hierarchy_kind == MPIR_COMM_HIERARCHY_KIND__NODE) {
154-
goto fn_exit;
155-
}
156157

157158
comm_ptr->hcoll_priv.hcoll_context = hcoll_create_context((rte_grp_handle_t) comm_ptr);
158159
if (NULL == comm_ptr->hcoll_priv.hcoll_context) {

0 commit comments

Comments
 (0)