From 839b4f6ce0f8544c90ca7cf74b35e0ab12fe9596 Mon Sep 17 00:00:00 2001 From: Berk Hess Date: Fri, 22 Aug 2014 12:37:49 +0200 Subject: [PATCH] Initialize unused velocity constraint components With domain decomposition, velocity components for communicated atoms could be uninitialized. These components were never used, but this could lead to valgrind warnings and floating point exceptions. Fixes #1576. Change-Id: Ic673680699578ddf62c2d240342138cbc16490c8 --- src/gromacs/mdlib/constr.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/gromacs/mdlib/constr.c b/src/gromacs/mdlib/constr.c index fa8275083d..b6878e6bd1 100644 --- a/src/gromacs/mdlib/constr.c +++ b/src/gromacs/mdlib/constr.c @@ -203,6 +203,18 @@ int n_flexible_constraints(struct gmx_constr *constr) return nflexcon; } +static void clear_constraint_quantity_nonlocal(gmx_domdec_t *dd, rvec *q) +{ + int nonlocal_at_start, nonlocal_at_end, at; + + dd_get_constraint_range(dd, &nonlocal_at_start, &nonlocal_at_end); + + for (at = nonlocal_at_start; at < nonlocal_at_end; at++) + { + clear_rvec(q[at]); + } +} + void too_many_constraint_warnings(int eConstrAlg, int warncount) { const char *abort = "- aborting to avoid logfile runaway.\n" @@ -431,6 +443,15 @@ gmx_bool constrain(FILE *fplog, gmx_bool bLog, gmx_bool bEner, if (cr->dd) { dd_move_x_constraints(cr->dd, box, x, xprime, econq == econqCoord); + + if (v != NULL) + { + /* We need to initialize the non-local components of v. + * We never actually use these values, but we do increment them, + * so we should avoid uninitialized variables and overflows. + */ + clear_constraint_quantity_nonlocal(cr->dd, v); + } } if (constr->lincsd != NULL) -- 2.22.0