Skip to content

Commit b79004e

Browse files
committed
Correctly handle attributes on MPI_COMM_WORLD.
During MPI_Finalize delete all predefined attributes from MPI_COMM_WORLD, before deleting the attributes placeholder. Note that user-defined attributes that were still attached to MPI_COMM_WORLD will leak. Fixes #12035. Signed-off-by: George Bosilca <bosilca@icl.utk.edu>
1 parent 1967454 commit b79004e

File tree

3 files changed

+28
-12
lines changed

3 files changed

+28
-12
lines changed

ompi/attribute/attribute.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
* reserved.
1818
* Copyright (c) 2022 Amazon.com, Inc. or its affiliates.
1919
* All Rights reserved.
20+
* Copyright (c) 2023 NVIDIA Corporation. All rights reserved.
2021
* $COPYRIGHT$
2122
*
2223
* Additional copyrights may follow
@@ -526,11 +527,12 @@ int ompi_attr_create_predefined_keyvals(void);
526527
/**
527528
* \internal
528529
*
529-
* Cache predefined attribute keys used in the World Model
530+
* Cache and release the predefined attribute keys used in the World Model
530531
*
531532
* @returns OMPI_SUCCESS
532533
*/
533534
int ompi_attr_set_predefined_keyvals_for_wm(void);
535+
void ompi_attr_delete_predefined_keyvals_for_wm(void);
534536

535537
/**
536538
* \internal

ompi/attribute/attribute_predefined.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
* All Rights reserved.
1919
* Copyright (c) 2022 Triad National Security, LLC. All rights
2020
* reserved.
21+
* Copyright (c) 2023 NVIDIA Corporation. All rights reserved.
2122
* $COPYRIGHT$
2223
*
2324
* Additional copyrights may follow
@@ -109,6 +110,7 @@ static int create_win(int target_keyval);
109110
static int free_win(int keyval);
110111

111112
static int set_f(int keyval, MPI_Fint value);
113+
static int unset_f(int keyval);
112114

113115
/*
114116
* We do not need a lock here as this function is invoked when the
@@ -188,6 +190,17 @@ int ompi_attr_set_predefined_keyvals_for_wm(void)
188190
return ret;
189191
}
190192

193+
void ompi_attr_delete_predefined_keyvals_for_wm(void)
194+
{
195+
unset_f(MPI_TAG_UB);
196+
unset_f(MPI_HOST);
197+
unset_f(MPI_IO);
198+
unset_f(MPI_WTIME_IS_GLOBAL);
199+
unset_f(MPI_FT);
200+
unset_f(MPI_LASTUSEDCODE);
201+
unset_f(MPI_UNIVERSE_SIZE);
202+
unset_f(MPI_APPNUM);
203+
}
191204

192205
/*
193206
* We do not need a lock here as this function is invoked when the
@@ -292,3 +305,10 @@ static int set_f(int keyval, MPI_Fint value)
292305
keyval, value,
293306
true);
294307
}
308+
309+
static int unset_f(int keyval)
310+
{
311+
return ompi_attr_delete(COMM_ATTR, MPI_COMM_WORLD,
312+
MPI_COMM_WORLD->c_keyhash,
313+
keyval, true);
314+
}

ompi/communicator/comm_init.c

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
* Copyright (c) 2018-2022 Triad National Security, LLC. All rights
2727
* reserved.
2828
* Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved.
29+
* Copyright (c) 2023 NVIDIA Corporation. All rights reserved.
2930
* $COPYRIGHT$
3031
*
3132
* Additional copyrights may follow
@@ -311,18 +312,11 @@ static int ompi_comm_finalize (void)
311312

312313
if (ompi_comm_intrinsic_init) {
313314
/* tear down MPI-3 predefined communicators (not initialized unless using MPI_Init) */
314-
/* Free the attributes on comm world. This is not done in the
315-
* destructor as we delete attributes in ompi_comm_free (which
316-
* is not called for comm world) */
317-
if (NULL != ompi_mpi_comm_world.comm.c_keyhash) {
318-
/* Ignore errors when deleting attributes on comm_world */
319-
(void) ompi_attr_delete_all(COMM_ATTR, &ompi_mpi_comm_world.comm, ompi_mpi_comm_world.comm.c_keyhash);
320-
OBJ_RELEASE(ompi_mpi_comm_world.comm.c_keyhash);
321-
}
322-
323-
/* Shut down MPI_COMM_SELF */
324315
OBJ_DESTRUCT( &ompi_mpi_comm_self );
325-
/* Shut down MPI_COMM_WORLD */
316+
ompi_attr_delete_predefined_keyvals_for_wm();
317+
/* Destroy the keyhash even is user defined attributes are still attached. */
318+
OBJ_DESTRUCT(ompi_mpi_comm_world.comm.c_keyhash);
319+
ompi_mpi_comm_world.comm.c_keyhash = NULL;
326320
OBJ_DESTRUCT( &ompi_mpi_comm_world );
327321

328322
ompi_comm_intrinsic_init = false;

0 commit comments

Comments
 (0)