Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug 239 emptyalloc #240

Merged
merged 2 commits into from
Jan 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 24 additions & 18 deletions dart-impl/mpi/src/dart_globmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -276,23 +276,29 @@ dart_team_memalloc_aligned(

win = dart_team_data[index].window;
/* Attach the allocated shared memory to win */
if (MPI_Win_attach(win, sub_mem, nbytes) != MPI_SUCCESS) {
DART_LOG_ERROR(
"dart_team_memalloc_aligned: bytes:%lu MPI_Win_attach failed", nbytes);
/* Calling MPI_Win_attach with nbytes == 0 leads to errors, see #239 */
if (nbytes > 0) {
if (MPI_Win_attach(win, sub_mem, nbytes) != MPI_SUCCESS) {
DART_LOG_ERROR(
"dart_team_memalloc_aligned: bytes:%lu MPI_Win_attach failed", nbytes);
#if !defined(DART_MPI_DISABLE_SHARED_WINDOWS)
free(baseptr_set);
free(baseptr_set);
#endif
free(disp_set);
return DART_ERR_OTHER;
}
if (MPI_Get_address(sub_mem, &disp) != MPI_SUCCESS) {
DART_LOG_ERROR(
"dart_team_memalloc_aligned: bytes:%lu MPI_Get_address failed", nbytes);
free(disp_set);
free(disp_set);
return DART_ERR_OTHER;
}

if (MPI_Get_address(sub_mem, &disp) != MPI_SUCCESS) {
DART_LOG_ERROR(
"dart_team_memalloc_aligned: bytes:%lu MPI_Get_address failed", nbytes);
free(disp_set);
#if !defined(DART_MPI_DISABLE_SHARED_WINDOWS)
free(baseptr_set);
free(baseptr_set);
#endif
return DART_ERR_OTHER;
return DART_ERR_OTHER;
}
} else {
disp = 0;
}

/* Collect the disp information from all the ranks in comm */
Expand Down Expand Up @@ -372,12 +378,12 @@ dart_ret_t dart_team_memfree(
return DART_ERR_INVAL;
}

/* Detach the window associated with sub-memory to be freed:
*/
MPI_Win_detach(win, sub_mem);
/* Detach the window associated with sub-memory to be freed */
if (sub_mem != NULL) {
MPI_Win_detach(win, sub_mem);
}

/* Free the window's associated sub-memory:
*/
/* Free the window's associated sub-memory */
#if !defined(DART_MPI_DISABLE_SHARED_WINDOWS)
MPI_Win sharedmem_win;
if (dart_segment_get_win(seg_id, &sharedmem_win) != DART_OK) {
Expand Down
45 changes: 21 additions & 24 deletions dash/include/dash/GlobMem.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,10 @@ class GlobMem
DASH_LOG_TRACE("GlobMem(nlocal,team)",
"number of local values:", _nlelem,
"team size:", team.size());
if (_nlelem == 0 || _nunits == 0) {
DASH_LOG_DEBUG("GlobMem(lvals,team)", "nothing to allocate");
return;
}
// if (_nlelem == 0 || _nunits == 0) {
// DASH_LOG_DEBUG("GlobMem(lvals,team)", "nothing to allocate");
// return;
// }
_begptr = _allocator.allocate(_nlelem);
DASH_ASSERT_MSG(!DART_GPTR_ISNULL(_begptr), "allocation failed");

Expand Down Expand Up @@ -153,26 +153,23 @@ class GlobMem
DASH_LOG_DEBUG("GlobMem(lvals,team)",
"number of local values:", _nlelem,
"team size:", team.size());
if (_nlelem == 0 || _nunits == 0) {
DASH_LOG_DEBUG("GlobMem(lvals,team)", "nothing to allocate");
} else {
_begptr = _allocator.allocate(_nlelem);
DASH_ASSERT_MSG(!DART_GPTR_ISNULL(_begptr), "allocation failed");

// Use id's of team all
_lbegin = lbegin(dash::Team::GlobalUnitID());
_lend = lend(dash::Team::GlobalUnitID());
DASH_ASSERT_EQ(std::distance(_lbegin, _lend), local_elements.size(),
"Capacity of local memory range differs from number "
"of specified local elements");

// Initialize allocated local elements with specified values:
auto copy_end = std::copy(local_elements.begin(),
local_elements.end(),
_lbegin);
DASH_ASSERT_EQ(_lend, copy_end,
"Initialization of specified local values failed");
}
_begptr = _allocator.allocate(_nlelem);
DASH_ASSERT_MSG(!DART_GPTR_ISNULL(_begptr), "allocation failed");

// Use id's of team all
_lbegin = lbegin(dash::Team::GlobalUnitID());
_lend = lend(dash::Team::GlobalUnitID());
DASH_ASSERT_EQ(std::distance(_lbegin, _lend), local_elements.size(),
"Capacity of local memory range differs from number "
"of specified local elements");

// Initialize allocated local elements with specified values:
auto copy_end = std::copy(local_elements.begin(),
local_elements.end(),
_lbegin);
DASH_ASSERT_EQ(_lend, copy_end,
"Initialization of specified local values failed");

if (_nunits > 1) {
// Wait for initialization of local values at all units.
// Barrier synchronization is okay here as multiple units are
Expand Down
14 changes: 6 additions & 8 deletions dash/include/dash/allocator/CollectiveAllocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,14 +177,12 @@ class CollectiveAllocator
DASH_LOG_DEBUG("CollectiveAllocator.allocate(nlocal)",
"number of local values:", num_local_elem);
pointer gptr = DART_GPTR_NULL;
if (num_local_elem > 0) {
dart_storage_t ds = dart_storage<ElementType>(num_local_elem);
if (dart_team_memalloc_aligned(_team_id, ds.nelem, ds.dtype, &gptr)
== DART_OK) {
_allocated.push_back(gptr);
} else {
gptr = DART_GPTR_NULL;
}
dart_storage_t ds = dart_storage<ElementType>(num_local_elem);
if (dart_team_memalloc_aligned(_team_id, ds.nelem, ds.dtype, &gptr)
== DART_OK) {
_allocated.push_back(gptr);
} else {
gptr = DART_GPTR_NULL;
}
DASH_LOG_DEBUG_VAR("CollectiveAllocator.allocate >", gptr);
return gptr;
Expand Down