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

reserveCells crashes mint mesh inside Umpire #1271

Draft
wants to merge 6 commits into
base: develop
Choose a base branch
from
Draft
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
23 changes: 22 additions & 1 deletion src/axom/core/memory_management.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,28 @@ inline T* reallocate(T* pointer, std::size_t n, int allocID) noexcept
}
else
{
pointer = static_cast<T*>(rm.reallocate(pointer, numbytes));
constexpr bool workAround = true;
if(workAround)
{
/*
This work-around addresses issue #1287 and PR #1271.
The reproducer is the immediate_ug_reserve test in file
axom/src/axom/quest/test/quest_initialize.cpp. This
work-around doesn't address the actual cause of the problem,
something we should try to identify and fix.
*/
auto oldPointer = pointer;
auto foundAllocator = rm.getAllocator(pointer);
auto oldSize = foundAllocator.getSize(pointer);
pointer = static_cast<T*>(foundAllocator.allocate(numbytes));
auto copysize = std::min(oldSize, numbytes);
axom::copy(pointer, oldPointer, copysize);
axom::deallocate(oldPointer);
}
else
{
pointer = static_cast<T*>(rm.reallocate(pointer, numbytes));
}
}

#else
Expand Down
12 changes: 12 additions & 0 deletions src/axom/mint/tests/mint_mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,18 @@ TEST(mint_mesh, get_mixed_topology_unstructured_from_sidre)
delete m;
}

//------------------------------------------------------------------------------
TEST(mint_mesh, immediate_ug_reserve)
{
axom::sidre::DataStore objectDS;
axom::sidre::Group* meshGroup = objectDS.getRoot()->createGroup("myGroup");
axom::mint::UnstructuredMesh<axom::mint::SINGLE_SHAPE> contourMesh(
2,
axom::mint::CellType::SEGMENT,
meshGroup);
contourMesh.reserveCells(10); // This may crash.
}

#endif /* AXOM_MINT_USE_SIDRE */

} /* namespace mint */
Expand Down
5 changes: 2 additions & 3 deletions src/axom/quest/examples/quest_marching_cubes_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -916,13 +916,12 @@ struct ContourTestBase
AXOM_ANNOTATE_BEGIN("convert to mint mesh");
std::string sidreGroupName = "contour_mesh";
sidre::DataStore objectDS;
// While awaiting fix for PR #1271, don't use Sidre storage in contourMesh.
auto* meshGroup = objectDS.getRoot()->createGroup(sidreGroupName);
AXOM_UNUSED_VAR(meshGroup); // variable is only referenced in debug configs

axom::mint::UnstructuredMesh<axom::mint::SINGLE_SHAPE> contourMesh(
DIM,
DIM == 2 ? mint::CellType::SEGMENT : mint::CellType::TRIANGLE);
DIM == 2 ? mint::CellType::SEGMENT : mint::CellType::TRIANGLE,
meshGroup);
axom::utilities::Timer extractTimer(false);
extractTimer.start();
mc.populateContourMesh(contourMesh, m_parentCellIdField, m_domainIdField);
Expand Down
17 changes: 17 additions & 0 deletions src/axom/quest/tests/quest_initialize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
// Axom includes
#include "axom/mint.hpp"
#include "quest_test_utilities.hpp"
#if defined AXOM_USE_SIDRE
#include "axom/sidre.hpp"
#endif

#include "axom/quest/interface/inout.hpp"
#include "axom/quest/interface/signed_distance.hpp"
Expand Down Expand Up @@ -72,6 +75,20 @@ TEST(quest_initialize, signed_distance_pointer_initialize)
delete input_mesh;
}

#if defined AXOM_USE_SIDRE
// Test immediately reserving space in UnstructuredMesh.
TEST(quest_initialize, immediate_ug_reserve)
{
axom::sidre::DataStore objectDS;
axom::sidre::Group* meshGroup = objectDS.getRoot()->createGroup("myGroup");
axom::mint::UnstructuredMesh<axom::mint::SINGLE_SHAPE> contourMesh(
2,
axom::mint::CellType::SEGMENT,
meshGroup);
contourMesh.reserveCells(10); // This may unexpectedly crash.
}
#endif

int main(int argc, char** argv)
{
#ifdef AXOM_USE_MPI
Expand Down