From 433b06b427c56a2fa9aec32b34770a2774bc4389 Mon Sep 17 00:00:00 2001 From: Joe Jordan Date: Fri, 19 Mar 2021 10:50:48 +0000 Subject: [PATCH] Use ArrayRef in ewald_LRcorrection This will make refactoring t_mdatoms easier. Also changed signatures of calculateLongRangeNonbondeds to use more ArrayRef. --- src/gromacs/ewald/long_range_correction.cpp | 38 +++++++++---------- src/gromacs/ewald/long_range_correction.h | 42 +++++++++++---------- src/gromacs/mdlib/force.cpp | 37 +++++++++--------- src/gromacs/mdlib/force.h | 4 +- src/gromacs/mdlib/sim_util.cpp | 4 +- 5 files changed, 64 insertions(+), 61 deletions(-) diff --git a/src/gromacs/ewald/long_range_correction.cpp b/src/gromacs/ewald/long_range_correction.cpp index ce2625717c..b5791ead47 100644 --- a/src/gromacs/ewald/long_range_correction.cpp +++ b/src/gromacs/ewald/long_range_correction.cpp @@ -64,22 +64,22 @@ * perturbations. The parameter vectors for LJ-PME are likewise * undefined when LJ-PME is not active. This works because * bHaveChargeOrTypePerturbed handles the control flow. */ -void ewald_LRcorrection(const int numAtomsLocal, - const t_commrec* cr, - int numThreads, - int thread, - const t_forcerec& fr, - const t_inputrec& ir, - const real* chargeA, - const real* chargeB, - gmx_bool bHaveChargePerturbed, - const rvec x[], - const matrix box, - const rvec mu_tot[], - rvec* f, - real* Vcorr_q, - real lambda_q, - real* dvdlambda_q) +void ewald_LRcorrection(const int numAtomsLocal, + const t_commrec* cr, + int numThreads, + int thread, + const t_forcerec& fr, + const t_inputrec& ir, + gmx::ArrayRef chargeA, + gmx::ArrayRef chargeB, + bool bHaveChargePerturbed, + gmx::ArrayRef x, + const matrix box, + gmx::ArrayRef mu_tot, + gmx::ArrayRef f, + real* Vcorr_q, + real lambda_q, + real* dvdlambda_q) { /* We need to correct only self interactions */ const int start = (numAtomsLocal * thread) / numThreads; @@ -211,11 +211,11 @@ void ewald_LRcorrection(const int numAtomsLocal, * We could implement a reduction over threads, * but this case is rarely used. */ - const real* qPtr = (q == 0 ? chargeA : chargeB); - real sumQZ2 = 0; + gmx::ArrayRef charge = (q == 0 ? chargeA : chargeB); + real sumQZ2 = 0; for (int i = 0; i < numAtomsLocal; i++) { - sumQZ2 += qPtr[i] * x[i][ZZ] * x[i][ZZ]; + sumQZ2 += charge[i] * x[i][ZZ] * x[i][ZZ]; } Vdipole[q] -= dipole_coeff * fr.qsum[q] * (sumQZ2 + fr.qsum[q] * box[ZZ][ZZ] * box[ZZ][ZZ] / 12); diff --git a/src/gromacs/ewald/long_range_correction.h b/src/gromacs/ewald/long_range_correction.h index df0a740569..f6fb0c5e8c 100644 --- a/src/gromacs/ewald/long_range_correction.h +++ b/src/gromacs/ewald/long_range_correction.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. @@ -52,33 +52,37 @@ #define GMX_EWALD_LONG_RANGE_CORRECTION_H #include "gromacs/math/vectypes.h" -#include "gromacs/topology/block.h" -#include "gromacs/utility/basedefinitions.h" #include "gromacs/utility/real.h" struct t_commrec; struct t_forcerec; struct t_inputrec; +namespace gmx +{ +template +class ArrayRef; +} + /*! \brief Calculate long-range Ewald correction terms. * * Calculate correction for electrostatic surface dipole terms. */ -void ewald_LRcorrection(int numAtomsLocal, - const t_commrec* cr, - int numThreads, - int thread, - const t_forcerec& fr, - const t_inputrec& ir, - const real* chargeA, - const real* chargeB, - gmx_bool bHaveChargePerturbed, - const rvec x[], - const matrix box, - const rvec mu_tot[], - rvec* f, - real* Vcorr_q, - real lambda_q, - real* dvdlambda_q); +void ewald_LRcorrection(int numAtomsLocal, + const t_commrec* cr, + int numThreads, + int thread, + const t_forcerec& fr, + const t_inputrec& ir, + gmx::ArrayRef chargeA, + gmx::ArrayRef chargeB, + bool bHaveChargePerturbed, + gmx::ArrayRef x, + const matrix box, + gmx::ArrayRef mu_tot, + gmx::ArrayRef f, + real* Vcorr_q, + real lambda_q, + real* dvdlambda_q); #endif diff --git a/src/gromacs/mdlib/force.cpp b/src/gromacs/mdlib/force.cpp index ad4f2f27d1..a598288f34 100644 --- a/src/gromacs/mdlib/force.cpp +++ b/src/gromacs/mdlib/force.cpp @@ -100,20 +100,20 @@ static void reduceEwaldThreadOuput(int nthreads, ewald_corr_thread_t* ewc_t) } } -void calculateLongRangeNonbondeds(t_forcerec* fr, - const t_inputrec& ir, - const t_commrec* cr, - t_nrnb* nrnb, - gmx_wallcycle_t wcycle, - const t_mdatoms* md, - gmx::ArrayRef coordinates, - gmx::ForceWithVirial* forceWithVirial, - gmx_enerdata_t* enerd, - const matrix box, - const real* lambda, - const rvec* mu_tot, - const gmx::StepWorkload& stepWork, - const DDBalanceRegionHandler& ddBalanceRegionHandler) +void calculateLongRangeNonbondeds(t_forcerec* fr, + const t_inputrec& ir, + const t_commrec* cr, + t_nrnb* nrnb, + gmx_wallcycle_t wcycle, + const t_mdatoms* md, + gmx::ArrayRef coordinates, + gmx::ForceWithVirial* forceWithVirial, + gmx_enerdata_t* enerd, + const matrix box, + gmx::ArrayRef lambda, + gmx::ArrayRef mu_tot, + const gmx::StepWorkload& stepWork, + const DDBalanceRegionHandler& ddBalanceRegionHandler) { const bool computePmeOnCpu = (EEL_PME(fr->ic->eeltype) || EVDW_PME(fr->ic->vdwtype)) && thisRankHasDuty(cr, DUTY_PME) @@ -160,7 +160,6 @@ void calculateLongRangeNonbondeds(t_forcerec* fr, * exclusion forces) are calculated, so we can store * the forces in the normal, single forceWithVirial->force_ array. */ - const rvec* x = as_rvec_array(coordinates.data()); ewald_LRcorrection( md->homenr, cr, @@ -168,13 +167,13 @@ void calculateLongRangeNonbondeds(t_forcerec* fr, t, *fr, ir, - md->chargeA, - md->chargeB, + gmx::constArrayRefFromArray(md->chargeA, md->nr), + gmx::constArrayRefFromArray(md->chargeB, md->nr), (md->nChargePerturbed != 0), - x, + coordinates, box, mu_tot, - as_rvec_array(forceWithVirial->force_.data()), + forceWithVirial->force_, &ewc_t.Vcorr_q, lambda[static_cast(FreeEnergyPerturbationCouplingType::Coul)], &ewc_t.dvdl[FreeEnergyPerturbationCouplingType::Coul]); diff --git a/src/gromacs/mdlib/force.h b/src/gromacs/mdlib/force.h index 6f795d0205..a25a42d6c2 100644 --- a/src/gromacs/mdlib/force.h +++ b/src/gromacs/mdlib/force.h @@ -143,8 +143,8 @@ void calculateLongRangeNonbondeds(t_forcerec* fr, gmx::ForceWithVirial* forceWithVirial, gmx_enerdata_t* enerd, const matrix box, - const real* lambda, - const rvec* mu_tot, + gmx::ArrayRef lambda, + gmx::ArrayRef mu_tot, const gmx::StepWorkload& stepWork, const DDBalanceRegionHandler& ddBalanceRegionHandler); diff --git a/src/gromacs/mdlib/sim_util.cpp b/src/gromacs/mdlib/sim_util.cpp index 55b94a7abb..5208ffc5c1 100644 --- a/src/gromacs/mdlib/sim_util.cpp +++ b/src/gromacs/mdlib/sim_util.cpp @@ -1886,8 +1886,8 @@ void do_force(FILE* fplog, &forceOutMtsLevel1->forceWithVirial(), enerd, box, - lambda.data(), - as_rvec_array(dipoleData.muStateAB), + lambda, + dipoleData.muStateAB, stepWork, ddBalanceRegionHandler); } -- 2.22.0