-
Notifications
You must be signed in to change notification settings - Fork 188
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
Fix tabulated bond memory leaks #3961
Changes from 1 commit
34e7952
5419b41
00f1d18
0451fef
7c85067
ef9c69a
b8e1eba
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -335,14 +335,15 @@ void mpi_bcast_ia_params_slave(int i, int j) { | |
boost::mpi::broadcast(comm_cart, *get_ia_param(i, j), 0); | ||
} else { /* bonded interaction parameters */ | ||
make_bond_type_exist(i); /* realloc bonded_ia_params on slave nodes! */ | ||
if (is_tabulated_bond(bonded_ia_params[i].type)) { | ||
delete bonded_ia_params[i].p.tab.pot; | ||
} | ||
MPI_Bcast(&(bonded_ia_params[i]), sizeof(Bonded_ia_parameters), MPI_BYTE, 0, | ||
comm_cart); | ||
/* For tabulated potentials we have to send the tables extra */ | ||
if (is_tabulated_bond(bonded_ia_params[i].type)) { | ||
auto *tab_pot = new TabulatedPotential(); | ||
boost::mpi::broadcast(comm_cart, *tab_pot, 0); | ||
|
||
bonded_ia_params[i].p.tab.pot = tab_pot; | ||
bonded_ia_params[i].p.tab.pot = new TabulatedPotential(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. haven't looked into the code, but can't we use smart pointers? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think so: we overwrite the memory block of the bond object on worker nodes with a bytestring of the same object from the head node, so the counter from a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i'm not sure i'm following... but it sounds like this is a place for larger scale refactoring which is out of scope of this pull request? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the correct way would be to write boost serialization methods, which can handle pointer members out of the box, e.g. struct Tabulated_bond_parameters {
int type;
TabulatedPotential *pot;
private:
friend boost::serialization::access;
template <typename Archive>
void serialize(Archive &ar, long int /* version */) {
ar &type;
ar &pot;
}
}; but there is no guarantee that we are overwriting a bond type with the same bond type, so we would have to add destructors too... Not sure if this is worth the effort, if our long-term goal is to replace this interaction communication infrastructure with a python setter. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, a much more promising refactoring goal is breaking the dependency on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Isn't that totally orthogonal to the memory leak issue? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
sorry, if that has been discussed and i don't remember it anymore... Do we have some design plans for the interaction stuff already? |
||
boost::mpi::broadcast(comm_cart, *bonded_ia_params[i].p.tab.pot, 0); | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cant't you just check for
nullptr
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually this would raise a Clang-Tidy warning because you can simplify it to
delete bonded_ia_params[bond_type].p.tab.pot;
which is safe on a
nullptr
.However, this would also trigger a segfault, because you can create a tabulated bond on top of an existing FENE bond, in which case
.p.tab.pot
contains a random address. You can overwrite an bond existing bond in ESPResSo, this is used for example intestsuite/python/interactions_bonded_interface.py
.