From 1b815839362d34ec2b530a4a21a0b4c9628886be Mon Sep 17 00:00:00 2001 From: Berk Hess Date: Mon, 6 Apr 2020 11:27:31 +0000 Subject: [PATCH] Move force buffer resizing to mdsetup Consolidate resizing of the force buffer passed to do_force() from many places in the code to mdAlgorithmsSetupAtomData(). Now only the modular simulation does it's own resizing when not using domain decomposition. Some refactoring is needed to avoid this. Change-Id: I1320dffb7b42150f65c5c6a260a7e94e2f6806b5 --- src/gromacs/domdec/distribute.cpp | 24 ++++----- src/gromacs/domdec/distribute.h | 16 +++--- src/gromacs/domdec/mdsetup.cpp | 51 +++++++++++++------ src/gromacs/domdec/mdsetup.h | 26 ++++++---- src/gromacs/domdec/partition.cpp | 23 ++++----- src/gromacs/domdec/redistribute.cpp | 25 ++++----- src/gromacs/domdec/redistribute.h | 21 ++++---- src/gromacs/domdec/utility.cpp | 31 ++--------- src/gromacs/domdec/utility.h | 23 +++------ src/gromacs/mdlib/forcerec.cpp | 5 -- src/gromacs/mdlib/sim_util.cpp | 4 ++ src/gromacs/mdrun/md.cpp | 3 +- src/gromacs/mdrun/mimic.cpp | 6 +-- src/gromacs/mdrun/minimize.cpp | 3 +- src/gromacs/mdrun/rerun.cpp | 6 +-- src/gromacs/mdrun/shellfc.cpp | 2 +- src/gromacs/mdtypes/forcerec.h | 5 +- .../modularsimulator/topologyholder.cpp | 7 ++- src/gromacs/modularsimulator/topologyholder.h | 2 +- 19 files changed, 127 insertions(+), 156 deletions(-) diff --git a/src/gromacs/domdec/distribute.cpp b/src/gromacs/domdec/distribute.cpp index a681378a05..062acc6b57 100644 --- a/src/gromacs/domdec/distribute.cpp +++ b/src/gromacs/domdec/distribute.cpp @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2018,2019, by the GROMACS development team, led by + * Copyright (c) 2018,2019,2020, 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. @@ -187,10 +187,7 @@ static void dd_distribute_dfhist(gmx_domdec_t* dd, df_history_t* dfhist) } } -static void dd_distribute_state(gmx_domdec_t* dd, - const t_state* state, - t_state* state_local, - PaddedHostVector* f) +static void dd_distribute_state(gmx_domdec_t* dd, const t_state* state, t_state* state_local) { int nh = state_local->nhchainlength; @@ -252,7 +249,7 @@ static void dd_distribute_state(gmx_domdec_t* dd, /* communicate df_history -- required for restarting from checkpoint */ dd_distribute_dfhist(dd, state_local->dfhist); - dd_resize_state(state_local, f, dd->comm->atomRanges.numHomeAtoms()); + state_change_natoms(state_local, dd->comm->atomRanges.numHomeAtoms()); if (state_local->flags & (1 << estX)) { @@ -552,17 +549,16 @@ static void distributeAtomGroups(const gmx::MDLogger& mdlog, } } -void distributeState(const gmx::MDLogger& mdlog, - gmx_domdec_t* dd, - const gmx_mtop_t& mtop, - t_state* state_global, - const gmx_ddbox_t& ddbox, - t_state* state_local, - PaddedHostVector* f) +void distributeState(const gmx::MDLogger& mdlog, + gmx_domdec_t* dd, + const gmx_mtop_t& mtop, + t_state* state_global, + const gmx_ddbox_t& ddbox, + t_state* state_local) { rvec* xGlobal = (DDMASTER(dd) ? state_global->x.rvec_array() : nullptr); distributeAtomGroups(mdlog, dd, mtop, DDMASTER(dd) ? state_global->box : nullptr, &ddbox, xGlobal); - dd_distribute_state(dd, state_global, state_local, f); + dd_distribute_state(dd, state_global, state_local); } diff --git a/src/gromacs/domdec/distribute.h b/src/gromacs/domdec/distribute.h index 7dc1a7b53d..7012f5bd60 100644 --- a/src/gromacs/domdec/distribute.h +++ b/src/gromacs/domdec/distribute.h @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2018,2019, by the GROMACS development team, led by + * Copyright (c) 2018,2019,2020, 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. @@ -42,7 +42,6 @@ #ifndef GMX_DOMDEC_DOMDEC_DISTRIBUTE_H #define GMX_DOMDEC_DOMDEC_DISTRIBUTE_H -#include "gromacs/gpu_utils/hostallocator.h" #include "gromacs/utility/basedefinitions.h" struct gmx_ddbox_t; @@ -57,12 +56,11 @@ class MDLogger; } /*! \brief Distributes the state from the master rank to all DD ranks */ -void distributeState(const gmx::MDLogger& mdlog, - gmx_domdec_t* dd, - const gmx_mtop_t& mtop, - t_state* state_global, - const gmx_ddbox_t& ddbox, - t_state* state_local, - gmx::PaddedHostVector* f); +void distributeState(const gmx::MDLogger& mdlog, + gmx_domdec_t* dd, + const gmx_mtop_t& mtop, + t_state* state_global, + const gmx_ddbox_t& ddbox, + t_state* state_local); #endif diff --git a/src/gromacs/domdec/mdsetup.cpp b/src/gromacs/domdec/mdsetup.cpp index bbe0cc67cf..218a4e559d 100644 --- a/src/gromacs/domdec/mdsetup.cpp +++ b/src/gromacs/domdec/mdsetup.cpp @@ -54,38 +54,55 @@ #include "gromacs/utility/gmxassert.h" #include "gromacs/utility/smalloc.h" +namespace gmx +{ + /* TODO: Add a routine that collects the initial setup of the algorithms. * * The final solution should be an MD algorithm base class with methods * for initialization and atom-data setup. */ -void mdAlgorithmsSetupAtomData(const t_commrec* cr, - const t_inputrec* ir, - const gmx_mtop_t& top_global, - gmx_localtop_t* top, - t_forcerec* fr, - gmx::MDAtoms* mdAtoms, - gmx::Constraints* constr, - gmx_vsite_t* vsite, - gmx_shellfc_t* shellfc) +void mdAlgorithmsSetupAtomData(const t_commrec* cr, + const t_inputrec* ir, + const gmx_mtop_t& top_global, + gmx_localtop_t* top, + t_forcerec* fr, + PaddedHostVector* force, + MDAtoms* mdAtoms, + Constraints* constr, + gmx_vsite_t* vsite, + gmx_shellfc_t* shellfc) { bool usingDomDec = DOMAINDECOMP(cr); - int numAtomIndex, numHomeAtoms; + int numAtomIndex; int* atomIndex; + int numHomeAtoms; + int numTotalAtoms; if (usingDomDec) { - numAtomIndex = dd_natoms_mdatoms(cr->dd); - atomIndex = cr->dd->globalAtomIndices.data(); - numHomeAtoms = dd_numHomeAtoms(*cr->dd); + numAtomIndex = dd_natoms_mdatoms(cr->dd); + atomIndex = cr->dd->globalAtomIndices.data(); + numHomeAtoms = dd_numHomeAtoms(*cr->dd); + numTotalAtoms = dd_natoms_mdatoms(cr->dd); } else { - numAtomIndex = -1; - atomIndex = nullptr; - numHomeAtoms = top_global.natoms; + numAtomIndex = -1; + atomIndex = nullptr; + numHomeAtoms = top_global.natoms; + numTotalAtoms = top_global.natoms; + } + + if (force != nullptr) + { + /* We need to allocate one element extra, since we might use + * (unaligned) 4-wide SIMD loads to access rvec entries. + */ + force->resizeWithPadding(numTotalAtoms); } + atoms2md(&top_global, ir, numAtomIndex, atomIndex, numHomeAtoms, mdAtoms); auto mdatoms = mdAtoms->mdatoms(); @@ -140,3 +157,5 @@ void mdAlgorithmsSetupAtomData(const t_commrec* cr, constr->setConstraints(top, *mdatoms); } } + +} // namespace gmx diff --git a/src/gromacs/domdec/mdsetup.h b/src/gromacs/domdec/mdsetup.h index 2daa293526..369bf64d71 100644 --- a/src/gromacs/domdec/mdsetup.h +++ b/src/gromacs/domdec/mdsetup.h @@ -43,6 +43,9 @@ #ifndef GMX_DOMDEC_MDSETUP_H #define GMX_DOMDEC_MDSETUP_H +#include "gromacs/gpu_utils/hostallocator.h" +#include "gromacs/math/vectypes.h" + struct bonded_threading_t; struct gmx_localtop_t; struct gmx_mtop_t; @@ -57,7 +60,6 @@ namespace gmx { class Constraints; class MDAtoms; -} // namespace gmx /*! \brief Gets the local shell with domain decomposition * @@ -79,19 +81,23 @@ void make_local_shells(const t_commrec* cr, const t_mdatoms* md, gmx_shellfc_t* * \param[in] top_global The global topology * \param[in,out] top The local topology * \param[in,out] fr The force calculation parameter/data record + * \param[out] force The force buffer * \param[out] mdAtoms The MD atom data * \param[in,out] constr The constraints handler, can be NULL * \param[in,out] vsite The virtual site data, can be NULL * \param[in,out] shellfc The shell/flexible-constraint data, can be NULL */ -void mdAlgorithmsSetupAtomData(const t_commrec* cr, - const t_inputrec* ir, - const gmx_mtop_t& top_global, - gmx_localtop_t* top, - t_forcerec* fr, - gmx::MDAtoms* mdAtoms, - gmx::Constraints* constr, - gmx_vsite_t* vsite, - gmx_shellfc_t* shellfc); +void mdAlgorithmsSetupAtomData(const t_commrec* cr, + const t_inputrec* ir, + const gmx_mtop_t& top_global, + gmx_localtop_t* top, + t_forcerec* fr, + PaddedHostVector* force, + MDAtoms* mdAtoms, + Constraints* constr, + gmx_vsite_t* vsite, + gmx_shellfc_t* shellfc); + +} // namespace gmx #endif diff --git a/src/gromacs/domdec/partition.cpp b/src/gromacs/domdec/partition.cpp index 7a36e5ae25..b4fa8901ed 100644 --- a/src/gromacs/domdec/partition.cpp +++ b/src/gromacs/domdec/partition.cpp @@ -1807,12 +1807,7 @@ static void clearCommSetupData(dd_comm_setup_work_t* work) } //! Prepare DD communication. -static void setup_dd_communication(gmx_domdec_t* dd, - matrix box, - gmx_ddbox_t* ddbox, - t_forcerec* fr, - t_state* state, - PaddedHostVector* f) +static void setup_dd_communication(gmx_domdec_t* dd, matrix box, gmx_ddbox_t* ddbox, t_forcerec* fr, t_state* state) { int dim_ind, dim, dim0, dim1, dim2, dimd, nat_tot; int nzone, nzone_send, zone, zonei, cg0, cg1; @@ -2089,7 +2084,7 @@ static void setup_dd_communication(gmx_domdec_t* dd, ddSendrecv(dd, dim_ind, dddirBackward, work.atomGroupBuffer, integerBufferRef); /* Make space for cg_cm */ - dd_check_alloc_ncg(fr, state, f, pos_cg + ind->nrecv[nzone]); + dd_resize_atominfo_and_state(fr, state, pos_cg + ind->nrecv[nzone]); /* Communicate the coordinates */ gmx::ArrayRef rvecBufferRef; @@ -2865,10 +2860,10 @@ void dd_partition_system(FILE* fplog, set_ddbox(*dd, true, DDMASTER(dd) ? state_global->box : nullptr, true, xGlobal, &ddbox); - distributeState(mdlog, dd, top_global, state_global, ddbox, state_local, f); + distributeState(mdlog, dd, top_global, state_global, ddbox, state_local); /* Ensure that we have space for the new distribution */ - dd_check_alloc_ncg(fr, state_local, f, dd->ncg_home); + dd_resize_atominfo_and_state(fr, state_local, dd->ncg_home); inc_nrnb(nrnb, eNR_CGCM, comm->atomRanges.numHomeAtoms()); @@ -2961,7 +2956,7 @@ void dd_partition_system(FILE* fplog, wallcycle_sub_start(wcycle, ewcsDD_REDIST); ncgindex_set = dd->ncg_home; - dd_redistribute_cg(fplog, step, dd, ddbox.tric_dir, state_local, f, fr, nrnb, &ncg_moved); + dd_redistribute_cg(fplog, step, dd, ddbox.tric_dir, state_local, fr, nrnb, &ncg_moved); GMX_RELEASE_ASSERT(bSortCG, "Sorting is required after redistribution"); @@ -3015,7 +3010,7 @@ void dd_partition_system(FILE* fplog, dd_sort_state(dd, fr, state_local); /* After sorting and compacting we set the correct size */ - dd_resize_state(state_local, f, comm->atomRanges.numHomeAtoms()); + state_change_natoms(state_local, comm->atomRanges.numHomeAtoms()); /* Rebuild all the indices */ dd->ga2la->clear(); @@ -3049,7 +3044,7 @@ void dd_partition_system(FILE* fplog, make_dd_indices(dd, ncgindex_set); /* Setup up the communication and communicate the coordinates */ - setup_dd_communication(dd, state_local->box, &ddbox, fr, state_local, f); + setup_dd_communication(dd, state_local->box, &ddbox, fr, state_local); /* Set the indices for the halo atoms */ make_dd_indices(dd, dd->ncg_home); @@ -3120,7 +3115,7 @@ void dd_partition_system(FILE* fplog, */ state_local->natoms = comm->atomRanges.numAtomsTotal(); - dd_resize_state(state_local, f, state_local->natoms); + state_change_natoms(state_local, state_local->natoms); if (fr->haveDirectVirialContributions) { @@ -3155,7 +3150,7 @@ void dd_partition_system(FILE* fplog, comm->atomRanges.end(DDAtomRanges::Type::Constraints), nat_f_novirsum); /* Update atom data for mdatoms and several algorithms */ - mdAlgorithmsSetupAtomData(cr, ir, top_global, top_local, fr, mdAtoms, constr, vsite, nullptr); + mdAlgorithmsSetupAtomData(cr, ir, top_global, top_local, fr, f, mdAtoms, constr, vsite, nullptr); auto mdatoms = mdAtoms->mdatoms(); if (!thisRankHasDuty(cr, DUTY_PME)) diff --git a/src/gromacs/domdec/redistribute.cpp b/src/gromacs/domdec/redistribute.cpp index ba86477b59..6b985c1345 100644 --- a/src/gromacs/domdec/redistribute.cpp +++ b/src/gromacs/domdec/redistribute.cpp @@ -1,8 +1,10 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018,2019, by the. - * Copyright (c) 2019, by the GROMACS development team, led by + * Copyright (c) 2005,2006,2007,2008,2009 by the GROMACS development team. + * Copyright (c) 2010,2011,2012,2013,2014 by the GROMACS development team. + * Copyright (c) 2015,2016,2017,2018,2019 by the GROMACS development team. + * Copyright (c) 2020, 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. @@ -545,15 +547,14 @@ static void applyPbcAndSetMoveFlags(const gmx::UpdateGroupsCog& updateGroups } } -void dd_redistribute_cg(FILE* fplog, - int64_t step, - gmx_domdec_t* dd, - ivec tric_dir, - t_state* state, - PaddedHostVector* f, - t_forcerec* fr, - t_nrnb* nrnb, - int* ncg_moved) +void dd_redistribute_cg(FILE* fplog, + int64_t step, + gmx_domdec_t* dd, + ivec tric_dir, + t_state* state, + t_forcerec* fr, + t_nrnb* nrnb, + int* ncg_moved) { gmx_domdec_comm_t* comm = dd->comm; @@ -777,7 +778,7 @@ void dd_redistribute_cg(FILE* fplog, nvr += i; } - dd_check_alloc_ncg(fr, state, f, home_pos_cg + ncg_recv); + dd_resize_atominfo_and_state(fr, state, home_pos_cg + ncg_recv); /* Process the received charge or update groups */ int buf_pos = 0; diff --git a/src/gromacs/domdec/redistribute.h b/src/gromacs/domdec/redistribute.h index 732094f4d7..68d8bd9c6e 100644 --- a/src/gromacs/domdec/redistribute.h +++ b/src/gromacs/domdec/redistribute.h @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2018,2019, by the GROMACS development team, led by + * Copyright (c) 2018,2019,2020, 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. @@ -44,7 +44,7 @@ #include -#include "gromacs/gpu_utils/hostallocator.h" +#include "gromacs/math/vectypes.h" #include "gromacs/utility/basedefinitions.h" struct gmx_domdec_t; @@ -53,14 +53,13 @@ struct t_nrnb; class t_state; /*! \brief Redistribute the atoms to their, new, local domains */ -void dd_redistribute_cg(FILE* fplog, - int64_t step, - gmx_domdec_t* dd, - ivec tric_dir, - t_state* state, - gmx::PaddedHostVector* f, - t_forcerec* fr, - t_nrnb* nrnb, - int* ncg_moved); +void dd_redistribute_cg(FILE* fplog, + int64_t step, + gmx_domdec_t* dd, + ivec tric_dir, + t_state* state, + t_forcerec* fr, + t_nrnb* nrnb, + int* ncg_moved); #endif diff --git a/src/gromacs/domdec/utility.cpp b/src/gromacs/domdec/utility.cpp index 01db3ead59..db2833c0c3 100644 --- a/src/gromacs/domdec/utility.cpp +++ b/src/gromacs/domdec/utility.cpp @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2018,2019, by the GROMACS development team, led by + * Copyright (c) 2018,2019,2020, 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. @@ -102,34 +102,11 @@ void check_screw_box(const matrix box) gmx_fatal(FARGS, "pbc=screw with non-zero box_zy is not supported"); } } -/*! \brief Resize the state and f*/ -void dd_resize_state(t_state* state, PaddedHostVector* f, int natoms) -{ - if (debug) - { - fprintf(debug, "Resizing state: currently %d, required %d\n", state->natoms, natoms); - } - - state_change_natoms(state, natoms); - - if (f != nullptr) - { - /* We need to allocate one element extra, since we might use - * (unaligned) 4-wide SIMD loads to access rvec entries. - */ - f->resizeWithPadding(natoms); - } -} -/*! \brief Ensure fr, state and f, if != nullptr, can hold numChargeGroups - * atoms for the Verlet scheme and charge groups for the group scheme. - * - * todo refactor this now that group scheme is removed - */ -void dd_check_alloc_ncg(t_forcerec* fr, t_state* state, PaddedHostVector* f, int numChargeGroups) +void dd_resize_atominfo_and_state(t_forcerec* fr, t_state* state, const int numAtoms) { - fr->cginfo.resize(numChargeGroups); + fr->cginfo.resize(numAtoms); /* We use x during the setup of the atom communication */ - dd_resize_state(state, f, numChargeGroups); + state_change_natoms(state, numAtoms); } diff --git a/src/gromacs/domdec/utility.h b/src/gromacs/domdec/utility.h index 353dc327b0..4e36029e2e 100644 --- a/src/gromacs/domdec/utility.h +++ b/src/gromacs/domdec/utility.h @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2018,2019, by the GROMACS development team, led by + * Copyright (c) 2018,2019,2020, 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. @@ -42,9 +42,9 @@ #ifndef GMX_DOMDEC_DOMDEC_UTILITY_H #define GMX_DOMDEC_DOMDEC_UTILITY_H -#include "gromacs/gpu_utils/hostallocator.h" #include "gromacs/mdtypes/forcerec.h" #include "gromacs/utility/arrayref.h" +#include "gromacs/math/vectypes.h" #include "domdec_internal.h" @@ -96,22 +96,13 @@ static inline int dd_load_count(const gmx_domdec_comm_t* comm) return (comm->ddSettings.eFlop ? comm->flop_n : comm->cycl_n[ddCyclF]); } -/*! \brief Resize the state and f, if !=nullptr, to natoms +/*! \brief Ensure fr and state can hold numAtoms atoms * - * \param[in] state Current state - * \param[in] f The vector of forces to be resized - * \param[out] natoms New number of atoms to accommodate + * \param[in] fr Force record + * \param[in] state Current state + * \param[out] numAtoms Number of atoms */ -void dd_resize_state(t_state* state, gmx::PaddedHostVector* f, int natoms); - -/*! \brief Enrsure fr, state and f, if != nullptr, can hold numChargeGroups atoms for the Verlet scheme and charge groups for the group scheme - * - * \param[in] fr Force record - * \param[in] state Current state - * \param[in] f The force buffer - * \param[out] numChargeGroups Number of charged groups - */ -void dd_check_alloc_ncg(t_forcerec* fr, t_state* state, gmx::PaddedHostVector* f, int numChargeGroups); +void dd_resize_atominfo_and_state(t_forcerec* fr, t_state* state, int numAtoms); /*! \brief Returns a domain-to-domain cutoff distance given an atom-to-atom cutoff */ static inline real atomToAtomIntoDomainToDomainCutoff(const DDSystemInfo& systemInfo, real cutoff) diff --git a/src/gromacs/mdlib/forcerec.cpp b/src/gromacs/mdlib/forcerec.cpp index 0d1828fe49..8d3c5fbf03 100644 --- a/src/gromacs/mdlib/forcerec.cpp +++ b/src/gromacs/mdlib/forcerec.cpp @@ -600,11 +600,6 @@ void forcerec_set_ranges(t_forcerec* fr, int natoms_force, int natoms_force_cons fr->natoms_force = natoms_force; fr->natoms_force_constr = natoms_force_constr; - if (fr->natoms_force_constr > fr->nalloc_force) - { - fr->nalloc_force = over_alloc_dd(fr->natoms_force_constr); - } - if (fr->haveDirectVirialContributions) { fr->forceBufferForDirectVirialContributions.resize(natoms_f_novirsum); diff --git a/src/gromacs/mdlib/sim_util.cpp b/src/gromacs/mdlib/sim_util.cpp index c21c809ca2..905c5f446b 100644 --- a/src/gromacs/mdlib/sim_util.cpp +++ b/src/gromacs/mdlib/sim_util.cpp @@ -960,6 +960,10 @@ void do_force(FILE* fplog, int legacyFlags, const DDBalanceRegionHandler& ddBalanceRegionHandler) { + GMX_ASSERT(force.unpaddedArrayRef().ssize() >= fr->natoms_force_constr, + "The size of the force buffer should be at least the number of atoms to compute " + "forces for"); + nonbonded_verlet_t* nbv = fr->nbv.get(); interaction_const_t* ic = fr->ic; gmx::StatePropagatorDataGpu* stateGpu = fr->stateGpu; diff --git a/src/gromacs/mdrun/md.cpp b/src/gromacs/mdrun/md.cpp index 1900f4938c..4147925cdf 100644 --- a/src/gromacs/mdrun/md.cpp +++ b/src/gromacs/mdrun/md.cpp @@ -336,12 +336,11 @@ void gmx::LegacySimulator::do_md() else { state_change_natoms(state_global, state_global->natoms); - f.resizeWithPadding(state_global->natoms); /* Copy the pointer to the global state */ state = state_global; /* Generate and initialize new topology */ - mdAlgorithmsSetupAtomData(cr, ir, *top_global, &top, fr, mdAtoms, constr, vsite, shellfc); + mdAlgorithmsSetupAtomData(cr, ir, *top_global, &top, fr, &f, mdAtoms, constr, vsite, shellfc); upd.setNumAtoms(state->natoms); } diff --git a/src/gromacs/mdrun/mimic.cpp b/src/gromacs/mdrun/mimic.cpp index 247e25caa6..bfb2cca0e3 100644 --- a/src/gromacs/mdrun/mimic.cpp +++ b/src/gromacs/mdrun/mimic.cpp @@ -267,14 +267,10 @@ void gmx::LegacySimulator::do_mimic() else { state_change_natoms(state_global, state_global->natoms); - /* We need to allocate one element extra, since we might use - * (unaligned) 4-wide SIMD loads to access rvec entries. - */ - f.resizeWithPadding(state_global->natoms); /* Copy the pointer to the global state */ state = state_global; - mdAlgorithmsSetupAtomData(cr, ir, *top_global, &top, fr, mdAtoms, constr, vsite, shellfc); + mdAlgorithmsSetupAtomData(cr, ir, *top_global, &top, fr, &f, mdAtoms, constr, vsite, shellfc); } auto mdatoms = mdAtoms->mdatoms(); diff --git a/src/gromacs/mdrun/minimize.cpp b/src/gromacs/mdrun/minimize.cpp index afe557f276..ca04f456df 100644 --- a/src/gromacs/mdrun/minimize.cpp +++ b/src/gromacs/mdrun/minimize.cpp @@ -428,9 +428,8 @@ static void init_em(FILE* fplog, /* Just copy the state */ ems->s = *state_global; state_change_natoms(&ems->s, ems->s.natoms); - ems->f.resizeWithPadding(ems->s.natoms); - mdAlgorithmsSetupAtomData(cr, ir, *top_global, top, fr, mdAtoms, constr, vsite, + mdAlgorithmsSetupAtomData(cr, ir, *top_global, top, fr, &ems->f, mdAtoms, constr, vsite, shellfc ? *shellfc : nullptr); if (vsite) diff --git a/src/gromacs/mdrun/rerun.cpp b/src/gromacs/mdrun/rerun.cpp index 3d369223a6..6fe368c30e 100644 --- a/src/gromacs/mdrun/rerun.cpp +++ b/src/gromacs/mdrun/rerun.cpp @@ -325,14 +325,10 @@ void gmx::LegacySimulator::do_rerun() else { state_change_natoms(state_global, state_global->natoms); - /* We need to allocate one element extra, since we might use - * (unaligned) 4-wide SIMD loads to access rvec entries. - */ - f.resizeWithPadding(state_global->natoms); /* Copy the pointer to the global state */ state = state_global; - mdAlgorithmsSetupAtomData(cr, ir, *top_global, &top, fr, mdAtoms, constr, vsite, shellfc); + mdAlgorithmsSetupAtomData(cr, ir, *top_global, &top, fr, &f, mdAtoms, constr, vsite, shellfc); } auto mdatoms = mdAtoms->mdatoms(); diff --git a/src/gromacs/mdrun/shellfc.cpp b/src/gromacs/mdrun/shellfc.cpp index 57d2e66ce4..4eeae2fe78 100644 --- a/src/gromacs/mdrun/shellfc.cpp +++ b/src/gromacs/mdrun/shellfc.cpp @@ -537,7 +537,7 @@ gmx_shellfc_t* init_shell_flexcon(FILE* fplog, const gmx_mtop_t* mtop, int nflex return shfc; } -void make_local_shells(const t_commrec* cr, const t_mdatoms* md, gmx_shellfc_t* shfc) +void gmx::make_local_shells(const t_commrec* cr, const t_mdatoms* md, gmx_shellfc_t* shfc) { int a0, a1; gmx_domdec_t* dd = nullptr; diff --git a/src/gromacs/mdtypes/forcerec.h b/src/gromacs/mdtypes/forcerec.h index 169cb1c153..552580a784 100644 --- a/src/gromacs/mdtypes/forcerec.h +++ b/src/gromacs/mdtypes/forcerec.h @@ -214,11 +214,8 @@ struct t_forcerec /* The number of atoms participating in do_force_lowlevel */ int natoms_force = 0; - /* The number of atoms participating in force and constraints */ + /* The number of atoms participating in force calculation and constraints */ int natoms_force_constr = 0; - /* The allocation size of vectors of size natoms_force */ - int nalloc_force = 0; - /* Forces that should not enter into the coord x force virial summation: * PPPM/PME/Ewald/posres/ForceProviders */ diff --git a/src/gromacs/modularsimulator/topologyholder.cpp b/src/gromacs/modularsimulator/topologyholder.cpp index d51084a243..ed4ba05e07 100644 --- a/src/gromacs/modularsimulator/topologyholder.cpp +++ b/src/gromacs/modularsimulator/topologyholder.cpp @@ -65,8 +65,11 @@ TopologyHolder::TopologyHolder(const gmx_mtop_t& globalTopology, // Generate and initialize new topology // Note that most of the data needed for the constructor is used here - // this function should probably be simplified sooner or later. - mdAlgorithmsSetupAtomData(cr, inputrec, globalTopology, localTopology_.get(), fr, mdAtoms, - constr, vsite, nullptr); + // Note: Legacy mdrun resizes the force buffer in mdAlgorithmsSetupAtomData() + // TopologyHolder has no access to the forces, so we are passing a nullptr + // TODO: Find a unique approach to resizing the forces in modular simulator (#3461) + mdAlgorithmsSetupAtomData(cr, inputrec, globalTopology, localTopology_.get(), fr, nullptr, + mdAtoms, constr, vsite, nullptr); } } diff --git a/src/gromacs/modularsimulator/topologyholder.h b/src/gromacs/modularsimulator/topologyholder.h index 37170225b9..53f03e6599 100644 --- a/src/gromacs/modularsimulator/topologyholder.h +++ b/src/gromacs/modularsimulator/topologyholder.h @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2019, by the GROMACS development team, led by + * Copyright (c) 2019,2020, 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. -- 2.22.0