Skip to content

Commit e87cb25

Browse files
authored
Merge pull request #4982 from xinzhao3/topic/shmem-final
ompi/oshmem: fix bug in shmem_finalize.
2 parents 0e6966f + 4aad386 commit e87cb25

File tree

2 files changed

+9
-16
lines changed

2 files changed

+9
-16
lines changed

oshmem/runtime/oshmem_shmem_finalize.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,30 +58,29 @@
5858
#include "oshmem/shmem/shmem_lock.h"
5959
#include "oshmem/runtime/oshmem_shmem_preconnect.h"
6060

61+
extern int oshmem_shmem_globalexit_status;
62+
6163
static int _shmem_finalize(void);
6264

6365
int oshmem_shmem_finalize(void)
6466
{
6567
int ret = OSHMEM_SUCCESS;
66-
static int32_t finalize_has_already_started = 0;
67-
int32_t _tmp = 0;
6868

69-
if (opal_atomic_compare_exchange_strong_32 (&finalize_has_already_started, &_tmp, 1)
70-
&& oshmem_shmem_initialized && !oshmem_shmem_aborted) {
69+
if (oshmem_shmem_initialized && !oshmem_shmem_aborted) {
7170
/* Should be called first because ompi_mpi_finalize makes orte and opal finalization */
7271
ret = _shmem_finalize();
7372

74-
if ((OSHMEM_SUCCESS == ret) && ompi_mpi_initialized
75-
&& !ompi_mpi_finalized) {
76-
PMPI_Comm_free(&oshmem_comm_world);
77-
ret = ompi_mpi_finalize();
78-
}
79-
8073
if (OSHMEM_SUCCESS == ret) {
8174
oshmem_shmem_initialized = false;
8275
}
8376
}
8477

78+
if ((OSHMEM_SUCCESS == ret) && ompi_mpi_initialized
79+
&& !ompi_mpi_finalized && oshmem_shmem_globalexit_status == 0) {
80+
PMPI_Comm_free(&oshmem_comm_world);
81+
ret = ompi_mpi_finalize();
82+
}
83+
8584
return ret;
8685
}
8786

oshmem/shmem/c/shmem_finalize.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,9 @@
2222
#include "oshmem/shmem/c/profile/defines.h"
2323
#endif
2424

25-
extern int oshmem_shmem_globalexit_status;
26-
2725
void shmem_finalize(void)
2826
{
2927
OPAL_CR_FINALIZE_LIBRARY();
30-
if (oshmem_shmem_globalexit_status != 0)
31-
{
32-
return;
33-
}
3428
oshmem_shmem_finalize();
3529
}
3630

0 commit comments

Comments
 (0)