Commit 1182a62a authored by Xin Zhao's avatar Xin Zhao Committed by Pavan Balaji
Browse files

fix bug of zero-byte shared window allocation.



In MPIDI_CH3I_Win_allocate_shared, if the size of shared memory
segment is 0, we just set window's base to NULL, do not allocate
shared memory segment and mutex memory region.

In MPIDI_CH3I_SHM_Win_free, we detach the shared memory segment
and mutex memory region only when the size of shared memory segment
is not 0.
Signed-off-by: Pavan Balaji's avatarPavan Balaji <balaji@mcs.anl.gov>
parent 1ffd39ba
......@@ -68,16 +68,19 @@ int MPIDI_CH3_SHM_Win_free(MPID_Win **win_ptr)
if ((*win_ptr)->shm_allocated) {
/* free shm_base_addrs that's only used for shared memory windows */
MPIU_Free((*win_ptr)->shm_base_addrs);
/* detach from shared memory segment */
mpi_errno = MPIU_SHMW_Seg_detach((*win_ptr)->shm_segment_handle, (char **)&(*win_ptr)->shm_base_addr,
if ((*win_ptr)->shm_segment_len > 0) {
/* detach from shared memory segment */
mpi_errno = MPIU_SHMW_Seg_detach((*win_ptr)->shm_segment_handle, (char **)&(*win_ptr)->shm_base_addr,
(*win_ptr)->shm_segment_len);
if (mpi_errno) MPIU_ERR_POP(mpi_errno);
if (mpi_errno) MPIU_ERR_POP(mpi_errno);
MPIU_SHMW_Hnd_finalize(&(*win_ptr)->shm_segment_handle);
MPIU_SHMW_Hnd_finalize(&(*win_ptr)->shm_segment_handle);
}
}
/* Free shared process mutex memory region */
if ((*win_ptr)->shm_mutex) {
if ((*win_ptr)->shm_mutex && (*win_ptr)->shm_segment_len > 0) {
if ((*win_ptr)->comm_ptr->rank == 0) {
MPIDI_CH3I_SHM_MUTEX_DESTROY(*win_ptr);
......
......@@ -133,6 +133,11 @@ static int MPIDI_CH3I_Win_allocate_shared(MPI_Aint size, int disp_unit, MPID_Inf
(*win_ptr)->shm_segment_len += (*win_ptr)->sizes[i];
}
if ((*win_ptr)->shm_segment_len == 0) {
(*win_ptr)->base = NULL;
}
else {
mpi_errno = MPIU_SHMW_Hnd_init(&(*win_ptr)->shm_segment_handle);
if (mpi_errno) MPIU_ERR_POP(mpi_errno);
......@@ -252,6 +257,7 @@ static int MPIDI_CH3I_Win_allocate_shared(MPI_Aint size, int disp_unit, MPID_Inf
}
(*win_ptr)->base = (*win_ptr)->shm_base_addrs[rank];
}
/* get the base addresses of the windows. Note we reuse tmp_buf from above
since it's at least as large as we need it for this allgather. */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment