-
Notifications
You must be signed in to change notification settings - Fork 566
Description
Consider the following code snippet:
mfem::Vector y;
{
HYPRE_BigInt col[2] = {0, 5};
mfem::HypreParVector z(MPI_COMM_WORLD, 5, col);
z = 2.0;
y = std::move(z);
}
When the brackets go out of scope, I would expect y = {2.0, 2.0, 2.0, 2.0, 2.0}, but this is not the case. The issue is z's data is not owned by z.data, it is instead owned by the derived class variable z.x. When z goes out of scope, the data held in z.x goes out of scope and is deleted. This has cropped up in serac, where we use HypreParVector pretty heavily.
I'm not sure what the best fix for the issue is. You could explicitly change the ownership of the data to y.data, but then hypre_ParVectorDestroy() is never called on the hypre_ParVector, potentially leading to memory leaks. Alternatively, you could make HypreParVector derive privately from Vector, since it seems you would never want to upcast a HypreParVector for this reason.
EDIT: fixed the constructor call for z