From b2eb180eefdbda29f2833fd830f8cc7a2aff211f Mon Sep 17 00:00:00 2001 From: Mark Abraham Date: Wed, 8 Nov 2017 12:22:57 +0100 Subject: [PATCH] Prepared t_mdatoms for using vector Wrapped it in another C++ class because the group-scheme kernels compile as plain C and this permits the contained t_mdatoms to be unmodified. The class has responsibility for maintaining the allocations for any of the fields of t_mdatoms that need to be managed with a std::vector plus perhaps an allocator. Change-Id: I6fef70beeb8d43f3e048cec02380f8ebf8153ecb --- src/gromacs/domdec/domdec.cpp | 5 ++- src/gromacs/domdec/domdec.h | 7 +++- src/gromacs/gmxana/gmx_disre.cpp | 7 ++-- src/gromacs/gmxpreprocess/readpull.cpp | 6 +-- src/gromacs/mdlib/integrator.h | 6 +-- src/gromacs/mdlib/mdatoms.cpp | 23 +++++++++-- src/gromacs/mdlib/mdatoms.h | 43 ++++++++++++++++++- src/gromacs/mdlib/mdsetup.cpp | 5 ++- src/gromacs/mdlib/mdsetup.h | 6 +-- src/gromacs/mdlib/minimize.cpp | 75 ++++++++++++++++++---------------- src/gromacs/mdlib/tpi.cpp | 7 ++-- src/programs/mdrun/md.cpp | 12 +++--- src/programs/mdrun/runner.cpp | 17 ++++---- 13 files changed, 145 insertions(+), 74 deletions(-) diff --git a/src/gromacs/domdec/domdec.cpp b/src/gromacs/domdec/domdec.cpp index ee6d4e3e62..adf21588be 100644 --- a/src/gromacs/domdec/domdec.cpp +++ b/src/gromacs/domdec/domdec.cpp @@ -9169,7 +9169,7 @@ void dd_partition_system(FILE *fplog, const t_inputrec *ir, t_state *state_local, PaddedRVecVector *f, - t_mdatoms *mdatoms, + gmx::MDAtoms *mdAtoms, gmx_localtop_t *top_local, t_forcerec *fr, gmx_vsite_t *vsite, @@ -9726,13 +9726,14 @@ void dd_partition_system(FILE *fplog, /* Update atom data for mdatoms and several algorithms */ mdAlgorithmsSetupAtomData(cr, ir, top_global, top_local, fr, - nullptr, mdatoms, vsite, nullptr); + nullptr, mdAtoms, vsite, nullptr); if (ir->implicit_solvent) { make_local_gb(cr, fr->born, ir->gb_algorithm); } + auto mdatoms = mdAtoms->mdatoms(); if (!thisRankHasDuty(cr, DUTY_PME)) { /* Send the charges and/or c6/sigmas to our PME only node */ diff --git a/src/gromacs/domdec/domdec.h b/src/gromacs/domdec/domdec.h index c5d13a2a40..5ae8947eff 100644 --- a/src/gromacs/domdec/domdec.h +++ b/src/gromacs/domdec/domdec.h @@ -82,6 +82,11 @@ struct t_commrec; struct t_inputrec; class t_state; +namespace gmx +{ +class MDAtoms; +} // namespace + /*! \brief Returns the global topology atom number belonging to local atom index i. * * This function is intended for writing ASCII output @@ -319,7 +324,7 @@ void dd_partition_system(FILE *fplog, const t_inputrec *ir, t_state *state_local, PaddedRVecVector *f, - t_mdatoms *mdatoms, + gmx::MDAtoms *mdatoms, gmx_localtop_t *top_local, t_forcerec *fr, gmx_vsite_t *vsite, diff --git a/src/gromacs/gmxana/gmx_disre.cpp b/src/gromacs/gmxana/gmx_disre.cpp index a8c56a57cd..02064f658f 100644 --- a/src/gromacs/gmxana/gmx_disre.cpp +++ b/src/gromacs/gmxana/gmx_disre.cpp @@ -711,7 +711,6 @@ int gmx_disre(int argc, char *argv[]) t_dr_result dr, *dr_clust = nullptr; char **leg; real *vvindex = nullptr, *w_rls = nullptr; - t_mdatoms *mdatoms; t_pbc pbc, *pbc_null; int my_clust; FILE *fplog; @@ -841,9 +840,9 @@ int gmx_disre(int argc, char *argv[]) "Largest Violation", "Time (ps)", "nm", oenv); } - mdatoms = init_mdatoms(fplog, mtop, *ir); - atoms2md(&mtop, ir, -1, nullptr, mtop.natoms, mdatoms); - update_mdatoms(mdatoms, ir->fepvals->init_lambda); + auto mdAtoms = gmx::makeMDAtoms(fplog, mtop, *ir); + atoms2md(&mtop, ir, -1, nullptr, mtop.natoms, mdAtoms.get()); + update_mdatoms(mdAtoms->mdatoms(), ir->fepvals->init_lambda); init_nrnb(&nrnb); if (ir->ePBC != epbcNONE) { diff --git a/src/gromacs/gmxpreprocess/readpull.cpp b/src/gromacs/gmxpreprocess/readpull.cpp index 3d67cb3549..17b9074271 100644 --- a/src/gromacs/gmxpreprocess/readpull.cpp +++ b/src/gromacs/gmxpreprocess/readpull.cpp @@ -508,15 +508,15 @@ pull_t *set_pull_init(t_inputrec *ir, const gmx_mtop_t *mtop, { pull_params_t *pull; pull_t *pull_work; - t_mdatoms *md; t_pbc pbc; int c; double t_start; pull = ir->pull; pull_work = init_pull(nullptr, pull, ir, 0, nullptr, mtop, nullptr, oenv, lambda, FALSE, ContinuationOptions()); - md = init_mdatoms(nullptr, *mtop, *ir); - atoms2md(mtop, ir, -1, nullptr, mtop->natoms, md); + auto mdAtoms = gmx::makeMDAtoms(nullptr, *mtop, *ir); + auto md = mdAtoms->mdatoms(); + atoms2md(mtop, ir, -1, nullptr, mtop->natoms, mdAtoms.get()); if (ir->efep) { update_mdatoms(md, lambda); diff --git a/src/gromacs/mdlib/integrator.h b/src/gromacs/mdlib/integrator.h index 9ac0b81730..272c69797e 100644 --- a/src/gromacs/mdlib/integrator.h +++ b/src/gromacs/mdlib/integrator.h @@ -47,7 +47,6 @@ #include "gromacs/mdlib/vsite.h" #include "gromacs/mdtypes/fcdata.h" #include "gromacs/mdtypes/forcerec.h" -#include "gromacs/mdtypes/mdatom.h" #include "gromacs/timing/wallcycle.h" #include "gromacs/timing/walltime_accounting.h" #include "gromacs/utility/basedefinitions.h" @@ -70,6 +69,7 @@ namespace gmx class IMDOutputProvider; class MDLogger; +class MDAtoms; /*! \brief Integrator algorithm implementation. * @@ -88,7 +88,7 @@ class MDLogger; * \param[in] fcd Force and constraint data * \param[in] state_global The state (x, v, f, box etc.) of the whole system * \param[in] observablesHistory The observables statistics history - * \param[in] mdatoms Structure containing atom information + * \param[in] mdAtoms Atom information * \param[in] nrnb Accounting for floating point operations * \param[in] wcycle Wall cycle timing information * \param[in] fr Force record with cut-off information and more @@ -106,7 +106,7 @@ typedef double integrator_t (FILE *fplog, t_commrec *cr, const gmx::MDLogger &md gmx_mtop_t *top_global, t_fcdata *fcd, t_state *state_global, ObservablesHistory *observablesHistory, - t_mdatoms *mdatoms, + MDAtoms *mdatoms, t_nrnb *nrnb, gmx_wallcycle_t wcycle, t_forcerec *fr, const ReplicaExchangeParameters &replExParams, diff --git a/src/gromacs/mdlib/mdatoms.cpp b/src/gromacs/mdlib/mdatoms.cpp index 56d1ce798b..9f144e27cc 100644 --- a/src/gromacs/mdlib/mdatoms.cpp +++ b/src/gromacs/mdlib/mdatoms.cpp @@ -40,6 +40,9 @@ #include +#include + +#include "gromacs/compat/make_unique.h" #include "gromacs/math/functions.h" #include "gromacs/mdlib/gmx_omp_nthreads.h" #include "gromacs/mdlib/qmmm.h" @@ -54,10 +57,21 @@ #define ALMOST_ZERO 1e-30 -t_mdatoms *init_mdatoms(FILE *fp, const gmx_mtop_t &mtop, const t_inputrec &ir) +namespace gmx +{ + +MDAtoms::MDAtoms() + : mdatoms_(nullptr) { +} + +std::unique_ptr +makeMDAtoms(FILE *fp, const gmx_mtop_t &mtop, const t_inputrec &ir) +{ + auto mdAtoms = compat::make_unique(); t_mdatoms *md; snew(md, 1); + mdAtoms->mdatoms_.reset(md); md->nenergrp = mtop.groups.grps[egcENER].nr; md->bVCMgrps = (mtop.groups.grps[egcVCM].nr > 1); @@ -116,13 +130,15 @@ t_mdatoms *init_mdatoms(FILE *fp, const gmx_mtop_t &mtop, const t_inputrec &ir) md->bOrires = gmx_mtop_ftype_count(&mtop, F_ORIRES); - return md; + return mdAtoms; } +} // namespace + void atoms2md(const gmx_mtop_t *mtop, const t_inputrec *ir, int nindex, const int *index, int homenr, - t_mdatoms *md) + gmx::MDAtoms *mdAtoms) { gmx_bool bLJPME; const t_grpopts *opts; @@ -135,6 +151,7 @@ void atoms2md(const gmx_mtop_t *mtop, const t_inputrec *ir, groups = &mtop->groups; + auto md = mdAtoms->mdatoms(); /* nindex>=0 indicates DD where we use an index */ if (nindex >= 0) { diff --git a/src/gromacs/mdlib/mdatoms.h b/src/gromacs/mdlib/mdatoms.h index 0355e5cad1..21771cbe90 100644 --- a/src/gromacs/mdlib/mdatoms.h +++ b/src/gromacs/mdlib/mdatoms.h @@ -39,19 +39,58 @@ #include +#include +#include + #include "gromacs/mdtypes/mdatom.h" #include "gromacs/utility/basedefinitions.h" #include "gromacs/utility/real.h" +#include "gromacs/utility/unique_cptr.h" struct gmx_mtop_t; struct t_inputrec; -t_mdatoms *init_mdatoms(FILE *fp, const gmx_mtop_t &mtop, const t_inputrec &ir); +namespace gmx +{ + +/*! \libinternal + * \brief Contains a C-style t_mdatoms while permitting future changes + * to manage some of its memory with C++ vectors with allocators. + * + * The group-scheme kernels need to use a plain C-style t_mdatoms, so + * this type combines that with the memory management needed e.g.for + * efficient PME on GPU transfers. + * + * \todo Refactor this class and rename MDAtoms once the group scheme + * is removed. */ +class MDAtoms +{ + //! C-style mdatoms struct. + unique_cptr mdatoms_; + public: + // TODO make this private + //! Constructor. + MDAtoms(); + //! Getter. + t_mdatoms *mdatoms() + { + return mdatoms_.get(); + } + //! Builder function. + friend std::unique_ptr + makeMDAtoms(FILE *fp, const gmx_mtop_t &mtop, const t_inputrec &ir); +}; + +//! Builder function for MdAtomsWrapper. +std::unique_ptr +makeMDAtoms(FILE *fp, const gmx_mtop_t &mtop, const t_inputrec &ir); + +} // namespace void atoms2md(const gmx_mtop_t *mtop, const t_inputrec *ir, int nindex, const int *index, int homenr, - t_mdatoms *md); + gmx::MDAtoms *mdAtoms); /* This routine copies the atoms->atom struct into md. * If index!=NULL only the indexed atoms are copied. * For the masses the A-state (lambda=0) mass is used. diff --git a/src/gromacs/mdlib/mdsetup.cpp b/src/gromacs/mdlib/mdsetup.cpp index 309c20e054..7ab1cb8c5e 100644 --- a/src/gromacs/mdlib/mdsetup.cpp +++ b/src/gromacs/mdlib/mdsetup.cpp @@ -65,7 +65,7 @@ void mdAlgorithmsSetupAtomData(t_commrec *cr, gmx_localtop_t *top, t_forcerec *fr, t_graph **graph, - t_mdatoms *mdatoms, + gmx::MDAtoms *mdAtoms, gmx_vsite_t *vsite, gmx_shellfc_t *shellfc) { @@ -86,8 +86,9 @@ void mdAlgorithmsSetupAtomData(t_commrec *cr, atomIndex = nullptr; numHomeAtoms = top_global->natoms; } - atoms2md(top_global, ir, numAtomIndex, atomIndex, numHomeAtoms, mdatoms); + atoms2md(top_global, ir, numAtomIndex, atomIndex, numHomeAtoms, mdAtoms); + auto mdatoms = mdAtoms->mdatoms(); if (usingDomDec) { dd_sort_local_top(cr->dd, mdatoms, top); diff --git a/src/gromacs/mdlib/mdsetup.h b/src/gromacs/mdlib/mdsetup.h index c261643a04..4f435041da 100644 --- a/src/gromacs/mdlib/mdsetup.h +++ b/src/gromacs/mdlib/mdsetup.h @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2016, by the GROMACS development team, led by + * Copyright (c) 2016,2017, 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. @@ -57,7 +57,7 @@ * \param[in,out] top The local topology * \param[in,out] fr The force calculation parameter/data record * \param[out] graph The molecular graph, can be NULL - * \param[out] mdatoms The MD atom data + * \param[out] mdAtoms The MD atom data * \param[in,out] vsite The virtual site data, can be NULL * \param[in,out] shellfc The shell/flexible-constraint data, can be NULL */ @@ -67,7 +67,7 @@ void mdAlgorithmsSetupAtomData(t_commrec *cr, gmx_localtop_t *top, t_forcerec *fr, t_graph **graph, - t_mdatoms *mdatoms, + gmx::MDAtoms *mdAtoms, gmx_vsite_t *vsite, gmx_shellfc_t *shellfc); diff --git a/src/gromacs/mdlib/minimize.cpp b/src/gromacs/mdlib/minimize.cpp index 52e7b42a61..16c8b2c865 100644 --- a/src/gromacs/mdlib/minimize.cpp +++ b/src/gromacs/mdlib/minimize.cpp @@ -329,7 +329,7 @@ static void init_em(FILE *fplog, const char *title, em_state_t *ems, gmx_localtop_t **top, t_nrnb *nrnb, rvec mu_tot, t_forcerec *fr, gmx_enerdata_t **enerd, - t_graph **graph, t_mdatoms *mdatoms, gmx_global_stat_t *gstat, + t_graph **graph, gmx::MDAtoms *mdAtoms, gmx_global_stat_t *gstat, gmx_vsite_t *vsite, gmx_constr_t constr, gmx_shellfc_t **shellfc, int nfile, const t_filenm fnm[], gmx_mdoutf_t *outf, t_mdebin **mdebin, @@ -380,6 +380,7 @@ static void init_em(FILE *fplog, const char *title, } } + auto mdatoms = mdAtoms->mdatoms(); if (DOMAINDECOMP(cr)) { *top = dd_init_local_top(top_global); @@ -389,7 +390,7 @@ static void init_em(FILE *fplog, const char *title, /* Distribute the charge groups over the nodes from the master node */ dd_partition_system(fplog, ir->init_step, cr, TRUE, 1, state_global, top_global, ir, - &ems->s, &ems->f, mdatoms, *top, + &ems->s, &ems->f, mdAtoms, *top, fr, vsite, constr, nrnb, nullptr, FALSE); dd_store_state(cr->dd, &ems->s); @@ -409,7 +410,7 @@ static void init_em(FILE *fplog, const char *title, snew(*top, 1); mdAlgorithmsSetupAtomData(cr, ir, top_global, *top, fr, - graph, mdatoms, + graph, mdAtoms, vsite, shellfc ? *shellfc : nullptr); if (vsite) @@ -418,7 +419,7 @@ static void init_em(FILE *fplog, const char *title, } } - update_mdatoms(mdatoms, ems->s.lambda[efptMASS]); + update_mdatoms(mdAtoms->mdatoms(), ems->s.lambda[efptMASS]); if (constr) { @@ -694,7 +695,7 @@ static bool do_em_step(t_commrec *cr, t_inputrec *ir, t_mdatoms *md, static void em_dd_partition_system(FILE *fplog, int step, t_commrec *cr, gmx_mtop_t *top_global, t_inputrec *ir, em_state_t *ems, gmx_localtop_t *top, - t_mdatoms *mdatoms, t_forcerec *fr, + gmx::MDAtoms *mdAtoms, t_forcerec *fr, gmx_vsite_t *vsite, gmx_constr_t constr, t_nrnb *nrnb, gmx_wallcycle_t wcycle) { @@ -702,7 +703,7 @@ static void em_dd_partition_system(FILE *fplog, int step, t_commrec *cr, dd_partition_system(fplog, step, cr, FALSE, 1, nullptr, top_global, ir, &ems->s, &ems->f, - mdatoms, top, fr, vsite, constr, + mdAtoms, top, fr, vsite, constr, nrnb, wcycle, FALSE); dd_store_state(cr->dd, &ems->s); } @@ -716,7 +717,7 @@ static void evaluate_energy(FILE *fplog, t_commrec *cr, gmx_global_stat_t gstat, gmx_vsite_t *vsite, gmx_constr_t constr, t_fcdata *fcd, - t_graph *graph, t_mdatoms *mdatoms, + t_graph *graph, gmx::MDAtoms *mdAtoms, t_forcerec *fr, rvec mu_tot, gmx_enerdata_t *enerd, tensor vir, tensor pres, gmx_int64_t count, gmx_bool bFirst) @@ -756,7 +757,7 @@ static void evaluate_energy(FILE *fplog, t_commrec *cr, { /* Repartition the domain decomposition */ em_dd_partition_system(fplog, count, cr, top_global, inputrec, - ems, top, mdatoms, fr, vsite, constr, + ems, top, mdAtoms, fr, vsite, constr, nrnb, wcycle); } @@ -767,7 +768,7 @@ static void evaluate_energy(FILE *fplog, t_commrec *cr, do_force(fplog, cr, inputrec, count, nrnb, wcycle, top, &top_global->groups, ems->s.box, &ems->s.x, &ems->s.hist, - &ems->f, force_vir, mdatoms, enerd, fcd, + &ems->f, force_vir, mdAtoms->mdatoms(), enerd, fcd, ems->s.lambda, graph, fr, vsite, mu_tot, t, nullptr, TRUE, GMX_FORCE_STATECHANGED | GMX_FORCE_ALLFORCES | GMX_FORCE_VIRIAL | GMX_FORCE_ENERGY | @@ -815,7 +816,7 @@ static void evaluate_energy(FILE *fplog, t_commrec *cr, dvdl_constr = 0; rvec *f_rvec = as_rvec_array(ems->f.data()); constrain(nullptr, FALSE, FALSE, constr, &top->idef, - inputrec, cr, count, 0, 1.0, mdatoms, + inputrec, cr, count, 0, 1.0, mdAtoms->mdatoms(), as_rvec_array(ems->s.x.data()), f_rvec, f_rvec, fr->bMolPBC, ems->s.box, ems->s.lambda[efptBONDED], &dvdl_constr, @@ -837,7 +838,7 @@ static void evaluate_energy(FILE *fplog, t_commrec *cr, if (EI_ENERGY_MINIMIZATION(inputrec->eI)) { - get_state_f_norm_max(cr, &(inputrec->opts), mdatoms, ems); + get_state_f_norm_max(cr, &(inputrec->opts), mdAtoms->mdatoms(), ems); } } @@ -983,7 +984,7 @@ namespace gmx t_inputrec *inputrec, gmx_mtop_t *top_global, t_fcdata *fcd, t_state *state_global, - t_mdatoms *mdatoms, + gmx::MDAtoms *mdAtoms, t_nrnb *nrnb, gmx_wallcycle_t wcycle, gmx_edsam_t ed, t_forcerec *fr, @@ -1001,7 +1002,7 @@ double do_cg(FILE *fplog, t_commrec *cr, const gmx::MDLogger gmx_unused &mdlog, gmx_mtop_t *top_global, t_fcdata *fcd, t_state *state_global, ObservablesHistory *observablesHistory, - t_mdatoms *mdatoms, + gmx::MDAtoms *mdAtoms, t_nrnb *nrnb, gmx_wallcycle_t wcycle, t_forcerec *fr, const ReplicaExchangeParameters gmx_unused &replExParams, @@ -1027,6 +1028,7 @@ double do_cg(FILE *fplog, t_commrec *cr, const gmx::MDLogger gmx_unused &mdlog, int number_steps, neval = 0, nstcg = inputrec->nstcgsteep; gmx_mdoutf_t outf; int m, step, nminstep; + auto mdatoms = mdAtoms->mdatoms(); step = 0; @@ -1043,7 +1045,7 @@ double do_cg(FILE *fplog, t_commrec *cr, const gmx::MDLogger gmx_unused &mdlog, /* Init em and store the local state in s_min */ init_em(fplog, CG, cr, outputProvider, inputrec, mdrunOptions, state_global, top_global, s_min, &top, - nrnb, mu_tot, fr, &enerd, &graph, mdatoms, &gstat, + nrnb, mu_tot, fr, &enerd, &graph, mdAtoms, &gstat, vsite, constr, nullptr, nfile, fnm, &outf, &mdebin, wcycle); @@ -1069,7 +1071,7 @@ double do_cg(FILE *fplog, t_commrec *cr, const gmx::MDLogger gmx_unused &mdlog, evaluate_energy(fplog, cr, top_global, s_min, top, inputrec, nrnb, wcycle, gstat, - vsite, constr, fcd, graph, mdatoms, fr, + vsite, constr, fcd, graph, mdAtoms, fr, mu_tot, enerd, vir, pres, -1, TRUE); where(); @@ -1234,7 +1236,7 @@ double do_cg(FILE *fplog, t_commrec *cr, const gmx::MDLogger gmx_unused &mdlog, if (DOMAINDECOMP(cr) && s_min->s.ddp_count < cr->dd->ddp_count) { em_dd_partition_system(fplog, step, cr, top_global, inputrec, - s_min, top, mdatoms, fr, vsite, constr, + s_min, top, mdAtoms, fr, vsite, constr, nrnb, wcycle); } @@ -1247,7 +1249,7 @@ double do_cg(FILE *fplog, t_commrec *cr, const gmx::MDLogger gmx_unused &mdlog, evaluate_energy(fplog, cr, top_global, s_c, top, inputrec, nrnb, wcycle, gstat, - vsite, constr, fcd, graph, mdatoms, fr, + vsite, constr, fcd, graph, mdAtoms, fr, mu_tot, enerd, vir, pres, -1, FALSE); /* Calc derivative along line */ @@ -1343,7 +1345,7 @@ double do_cg(FILE *fplog, t_commrec *cr, const gmx::MDLogger gmx_unused &mdlog, { /* Reload the old state */ em_dd_partition_system(fplog, -1, cr, top_global, inputrec, - s_min, top, mdatoms, fr, vsite, constr, + s_min, top, mdAtoms, fr, vsite, constr, nrnb, wcycle); } @@ -1356,7 +1358,7 @@ double do_cg(FILE *fplog, t_commrec *cr, const gmx::MDLogger gmx_unused &mdlog, evaluate_energy(fplog, cr, top_global, s_b, top, inputrec, nrnb, wcycle, gstat, - vsite, constr, fcd, graph, mdatoms, fr, + vsite, constr, fcd, graph, mdAtoms, fr, mu_tot, enerd, vir, pres, -1, FALSE); /* p does not change within a step, but since the domain decomposition @@ -1627,7 +1629,7 @@ double do_cg(FILE *fplog, t_commrec *cr, const gmx::MDLogger gmx_unused &mdlog, t_inputrec *inputrec, gmx_mtop_t *top_global, t_fcdata *fcd, t_state *state_global, - t_mdatoms *mdatoms, + gmx::MDAtoms *mdAtoms, t_nrnb *nrnb, gmx_wallcycle_t wcycle, gmx_edsam_t ed, t_forcerec *fr, @@ -1645,7 +1647,7 @@ double do_lbfgs(FILE *fplog, t_commrec *cr, const gmx::MDLogger gmx_unused &mdlo gmx_mtop_t *top_global, t_fcdata *fcd, t_state *state_global, ObservablesHistory *observablesHistory, - t_mdatoms *mdatoms, + gmx::MDAtoms *mdAtoms, t_nrnb *nrnb, gmx_wallcycle_t wcycle, t_forcerec *fr, const ReplicaExchangeParameters gmx_unused &replExParams, @@ -1673,6 +1675,7 @@ double do_lbfgs(FILE *fplog, t_commrec *cr, const gmx::MDLogger gmx_unused &mdlo gmx_mdoutf_t outf; int i, k, m, n, gf, step; int mdof_flags; + auto mdatoms = mdAtoms->mdatoms(); if (PAR(cr)) { @@ -1711,7 +1714,7 @@ double do_lbfgs(FILE *fplog, t_commrec *cr, const gmx::MDLogger gmx_unused &mdlo /* Init em */ init_em(fplog, LBFGS, cr, outputProvider, inputrec, mdrunOptions, state_global, top_global, &ems, &top, - nrnb, mu_tot, fr, &enerd, &graph, mdatoms, &gstat, + nrnb, mu_tot, fr, &enerd, &graph, mdAtoms, &gstat, vsite, constr, nullptr, nfile, fnm, &outf, &mdebin, wcycle); @@ -1774,7 +1777,7 @@ double do_lbfgs(FILE *fplog, t_commrec *cr, const gmx::MDLogger gmx_unused &mdlo evaluate_energy(fplog, cr, top_global, &ems, top, inputrec, nrnb, wcycle, gstat, - vsite, constr, fcd, graph, mdatoms, fr, + vsite, constr, fcd, graph, mdAtoms, fr, mu_tot, enerd, vir, pres, -1, TRUE); where(); @@ -1980,7 +1983,7 @@ double do_lbfgs(FILE *fplog, t_commrec *cr, const gmx::MDLogger gmx_unused &mdlo evaluate_energy(fplog, cr, top_global, sc, top, inputrec, nrnb, wcycle, gstat, - vsite, constr, fcd, graph, mdatoms, fr, + vsite, constr, fcd, graph, mdAtoms, fr, mu_tot, enerd, vir, pres, step, FALSE); // Calc line gradient in position C @@ -2071,7 +2074,7 @@ double do_lbfgs(FILE *fplog, t_commrec *cr, const gmx::MDLogger gmx_unused &mdlo evaluate_energy(fplog, cr, top_global, sb, top, inputrec, nrnb, wcycle, gstat, - vsite, constr, fcd, graph, mdatoms, fr, + vsite, constr, fcd, graph, mdAtoms, fr, mu_tot, enerd, vir, pres, step, FALSE); fnorm = sb->fnorm; @@ -2392,7 +2395,7 @@ double do_lbfgs(FILE *fplog, t_commrec *cr, const gmx::MDLogger gmx_unused &mdlo t_inputrec *inputrec, gmx_mtop_t *top_global, t_fcdata *fcd, t_state *state_global, - t_mdatoms *mdatoms, + gmx::MDAtoms *mdAtoms, t_nrnb *nrnb, gmx_wallcycle_t wcycle, gmx_edsam_t ed, t_forcerec *fr, @@ -2409,7 +2412,7 @@ double do_steep(FILE *fplog, t_commrec *cr, const gmx::MDLogger gmx_unused &mdlo gmx_mtop_t *top_global, t_fcdata *fcd, t_state *state_global, ObservablesHistory *observablesHistory, - t_mdatoms *mdatoms, + gmx::MDAtoms *mdAtoms, t_nrnb *nrnb, gmx_wallcycle_t wcycle, t_forcerec *fr, const ReplicaExchangeParameters gmx_unused &replExParams, @@ -2431,6 +2434,7 @@ double do_steep(FILE *fplog, t_commrec *cr, const gmx::MDLogger gmx_unused &mdlo int nsteps; int count = 0; int steps_accepted = 0; + auto mdatoms = mdAtoms->mdatoms(); /* Create 2 states on the stack and extract pointers that we will swap */ em_state_t s0 {}, s1 {}; @@ -2440,7 +2444,7 @@ double do_steep(FILE *fplog, t_commrec *cr, const gmx::MDLogger gmx_unused &mdlo /* Init em and store the local state in s_try */ init_em(fplog, SD, cr, outputProvider, inputrec, mdrunOptions, state_global, top_global, s_try, &top, - nrnb, mu_tot, fr, &enerd, &graph, mdatoms, &gstat, + nrnb, mu_tot, fr, &enerd, &graph, mdAtoms, &gstat, vsite, constr, nullptr, nfile, fnm, &outf, &mdebin, wcycle); @@ -2494,7 +2498,7 @@ double do_steep(FILE *fplog, t_commrec *cr, const gmx::MDLogger gmx_unused &mdlo evaluate_energy(fplog, cr, top_global, s_try, top, inputrec, nrnb, wcycle, gstat, - vsite, constr, fcd, graph, mdatoms, fr, + vsite, constr, fcd, graph, mdAtoms, fr, mu_tot, enerd, vir, pres, count, count == 0); } else @@ -2580,7 +2584,7 @@ double do_steep(FILE *fplog, t_commrec *cr, const gmx::MDLogger gmx_unused &mdlo { /* Reload the old state */ em_dd_partition_system(fplog, count, cr, top_global, inputrec, - s_min, top, mdatoms, fr, vsite, constr, + s_min, top, mdAtoms, fr, vsite, constr, nrnb, wcycle); } } @@ -2657,7 +2661,7 @@ double do_steep(FILE *fplog, t_commrec *cr, const gmx::MDLogger gmx_unused &mdlo t_inputrec *inputrec, gmx_mtop_t *top_global, t_fcdata *fcd, t_state *state_global, - t_mdatoms *mdatoms, + gmx::MDAtoms *mdAtoms, t_nrnb *nrnb, gmx_wallcycle_t wcycle, gmx_edsam_t ed, t_forcerec *fr, @@ -2674,7 +2678,7 @@ double do_nm(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog, gmx_mtop_t *top_global, t_fcdata *fcd, t_state *state_global, ObservablesHistory gmx_unused *observablesHistory, - t_mdatoms *mdatoms, + gmx::MDAtoms *mdAtoms, t_nrnb *nrnb, gmx_wallcycle_t wcycle, t_forcerec *fr, const ReplicaExchangeParameters gmx_unused &replExParams, @@ -2701,6 +2705,7 @@ double do_nm(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog, real der_range = 10.0*sqrt(GMX_REAL_EPS); real x_min; bool bIsMaster = MASTER(cr); + auto mdatoms = mdAtoms->mdatoms(); if (constr != nullptr) { @@ -2714,7 +2719,7 @@ double do_nm(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog, /* Init em and store the local state in state_minimum */ init_em(fplog, NM, cr, outputProvider, inputrec, mdrunOptions, state_global, top_global, &state_work, &top, - nrnb, mu_tot, fr, &enerd, &graph, mdatoms, &gstat, + nrnb, mu_tot, fr, &enerd, &graph, mdAtoms, &gstat, vsite, constr, &shellfc, nfile, fnm, &outf, nullptr, wcycle); @@ -2794,7 +2799,7 @@ double do_nm(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog, evaluate_energy(fplog, cr, top_global, &state_work, top, inputrec, nrnb, wcycle, gstat, - vsite, constr, fcd, graph, mdatoms, fr, + vsite, constr, fcd, graph, mdAtoms, fr, mu_tot, enerd, vir, pres, -1, TRUE); cr->nnodes = nnodes; @@ -2868,7 +2873,7 @@ double do_nm(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog, evaluate_energy(fplog, cr, top_global, &state_work, top, inputrec, nrnb, wcycle, gstat, - vsite, constr, fcd, graph, mdatoms, fr, + vsite, constr, fcd, graph, mdAtoms, fr, mu_tot, enerd, vir, pres, atom*2+dx, FALSE); } diff --git a/src/gromacs/mdlib/tpi.cpp b/src/gromacs/mdlib/tpi.cpp index 5a68205f35..5ea806f661 100644 --- a/src/gromacs/mdlib/tpi.cpp +++ b/src/gromacs/mdlib/tpi.cpp @@ -136,7 +136,7 @@ namespace gmx t_inputrec *inputrec, gmx_mtop_t *top_global, t_fcdata *fcd, t_state *state_global, - t_mdatoms *mdatoms, + gmx::MDAtoms *mdAtoms, t_nrnb *nrnb, gmx_wallcycle_t wcycle, gmx_edsam_t ed, t_forcerec *fr, @@ -154,7 +154,7 @@ double do_tpi(FILE *fplog, t_commrec *cr, const gmx::MDLogger gmx_unused &mdlog, gmx_mtop_t *top_global, t_fcdata *fcd, t_state *state_global, ObservablesHistory gmx_unused *observablesHistory, - t_mdatoms *mdatoms, + gmx::MDAtoms *mdAtoms, t_nrnb *nrnb, gmx_wallcycle_t wcycle, t_forcerec *fr, const ReplicaExchangeParameters gmx_unused &replExParams, @@ -190,6 +190,7 @@ double do_tpi(FILE *fplog, t_commrec *cr, const gmx::MDLogger gmx_unused &mdlog, real prescorr, enercorr, dvdlcorr; gmx_bool bEnergyOutOfBounds; const char *tpid_leg[2] = {"direct", "reweighted"}; + auto mdatoms = mdAtoms->mdatoms(); GMX_UNUSED_VALUE(outputProvider); @@ -282,7 +283,7 @@ double do_tpi(FILE *fplog, t_commrec *cr, const gmx::MDLogger gmx_unused &mdlog, sscanf(dump_pdb, "%20lf", &dump_ener); } - atoms2md(top_global, inputrec, -1, nullptr, top_global->natoms, mdatoms); + atoms2md(top_global, inputrec, -1, nullptr, top_global->natoms, mdAtoms); update_mdatoms(mdatoms, inputrec->fepvals->init_lambda); snew(enerd, 1); diff --git a/src/programs/mdrun/md.cpp b/src/programs/mdrun/md.cpp index 3903d3091f..0885f1e3ee 100644 --- a/src/programs/mdrun/md.cpp +++ b/src/programs/mdrun/md.cpp @@ -304,7 +304,7 @@ double gmx::do_md(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog, t_fcdata *fcd, t_state *state_global, ObservablesHistory *observablesHistory, - t_mdatoms *mdatoms, + gmx::MDAtoms *mdAtoms, t_nrnb *nrnb, gmx_wallcycle_t wcycle, t_forcerec *fr, const ReplicaExchangeParameters &replExParams, @@ -525,7 +525,7 @@ double gmx::do_md(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog, snew(top, 1); mdAlgorithmsSetupAtomData(cr, ir, top_global, top, fr, - &graph, mdatoms, vsite, shellfc); + &graph, mdAtoms, vsite, shellfc); update_realloc(upd, state->natoms); } @@ -539,13 +539,15 @@ double gmx::do_md(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog, /* Distribute the charge groups over the nodes from the master node */ dd_partition_system(fplog, ir->init_step, cr, TRUE, 1, state_global, top_global, ir, - state, &f, mdatoms, top, fr, + state, &f, mdAtoms, top, fr, vsite, constr, nrnb, nullptr, FALSE); shouldCheckNumberOfBondedInteractions = true; update_realloc(upd, state->natoms); } + auto mdatoms = mdAtoms->mdatoms(); + // NOTE: The global state is no longer used at this point. // But state_global is still used as temporary storage space for writing // the global state to file and potentially for replica exchange. @@ -1068,7 +1070,7 @@ double gmx::do_md(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog, dd_partition_system(fplog, step, cr, bMasterState, nstglobalcomm, state_global, top_global, ir, - state, &f, mdatoms, top, fr, + state, &f, mdAtoms, top, fr, vsite, constr, nrnb, wcycle, do_verbose && !bPMETunePrinting); @@ -1802,7 +1804,7 @@ double gmx::do_md(FILE *fplog, t_commrec *cr, const gmx::MDLogger &mdlog, { dd_partition_system(fplog, step, cr, TRUE, 1, state_global, top_global, ir, - state, &f, mdatoms, top, fr, + state, &f, mdAtoms, top, fr, vsite, constr, nrnb, wcycle, FALSE); shouldCheckNumberOfBondedInteractions = true; diff --git a/src/programs/mdrun/runner.cpp b/src/programs/mdrun/runner.cpp index 2e4b7237cc..d9f098c591 100644 --- a/src/programs/mdrun/runner.cpp +++ b/src/programs/mdrun/runner.cpp @@ -437,7 +437,6 @@ int Mdrunner::mdrunner() int npme_major, npme_minor; t_nrnb *nrnb; gmx_mtop_t *mtop = nullptr; - t_mdatoms *mdatoms = nullptr; t_forcerec *fr = nullptr; t_fcdata *fcd = nullptr; real ewaldcoeff_q = 0; @@ -977,6 +976,8 @@ int Mdrunner::mdrunner() membed = init_membed(fplog, nfile, fnm, mtop, inputrec, globalState.get(), cr, &mdrunOptions.checkpointOptions.period); } + std::unique_ptr mdAtoms; + snew(nrnb, 1); if (thisRankHasDuty(cr, DUTY_PP)) { @@ -998,11 +999,11 @@ int Mdrunner::mdrunner() init_QMMMrec(cr, mtop, inputrec, fr); } - /* Initialize the mdatoms structure. - * mdatoms is not filled with atom data, + /* Initialize the mdAtoms structure. + * mdAtoms is not filled with atom data, * as this can not be done now with domain decomposition. */ - mdatoms = init_mdatoms(fplog, *mtop, *inputrec); + mdAtoms = makeMDAtoms(fplog, *mtop, *inputrec); /* Initialize the virtual site communication */ vsite = initVsite(*mtop, cr); @@ -1081,12 +1082,12 @@ int Mdrunner::mdrunner() * either on all nodes or on dedicated PME nodes only. */ if (EEL_PME(inputrec->coulombtype) || EVDW_PME(inputrec->vdwtype)) { - if (mdatoms) + if (mdAtoms && mdAtoms->mdatoms()) { - nChargePerturbed = mdatoms->nChargePerturbed; + nChargePerturbed = mdAtoms->mdatoms()->nChargePerturbed; if (EVDW_PME(inputrec->vdwtype)) { - nTypePerturbed = mdatoms->nTypePerturbed; + nTypePerturbed = mdAtoms->mdatoms()->nTypePerturbed; } } if (cr->npmenodes > 0) @@ -1172,7 +1173,7 @@ int Mdrunner::mdrunner() fcd, globalState.get(), &observablesHistory, - mdatoms, nrnb, wcycle, fr, + mdAtoms.get(), nrnb, wcycle, fr, replExParams, membed, walltime_accounting); -- 2.11.4.GIT