From: Berk Hess Date: Mon, 9 Mar 2015 14:47:49 +0000 (+0100) Subject: Reduced cost of Berendsen pressure coupling X-Git-Url: http://biod.pnpi.spb.ru/gitweb/?a=commitdiff_plain;h=d18dc3014c5c968f9a680f0e7707e716eec567ca;p=alexxy%2Fgromacs.git Reduced cost of Berendsen pressure coupling The coordinate and box scaling for Berendsen pressure coupling is now done only every nstpcouple steps. It now also uses OpenMP threading. Partially solves #1694 Change-Id: Id6abbb7f60960076e683707277ebbe5ff8e75453 --- diff --git a/src/gromacs/mdlib/coupling.cpp b/src/gromacs/mdlib/coupling.cpp index 8677c2d970..311ead52fe 100644 --- a/src/gromacs/mdlib/coupling.cpp +++ b/src/gromacs/mdlib/coupling.cpp @@ -3,7 +3,7 @@ * * Copyright (c) 1991-2000, University of Groningen, The Netherlands. * Copyright (c) 2001-2004, The GROMACS development team. - * Copyright (c) 2013,2014, by the GROMACS development team, led by + * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -40,6 +40,7 @@ #include +#include "gromacs/legacyheaders/gmx_omp_nthreads.h" #include "gromacs/legacyheaders/macros.h" #include "gromacs/legacyheaders/mdrun.h" #include "gromacs/legacyheaders/names.h" @@ -646,12 +647,25 @@ void berendsen_pscale(t_inputrec *ir, matrix mu, t_nrnb *nrnb) { ivec *nFreeze = ir->opts.nFreeze; - int n, d, g = 0; + int n, d; + int nthreads gmx_unused; + +#ifndef __clang_analyzer__ + // cppcheck-suppress unreadVariable + nthreads = gmx_omp_nthreads_get(emntUpdate); +#endif /* Scale the positions */ +#pragma omp parallel for num_threads(nthreads) schedule(static) for (n = start; n < start+nr_atoms; n++) { - if (cFREEZE) + int g; + + if (cFREEZE == NULL) + { + g = 0; + } + else { g = cFREEZE[n]; } diff --git a/src/gromacs/mdlib/update.cpp b/src/gromacs/mdlib/update.cpp index eab7fb1932..d5d18d2ab4 100644 --- a/src/gromacs/mdlib/update.cpp +++ b/src/gromacs/mdlib/update.cpp @@ -3,7 +3,7 @@ * * Copyright (c) 1991-2000, University of Groningen, The Netherlands. * Copyright (c) 2001-2004, The GROMACS development team. - * Copyright (c) 2013,2014, by the GROMACS development team, led by + * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -1778,8 +1778,16 @@ void update_box(FILE *fplog, case (epcNO): break; case (epcBERENDSEN): - berendsen_pscale(inputrec, pcoupl_mu, state->box, state->box_rel, - start, homenr, state->x, md->cFREEZE, nrnb); + /* We should only scale after a step where the pressure (kinetic + * energy and virial) was calculated. This happens after the + * coordinate update, whereas the current routine is called before + * that, so we scale when step % nstpcouple = 1 instead of 0. + */ + if (inputrec->nstpcouple == 1 || (step % inputrec->nstpcouple == 1)) + { + berendsen_pscale(inputrec, pcoupl_mu, state->box, state->box_rel, + start, homenr, state->x, md->cFREEZE, nrnb); + } break; case (epcPARRINELLORAHMAN): /* The box velocities were updated in do_pr_pcoupl in the update