/*
* 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.
}
}
-static void dd_distribute_state(gmx_domdec_t* dd,
- const t_state* state,
- t_state* state_local,
- PaddedHostVector<gmx::RVec>* f)
+static void dd_distribute_state(gmx_domdec_t* dd, const t_state* state, t_state* state_local)
{
int nh = state_local->nhchainlength;
/* 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))
{
}
}
-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<gmx::RVec>* 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);
}
/*
* 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.
#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;
}
/*! \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<gmx::RVec>* 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
#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<RVec>* 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();
constr->setConstraints(top, *mdatoms);
}
}
+
+} // namespace gmx
#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;
{
class Constraints;
class MDAtoms;
-} // namespace gmx
/*! \brief Gets the local shell with domain decomposition
*
* \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<RVec>* force,
+ MDAtoms* mdAtoms,
+ Constraints* constr,
+ gmx_vsite_t* vsite,
+ gmx_shellfc_t* shellfc);
+
+} // namespace gmx
#endif
}
//! 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<gmx::RVec>* 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;
ddSendrecv<int>(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<gmx::RVec> rvecBufferRef;
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());
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");
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();
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);
*/
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)
{
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))
/*
* 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.
}
}
-void dd_redistribute_cg(FILE* fplog,
- int64_t step,
- gmx_domdec_t* dd,
- ivec tric_dir,
- t_state* state,
- PaddedHostVector<gmx::RVec>* 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;
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;
/*
* 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.
#include <cstdio>
-#include "gromacs/gpu_utils/hostallocator.h"
+#include "gromacs/math/vectypes.h"
#include "gromacs/utility/basedefinitions.h"
struct gmx_domdec_t;
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<gmx::RVec>* 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
/*
* 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.
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<gmx::RVec>* 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<gmx::RVec>* 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);
}
/*
* 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.
#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"
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<gmx::RVec>* 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<gmx::RVec>* 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)
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);
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;
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);
}
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();
/* 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)
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();
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;
/* 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
*/
// 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);
}
}
/*
* 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.