From: Pascal Merz Date: Tue, 12 Jan 2021 09:36:19 +0000 (+0000) Subject: Make inputrec const at simulator level (leaves some TODOs) X-Git-Url: http://biod.pnpi.spb.ru/gitweb/?a=commitdiff_plain;h=eb46e811a3ec6a0cfe948f33d51496484c2a192d;p=alexxy%2Fgromacs.git Make inputrec const at simulator level (leaves some TODOs) This does not resolve the last few instances that change inputrec, but it makes sure that the intent of inputrec being const is clear, and that future code changes don't easily introduce additional non-const uses of inputrec. See !46 for a similar change targetting the global topology. Refs #3854. --- diff --git a/src/gromacs/mdlib/update_vv.cpp b/src/gromacs/mdlib/update_vv.cpp index 40b99699a8..bd40e9b426 100644 --- a/src/gromacs/mdlib/update_vv.cpp +++ b/src/gromacs/mdlib/update_vv.cpp @@ -4,7 +4,7 @@ * Copyright (c) 1991-2000, University of Groningen, The Netherlands. * Copyright (c) 2001-2004, The GROMACS development team. * Copyright (c) 2013,2014,2015,2016,2017 by the GROMACS development team. - * Copyright (c) 2018,2019,2020, by the GROMACS development team, led by + * Copyright (c) 2018,2019,2020,2021, 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. @@ -75,7 +75,7 @@ void integrateVVFirstStep(int64_t step, bool bInitStep, gmx::StartingBehavior startingBehavior, int nstglobalcomm, - t_inputrec* ir, + const t_inputrec* ir, t_forcerec* fr, t_commrec* cr, t_state* state, @@ -299,7 +299,7 @@ void integrateVVFirstStep(int64_t step, } void integrateVVSecondStep(int64_t step, - t_inputrec* ir, + const t_inputrec* ir, t_forcerec* fr, t_commrec* cr, t_state* state, diff --git a/src/gromacs/mdlib/update_vv.h b/src/gromacs/mdlib/update_vv.h index 8699f6b9ef..9c56cf4927 100644 --- a/src/gromacs/mdlib/update_vv.h +++ b/src/gromacs/mdlib/update_vv.h @@ -4,7 +4,7 @@ * Copyright (c) 1991-2000, University of Groningen, The Netherlands. * Copyright (c) 2001-2004, The GROMACS development team. * Copyright (c) 2013,2014,2015,2016,2017 by the GROMACS development team. - * Copyright (c) 2018,2019,2020, by the GROMACS development team, led by + * Copyright (c) 2018,2019,2020,2021, 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. @@ -123,7 +123,7 @@ void integrateVVFirstStep(int64_t step, bool bInitStep, gmx::StartingBehavior startingBehavior, int nstglobalcomm, - t_inputrec* ir, + const t_inputrec* ir, t_forcerec* fr, t_commrec* cr, t_state* state, @@ -201,7 +201,7 @@ void integrateVVFirstStep(int64_t step, * \param[in] wcycle Wall-clock cycle counter. */ void integrateVVSecondStep(int64_t step, - t_inputrec* ir, + const t_inputrec* ir, t_forcerec* fr, t_commrec* cr, t_state* state, diff --git a/src/gromacs/mdrun/isimulator.h b/src/gromacs/mdrun/isimulator.h index 86ea3279a8..e6957b97fb 100644 --- a/src/gromacs/mdrun/isimulator.h +++ b/src/gromacs/mdrun/isimulator.h @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2019,2020, by the GROMACS development team, led by + * Copyright (c) 2019,2020,2021, 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. @@ -210,8 +210,8 @@ public: IMDOutputProvider* outputProvider; //! Handles notifications to MdModules for checkpoint writing const MdModulesNotifier& mdModulesNotifier; - //! Contains user input mdp options. - t_inputrec* inputrec; + //! Contains user input mdp options. Note: The const-ness is casted away in a few instances, see #3854. + const t_inputrec* inputrec; //! The Interactive Molecular Dynamics session. ImdSession* imdSession; //! The pull work object. diff --git a/src/gromacs/mdrun/md.cpp b/src/gromacs/mdrun/md.cpp index 1d786bc946..94568b39dd 100644 --- a/src/gromacs/mdrun/md.cpp +++ b/src/gromacs/mdrun/md.cpp @@ -3,7 +3,7 @@ * * Copyright (c) 1991-2000, University of Groningen, The Netherlands. * Copyright (c) 2001-2004, The GROMACS development team. - * Copyright (c) 2011-2019,2020, by the GROMACS development team, led by + * Copyright (c) 2011-2019,2020,2021, 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. @@ -162,7 +162,8 @@ void gmx::LegacySimulator::do_md() // alias to avoid a large ripple of nearly useless changes. // t_inputrec is being replaced by IMdpOptionsProvider, so this // will go away eventually. - t_inputrec* ir = inputrec; + const t_inputrec* ir = inputrec; + int64_t step, step_rel; double t, t0 = ir->init_t; gmx_bool bGStatEveryStep, bGStat, bCalcVir, bCalcEnerStep, bCalcEner; @@ -265,9 +266,15 @@ void gmx::LegacySimulator::do_md() int* fep_state = MASTER(cr) ? &state_global->fep_state : nullptr; gmx::ArrayRef lambda = MASTER(cr) ? state_global->lambda : gmx::ArrayRef(); initialize_lambdas(fplog, *ir, MASTER(cr), fep_state, lambda); - Update upd(*ir, deform); - const bool doSimulatedAnnealing = initSimulatedAnnealing(ir, &upd); - const bool useReplicaExchange = (replExParams.exchangeInterval > 0); + Update upd(*ir, deform); + bool doSimulatedAnnealing = false; + { + // TODO: Avoid changing inputrec (#3854) + // Simulated annealing updates the reference temperature. + auto* nonConstInputrec = const_cast(inputrec); + doSimulatedAnnealing = initSimulatedAnnealing(nonConstInputrec, &upd); + } + const bool useReplicaExchange = (replExParams.exchangeInterval > 0); const t_fcdata& fcdata = *fr->fcdata; @@ -905,7 +912,10 @@ void gmx::LegacySimulator::do_md() if (doSimulatedAnnealing) { - update_annealing_target_temp(ir, t, &upd); + // TODO: Avoid changing inputrec (#3854) + // Simulated annealing updates the reference temperature. + auto* nonConstInputrec = const_cast(inputrec); + update_annealing_target_temp(nonConstInputrec, t, &upd); } /* Stop Center of Mass motion */ @@ -1238,9 +1248,20 @@ void gmx::LegacySimulator::do_md() actually move to the new state before outputting statistics, but if performing simulated tempering, we do update the velocities and the tau_t. */ - - lamnew = ExpandedEnsembleDynamics( - fplog, ir, enerd, state, &MassQ, state->fep_state, state->dfhist, step, state->v.rvec_array(), mdatoms); + // TODO: Avoid changing inputrec (#3854) + // Simulated tempering updates the reference temperature. + // Expanded ensemble without simulated tempering does not change the inputrec. + auto* nonConstInputrec = const_cast(inputrec); + lamnew = ExpandedEnsembleDynamics(fplog, + nonConstInputrec, + enerd, + state, + &MassQ, + state->fep_state, + state->dfhist, + step, + state->v.rvec_array(), + mdatoms); /* history is maintained in state->dfhist, but state_global is what is sent to trajectory and log output */ if (MASTER(cr)) { diff --git a/src/gromacs/mdrun/mimic.cpp b/src/gromacs/mdrun/mimic.cpp index adc120d1b2..38d0d6ef33 100644 --- a/src/gromacs/mdrun/mimic.cpp +++ b/src/gromacs/mdrun/mimic.cpp @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2018,2019,2020, by the GROMACS development team, led by + * Copyright (c) 2018,2019,2020,2021, 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. @@ -141,7 +141,7 @@ using gmx::SimulationSignaller; void gmx::LegacySimulator::do_mimic() { - t_inputrec* ir = inputrec; + const t_inputrec* ir = inputrec; int64_t step, step_rel; double t; bool isLastStep = false; @@ -205,8 +205,13 @@ void gmx::LegacySimulator::do_mimic() } /* Settings for rerun */ - ir->nstlist = 1; - ir->nstcalcenergy = 1; + { + // TODO: Avoid changing inputrec (#3854) + auto* nonConstInputrec = const_cast(inputrec); + nonConstInputrec->nstlist = 1; + nonConstInputrec->nstcalcenergy = 1; + nonConstInputrec->nstxout_compressed = 0; + } int nstglobalcomm = 1; const bool bNS = true; @@ -215,10 +220,17 @@ void gmx::LegacySimulator::do_mimic() MimicCommunicator::init(); auto nonConstGlobalTopology = const_cast(top_global); MimicCommunicator::sendInitData(nonConstGlobalTopology, state_global->x); - ir->nsteps = MimicCommunicator::getStepNumber(); + // TODO: Avoid changing inputrec (#3854) + auto* nonConstInputrec = const_cast(inputrec); + nonConstInputrec->nsteps = MimicCommunicator::getStepNumber(); + } + if (DOMAINDECOMP(cr)) + { + // TODO: Avoid changing inputrec (#3854) + auto* nonConstInputrec = const_cast(inputrec); + gmx_bcast(sizeof(ir->nsteps), &nonConstInputrec->nsteps, cr->mpi_comm_mygroup); } - ir->nstxout_compressed = 0; const SimulationGroups* groups = &top_global->groups; { auto nonConstGlobalTopology = const_cast(top_global); @@ -305,7 +317,6 @@ void gmx::LegacySimulator::do_mimic() nullptr, FALSE); shouldCheckNumberOfBondedInteractions = true; - gmx_bcast(sizeof(ir->nsteps), &ir->nsteps, cr->mpi_comm_mygroup); } else { diff --git a/src/gromacs/mdrun/minimize.cpp b/src/gromacs/mdrun/minimize.cpp index c71f86ba1a..988723c0c7 100644 --- a/src/gromacs/mdrun/minimize.cpp +++ b/src/gromacs/mdrun/minimize.cpp @@ -2979,7 +2979,11 @@ void LegacySimulator::do_steep() finish_em(cr, outf, walltime_accounting, wcycle); /* To print the actual number of steps we needed somewhere */ - inputrec->nsteps = count; + { + // TODO: Avoid changing inputrec (#3854) + auto* nonConstInputrec = const_cast(inputrec); + nonConstInputrec->nsteps = count; + } walltime_accounting_set_nsteps_done(walltime_accounting, count); } @@ -3118,7 +3122,11 @@ void LegacySimulator::do_nm() print_em_start(fplog, cr, walltime_accounting, wcycle, NM); /* fudge nr of steps to nr of atoms */ - inputrec->nsteps = atom_index.size() * 2; + { + // TODO: Avoid changing inputrec (#3854) + auto* nonConstInputrec = const_cast(inputrec); + nonConstInputrec->nsteps = atom_index.size() * 2; + } if (bIsMaster) { diff --git a/src/gromacs/mdrun/rerun.cpp b/src/gromacs/mdrun/rerun.cpp index ab974dd8d7..7d97dbe99e 100644 --- a/src/gromacs/mdrun/rerun.cpp +++ b/src/gromacs/mdrun/rerun.cpp @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2018,2019,2020, by the GROMACS development team, led by + * Copyright (c) 2018,2019,2020,2021, 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. @@ -173,7 +173,7 @@ void gmx::LegacySimulator::do_rerun() // alias to avoid a large ripple of nearly useless changes. // t_inputrec is being replaced by IMdpOptionsProvider, so this // will go away eventually. - t_inputrec* ir = inputrec; + const t_inputrec* ir = inputrec; int64_t step, step_rel; double t; bool isLastStep = false; @@ -268,12 +268,16 @@ void gmx::LegacySimulator::do_rerun() } /* Settings for rerun */ - ir->nstlist = 1; - ir->nstcalcenergy = 1; + { + // TODO: Avoid changing inputrec (#3854) + auto* nonConstInputrec = const_cast(inputrec); + nonConstInputrec->nstlist = 1; + nonConstInputrec->nstcalcenergy = 1; + nonConstInputrec->nstxout_compressed = 0; + } int nstglobalcomm = 1; const bool bNS = true; - ir->nstxout_compressed = 0; const SimulationGroups* groups = &top_global->groups; if (ir->eI == eiMimic) { diff --git a/src/gromacs/mdrun/tpi.cpp b/src/gromacs/mdrun/tpi.cpp index 481a361962..f468251ef9 100644 --- a/src/gromacs/mdrun/tpi.cpp +++ b/src/gromacs/mdrun/tpi.cpp @@ -4,7 +4,7 @@ * Copyright (c) 1991-2000, University of Groningen, The Netherlands. * Copyright (c) 2001-2004, The GROMACS development team. * Copyright (c) 2013,2014,2015,2016,2017 by the GROMACS development team. - * Copyright (c) 2018,2019,2020, by the GROMACS development team, led by + * Copyright (c) 2018,2019,2020,2021, 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. @@ -434,8 +434,12 @@ void LegacySimulator::do_tpi() * inserted atoms located in the center of the sphere, so we need * a buffer of size of the sphere and molecule radius. */ - inputrec->rlist = maxCutoff + 2 * inputrec->rtpi + 2 * molRadius; - fr->rlist = inputrec->rlist; + { + // TODO: Avoid changing inputrec (#3854) + auto* nonConstInputrec = const_cast(inputrec); + nonConstInputrec->rlist = maxCutoff + 2 * inputrec->rtpi + 2 * molRadius; + } + fr->rlist = inputrec->rlist; fr->nbv->changePairlistRadii(inputrec->rlist, inputrec->rlist); ngid = groups->groups[SimulationAtomGroupType::EnergyOutput].size();