Skip to content

Commit

Permalink
Skip UBSAN error (division by zero)
Browse files Browse the repository at this point in the history
Happens when calling `system.integrator.run(0)`. In that case the
average instantaneous pressure is undefined and can only be NaN.
  • Loading branch information
jngrad committed Oct 12, 2019
1 parent c3247bd commit fb3c8fe
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/core/npt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,27 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "npt.hpp"
#include <cmath>

#include "communication.hpp"
#include "config.hpp"
#include "errorhandling.hpp"
#include "integrate.hpp"
#include "npt.hpp"

#ifdef NPT
void synchronize_npt_state(int n_steps) {
nptiso.invalidate_p_vel = false;
MPI_Bcast(&nptiso.p_inst, 1, MPI_DOUBLE, 0, comm_cart);
MPI_Bcast(&nptiso.p_diff, 1, MPI_DOUBLE, 0, comm_cart);
MPI_Bcast(&nptiso.volume, 1, MPI_DOUBLE, 0, comm_cart);
if (this_node == 0)
nptiso.p_inst_av /= 1.0 * n_steps;
if (this_node == 0) {
if (n_steps == 0) {
nptiso.p_inst_av = std::nan("");
} else {
nptiso.p_inst_av /= 1.0 * n_steps;
}
}
MPI_Bcast(&nptiso.p_inst_av, 1, MPI_DOUBLE, 0, comm_cart);
}

Expand Down

0 comments on commit fb3c8fe

Please sign in to comment.