From 23275a72d48ea28c0ae1558d597c55440ce28c9b Mon Sep 17 00:00:00 2001 From: Mark Abraham Date: Mon, 31 May 2021 08:14:35 +0000 Subject: [PATCH] Partial renaming of cginfo to atom info --- src/gromacs/domdec/collect.cpp | 2 +- src/gromacs/domdec/distribute.cpp | 8 +- src/gromacs/domdec/domdec.cpp | 4 +- src/gromacs/domdec/domdec.h | 8 +- src/gromacs/domdec/domdec_constraints.cpp | 22 ++-- src/gromacs/domdec/domdec_constraints.h | 2 +- src/gromacs/domdec/domdec_struct.h | 4 +- src/gromacs/domdec/domdec_topology.cpp | 68 ++++++------ src/gromacs/domdec/partition.cpp | 128 +++++++++++---------- src/gromacs/domdec/redistribute.cpp | 34 +++--- src/gromacs/domdec/utility.cpp | 4 +- src/gromacs/domdec/utility.h | 14 ++- src/gromacs/mdlib/forcerec.cpp | 129 ++++++++++++---------- src/gromacs/mdlib/sim_util.cpp | 6 +- src/gromacs/mdrun/runner.cpp | 4 +- src/gromacs/mdrun/tpi.cpp | 10 +- src/gromacs/mdtypes/forcerec.h | 40 ++++--- 17 files changed, 263 insertions(+), 224 deletions(-) diff --git a/src/gromacs/domdec/collect.cpp b/src/gromacs/domdec/collect.cpp index 6d6c4a2dc4..6c8fac2f63 100644 --- a/src/gromacs/domdec/collect.cpp +++ b/src/gromacs/domdec/collect.cpp @@ -73,7 +73,7 @@ static void dd_collect_cg(gmx_domdec_t* dd, if (ddpCount == dd->ddp_count) { /* The local state and DD are in sync, use the DD indices */ - atomGroups = gmx::constArrayRefFromArray(dd->globalAtomGroupIndices.data(), dd->ncg_home); + atomGroups = gmx::constArrayRefFromArray(dd->globalAtomGroupIndices.data(), dd->numHomeAtoms); nat_home = dd->comm->atomRanges.numHomeAtoms(); } else if (ddpCountCgGl == ddpCount) diff --git a/src/gromacs/domdec/distribute.cpp b/src/gromacs/domdec/distribute.cpp index f0e8a9e04a..6f65e558a1 100644 --- a/src/gromacs/domdec/distribute.cpp +++ b/src/gromacs/domdec/distribute.cpp @@ -513,9 +513,9 @@ static void distributeAtomGroups(const gmx::MDLogger& mdlog, } dd_scatter(dd, 2 * sizeof(int), ibuf, buf2); - dd->ncg_home = buf2[0]; + dd->numHomeAtoms = buf2[0]; dd->comm->atomRanges.setEnd(DDAtomRanges::Type::Home, buf2[1]); - dd->globalAtomGroupIndices.resize(dd->ncg_home); + dd->globalAtomGroupIndices.resize(dd->numHomeAtoms); dd->globalAtomIndices.resize(dd->comm->atomRanges.numHomeAtoms()); if (bMaster) @@ -542,13 +542,13 @@ static void distributeAtomGroups(const gmx::MDLogger& mdlog, bMaster ? ma->intBuffer.data() : nullptr, bMaster ? ma->intBuffer.data() + dd->nnodes : nullptr, bMaster ? ma->atomGroups.data() : nullptr, - dd->ncg_home * sizeof(int), + dd->numHomeAtoms * sizeof(int), dd->globalAtomGroupIndices.data()); if (debug) { fprintf(debug, "Home charge groups:\n"); - for (int i = 0; i < dd->ncg_home; i++) + for (int i = 0; i < dd->numHomeAtoms; i++) { fprintf(debug, " %d", dd->globalAtomGroupIndices[i]); if (i % 10 == 9) diff --git a/src/gromacs/domdec/domdec.cpp b/src/gromacs/domdec/domdec.cpp index 86e75b748a..2c648b83d4 100644 --- a/src/gromacs/domdec/domdec.cpp +++ b/src/gromacs/domdec/domdec.cpp @@ -221,8 +221,8 @@ void dd_store_state(const gmx_domdec_t& dd, t_state* state) gmx_incons("The MD state does not match the domain decomposition state"); } - state->cg_gl.resize(dd.ncg_home); - for (int i = 0; i < dd.ncg_home; i++) + state->cg_gl.resize(dd.numHomeAtoms); + for (int i = 0; i < dd.numHomeAtoms; i++) { state->cg_gl[i] = dd.globalAtomGroupIndices[i]; } diff --git a/src/gromacs/domdec/domdec.h b/src/gromacs/domdec/domdec.h index d02770184a..55644322b7 100644 --- a/src/gromacs/domdec/domdec.h +++ b/src/gromacs/domdec/domdec.h @@ -66,7 +66,7 @@ #include "gromacs/math/vectypes.h" #include "gromacs/utility/real.h" -struct cginfo_mb_t; +struct AtomInfoWithinMoleculeBlock; struct gmx_domdec_t; struct gmx_ddbox_t; struct gmx_domdec_zones_t; @@ -263,9 +263,11 @@ void dd_init_local_state(const gmx_domdec_t& dd, const t_state* state_global, t_ /*! \brief Generate a list of links between atoms that are linked by bonded interactions * - * Also stores whether atoms are linked in \p cginfo_mb. + * Also stores whether atoms are linked in \p atomInfoForEachMoleculeBlock. */ -void makeBondedLinks(gmx_domdec_t* dd, const gmx_mtop_t& mtop, gmx::ArrayRef cginfo_mb); +void makeBondedLinks(gmx_domdec_t* dd, + const gmx_mtop_t& mtop, + gmx::ArrayRef atomInfoForEachMoleculeBlock); /*! \brief Calculate the maximum distance involved in 2-body and multi-body bonded interactions */ void dd_bonded_cg_distance(const gmx::MDLogger& mdlog, diff --git a/src/gromacs/domdec/domdec_constraints.cpp b/src/gromacs/domdec/domdec_constraints.cpp index cd6fec86c7..17cb74fdcb 100644 --- a/src/gromacs/domdec/domdec_constraints.cpp +++ b/src/gromacs/domdec/domdec_constraints.cpp @@ -223,7 +223,7 @@ static void walk_out(int con, /*! \brief Looks up SETTLE constraints for a range of charge-groups */ static void atoms_to_settles(gmx_domdec_t* dd, const gmx_mtop_t& mtop, - const int* cginfo, + const int* atomInfo, gmx::ArrayRef> at2settle_mt, int cg_start, int cg_end, @@ -236,7 +236,7 @@ static void atoms_to_settles(gmx_domdec_t* dd, int mb = 0; for (int a = cg_start; a < cg_end; a++) { - if (GET_CGINFO_SETTLE(cginfo[a])) + if (GET_CGINFO_SETTLE(atomInfo[a])) { int a_gl = dd->globalAtomIndices[a]; int a_mol = 0; @@ -298,7 +298,7 @@ static void atoms_to_settles(gmx_domdec_t* dd, /*! \brief Looks up constraint for the local atoms */ static void atoms_to_constraints(gmx_domdec_t* dd, const gmx_mtop_t& mtop, - const int* cginfo, + const int* atomInfo, gmx::ArrayRef> at2con_mt, int nrec, InteractionList* ilc_local, @@ -314,9 +314,9 @@ static void atoms_to_constraints(gmx_domdec_t* dd, int mb = 0; int nhome = 0; - for (int a = 0; a < dd->ncg_home; a++) + for (int a = 0; a < dd->numHomeAtoms; a++) { - if (GET_CGINFO_CONSTR(cginfo[a])) + if (GET_CGINFO_CONSTR(atomInfo[a])) { int a_gl = dd->globalAtomIndices[a]; int molnr = 0; @@ -399,7 +399,7 @@ static void atoms_to_constraints(gmx_domdec_t* dd, int dd_make_local_constraints(gmx_domdec_t* dd, int at_start, const struct gmx_mtop_t& mtop, - const int* cginfo, + const int* atomInfo, gmx::Constraints* constr, int nrec, gmx::ArrayRef il_local) @@ -449,7 +449,7 @@ int dd_make_local_constraints(gmx_domdec_t* dd, if (at2settle_mt.empty()) { - atoms_to_constraints(dd, mtop, cginfo, at2con_mt, nrec, ilc_local, ireq); + atoms_to_constraints(dd, mtop, atomInfo, at2con_mt, nrec, ilc_local, ireq); } else { @@ -465,7 +465,7 @@ int dd_make_local_constraints(gmx_domdec_t* dd, { if (!at2con_mt.empty() && thread == 0) { - atoms_to_constraints(dd, mtop, cginfo, at2con_mt, nrec, ilc_local, ireq); + atoms_to_constraints(dd, mtop, atomInfo, at2con_mt, nrec, ilc_local, ireq); } if (thread >= t0_set) @@ -473,8 +473,8 @@ int dd_make_local_constraints(gmx_domdec_t* dd, /* Distribute the settle check+assignments over * dc->nthread or dc->nthread-1 threads. */ - const int cg0 = (dd->ncg_home * (thread - t0_set)) / (dc->nthread - t0_set); - const int cg1 = (dd->ncg_home * (thread - t0_set + 1)) / (dc->nthread - t0_set); + const int cg0 = (dd->numHomeAtoms * (thread - t0_set)) / (dc->nthread - t0_set); + const int cg1 = (dd->numHomeAtoms * (thread - t0_set + 1)) / (dc->nthread - t0_set); InteractionList* ilst = (thread == t0_set) ? ils_local : &dc->ils[thread]; ilst->clear(); @@ -485,7 +485,7 @@ int dd_make_local_constraints(gmx_domdec_t* dd, ireqt.clear(); } - atoms_to_settles(dd, mtop, cginfo, at2settle_mt, cg0, cg1, ilst, &ireqt); + atoms_to_settles(dd, mtop, atomInfo, at2settle_mt, cg0, cg1, ilst, &ireqt); } } GMX_CATCH_ALL_AND_EXIT_WITH_FATAL_ERROR diff --git a/src/gromacs/domdec/domdec_constraints.h b/src/gromacs/domdec/domdec_constraints.h index e2a5772b18..81390a8f99 100644 --- a/src/gromacs/domdec/domdec_constraints.h +++ b/src/gromacs/domdec/domdec_constraints.h @@ -64,7 +64,7 @@ void dd_clear_local_constraint_indices(gmx_domdec_t* dd); int dd_make_local_constraints(struct gmx_domdec_t* dd, int at_start, const struct gmx_mtop_t& mtop, - const int* cginfo, + const int* atomInfo, gmx::Constraints* constr, int nrec, gmx::ArrayRef il_local); diff --git a/src/gromacs/domdec/domdec_struct.h b/src/gromacs/domdec/domdec_struct.h index 002dd66f05..98467b8f1a 100644 --- a/src/gromacs/domdec/domdec_struct.h +++ b/src/gromacs/domdec/domdec_struct.h @@ -214,8 +214,8 @@ struct gmx_domdec_t gmx_domdec_constraints_t* constraints = nullptr; gmx_domdec_specat_comm_t* constraint_comm = nullptr; - /* The number of home atom groups */ - int ncg_home = 0; + /* The number of home atoms */ + int numHomeAtoms = 0; /* Global atom group indices for the home and all non-home groups */ std::vector globalAtomGroupIndices; diff --git a/src/gromacs/domdec/domdec_topology.cpp b/src/gromacs/domdec/domdec_topology.cpp index f8a242db16..2586694f77 100644 --- a/src/gromacs/domdec/domdec_topology.cpp +++ b/src/gromacs/domdec/domdec_topology.cpp @@ -733,7 +733,7 @@ static void make_exclusions_zone(ArrayRef globalAtomInd gmx_domdec_zones_t* zones, ArrayRef molblockIndices, const std::vector& moltype, - const int* cginfo, + const int* atomInfo, ListOfLists* lexcls, int iz, int at_start, @@ -749,7 +749,7 @@ static void make_exclusions_zone(ArrayRef globalAtomInd { exclusionsForAtom.clear(); - if (GET_CGINFO_EXCL_INTER(cginfo[at])) + if (GET_CGINFO_EXCL_INTER(atomInfo[at])) { int mb = 0; int mt = 0; @@ -808,7 +808,7 @@ static void make_exclusions_zone(ArrayRef globalAtomInd static int make_local_bondeds_excls(gmx_domdec_t* dd, gmx_domdec_zones_t* zones, const gmx_mtop_t& mtop, - const int* cginfo, + const int* atomInfo, const bool checkDistanceMultiBody, const ivec rcheck, const gmx_bool checkDistanceTwoBody, @@ -910,7 +910,7 @@ static int make_local_bondeds_excls(gmx_domdec_t* dd, zones, rt->molblockIndices(), mtop.moltype, - cginfo, + atomInfo, excl_t, izone, cg0t, @@ -1028,7 +1028,7 @@ int dd_make_local_top(gmx_domdec_t* dd, int numBondedInteractionsToReduce = make_local_bondeds_excls(dd, zones, mtop, - fr->cginfo.data(), + fr->atomInfo.data(), checkDistanceMultiBody, rcheck, checkDistanceTwoBody, @@ -1104,7 +1104,9 @@ static void check_link(t_blocka* link, int cg_gl, int cg_gl_j) } } -void makeBondedLinks(gmx_domdec_t* dd, const gmx_mtop_t& mtop, gmx::ArrayRef cginfo_mb) +void makeBondedLinks(gmx_domdec_t* dd, + const gmx_mtop_t& mtop, + gmx::ArrayRef atomInfoForEachMoleculeBlock) { if (!dd->comm->systemInfo.filterBondedCommunication) @@ -1142,9 +1144,9 @@ void makeBondedLinks(gmx_domdec_t* dd, const gmx_mtop_t& mtop, gmx::ArrayRefnalloc_a = 0; link->a = nullptr; - link->index[0] = 0; - int cg_offset = 0; - int ncgi = 0; + link->index[0] = 0; + int indexOfFirstAtomInMolecule = 0; + int numLinkedAtoms = 0; for (size_t mb = 0; mb < mtop.molblock.size(); mb++) { const gmx_molblock_t& molb = mtop.molblock[mb]; @@ -1161,16 +1163,16 @@ void makeBondedLinks(gmx_domdec_t* dd, const gmx_mtop_t& mtop, gmx::ArrayRefindex[cg_gl + 1] = link->index[cg_gl]; - int i = ril.index[a]; + int atomIndex = indexOfFirstAtomInMolecule + a; + link->index[atomIndex + 1] = link->index[atomIndex]; + int i = ril.index[a]; while (i < ril.index[a + 1]) { int ftype = ril.il[i++]; @@ -1182,7 +1184,7 @@ void makeBondedLinks(gmx_domdec_t* dd, const gmx_mtop_t& mtop, gmx::ArrayRefindex[cg_gl + 1] - link->index[cg_gl] > 0) + if (link->index[atomIndex + 1] - link->index[atomIndex] > 0) { - SET_CGINFO_BOND_INTER(cgi_mb->cginfo[a]); - ncgi++; + SET_CGINFO_BOND_INTER(atomInfoOfMoleculeBlock->atomInfo[a]); + numLinkedAtoms++; } } - cg_offset += molt.atoms.nr; + indexOfFirstAtomInMolecule += molt.atoms.nr; } - int nlink_mol = link->index[cg_offset] - link->index[cg_offset - molt.atoms.nr]; + int nlink_mol = link->index[indexOfFirstAtomInMolecule] + - link->index[indexOfFirstAtomInMolecule - molt.atoms.nr]; if (debug) { @@ -1237,27 +1240,30 @@ void makeBondedLinks(gmx_domdec_t* dd, const gmx_mtop_t& mtop, gmx::ArrayRefindex[cg_gl + 1] = link->index[cg_gl + 1 - molt.atoms.nr] + nlink_mol; - for (int j = link->index[cg_gl]; j < link->index[cg_gl + 1]; j++) + int atomIndex = indexOfFirstAtomInMolecule + a; + link->index[atomIndex + 1] = link->index[atomIndex + 1 - molt.atoms.nr] + nlink_mol; + for (int j = link->index[atomIndex]; j < link->index[atomIndex + 1]; j++) { link->a[j] = link->a[j - nlink_mol] + molt.atoms.nr; } - if (link->index[cg_gl + 1] - link->index[cg_gl] > 0 - && cg_gl - cgi_mb->cg_start < cgi_mb->cg_mod) + if (link->index[atomIndex + 1] - link->index[atomIndex] > 0 + && atomIndex - atomInfoOfMoleculeBlock->indexOfFirstAtomInMoleculeBlock + < gmx::ssize(atomInfoOfMoleculeBlock->atomInfo)) { - SET_CGINFO_BOND_INTER(cgi_mb->cginfo[cg_gl - cgi_mb->cg_start]); - ncgi++; + SET_CGINFO_BOND_INTER( + atomInfoOfMoleculeBlock + ->atomInfo[atomIndex - atomInfoOfMoleculeBlock->indexOfFirstAtomInMoleculeBlock]); + numLinkedAtoms++; } } - cg_offset += molt.atoms.nr; + indexOfFirstAtomInMolecule += molt.atoms.nr; } } } if (debug) { - fprintf(debug, "Of the %d atoms %d are linked via bonded interactions\n", mtop.natoms, ncgi); + fprintf(debug, "Of the %d atoms %d are linked via bonded interactions\n", mtop.natoms, numLinkedAtoms); } dd->comm->bondedLinks = link; diff --git a/src/gromacs/domdec/partition.cpp b/src/gromacs/domdec/partition.cpp index 7e4e9f4984..2b1eea9948 100644 --- a/src/gromacs/domdec/partition.cpp +++ b/src/gromacs/domdec/partition.cpp @@ -435,7 +435,7 @@ static void dd_move_cellx(gmx_domdec_t* dd, const gmx_ddbox_t* ddbox, rvec cell_ } //! Sets the charge-group zones to be equal to the home zone. -static void set_zones_ncg_home(gmx_domdec_t* dd) +static void set_zones_numHomeAtoms(gmx_domdec_t* dd) { gmx_domdec_zones_t* zones; int i; @@ -445,10 +445,10 @@ static void set_zones_ncg_home(gmx_domdec_t* dd) zones->cg_range[0] = 0; for (i = 1; i < zones->n + 1; i++) { - zones->cg_range[i] = dd->ncg_home; + zones->cg_range[i] = dd->numHomeAtoms; } - /* zone_ncg1[0] should always be equal to ncg_home */ - dd->comm->zone_ncg1[0] = dd->ncg_home; + /* zone_ncg1[0] should always be equal to numHomeAtoms */ + dd->comm->zone_ncg1[0] = dd->numHomeAtoms; } //! Restore atom groups for the charge groups. @@ -468,23 +468,24 @@ static void restoreAtomGroups(gmx_domdec_t* dd, const t_state* state) globalAtomGroupIndices[i] = atomGroupsState[i]; } - dd->ncg_home = atomGroupsState.size(); + dd->numHomeAtoms = atomGroupsState.size(); dd->comm->atomRanges.setEnd(DDAtomRanges::Type::Home, atomGroupsState.ssize()); - set_zones_ncg_home(dd); + set_zones_numHomeAtoms(dd); } -//! Sets the cginfo structures. -static void dd_set_cginfo(gmx::ArrayRef index_gl, int cg0, int cg1, t_forcerec* fr) +//! Sets the atom info structures. +static void dd_set_atominfo(gmx::ArrayRef index_gl, int cg0, int cg1, t_forcerec* fr) { if (fr != nullptr) { - gmx::ArrayRef cginfo_mb = fr->cginfo_mb; - gmx::ArrayRef cginfo = fr->cginfo; + gmx::ArrayRef atomInfoForEachMoleculeBlock = + fr->atomInfoForEachMoleculeBlock; + gmx::ArrayRef atomInfo = fr->atomInfo; for (int cg = cg0; cg < cg1; cg++) { - cginfo[cg] = ddcginfo(cginfo_mb, index_gl[cg]); + atomInfo[cg] = ddGetAtomInfo(atomInfoForEachMoleculeBlock, index_gl[cg]); } } } @@ -500,7 +501,7 @@ static void make_dd_indices(gmx_domdec_t* dd, const int atomStart) std::vector& globalAtomIndices = dd->globalAtomIndices; gmx_ga2la_t& ga2la = *dd->ga2la; - if (zone2cg[1] != dd->ncg_home) + if (zone2cg[1] != dd->numHomeAtoms) { gmx_incons("dd->ncg_zone is not up to date"); } @@ -1334,16 +1335,16 @@ void set_dd_dlb_max_cutoff(t_commrec* cr, real cutoff) } //! Merge atom buffers. -static void merge_cg_buffers(int ncell, - gmx_domdec_comm_dim_t* cd, - int pulse, - int* ncg_cell, - gmx::ArrayRef index_gl, - const int* recv_i, - gmx::ArrayRef x, - gmx::ArrayRef recv_vr, - gmx::ArrayRef cginfo_mb, - gmx::ArrayRef cginfo) +static void merge_cg_buffers(int ncell, + gmx_domdec_comm_dim_t* cd, + int pulse, + int* ncg_cell, + gmx::ArrayRef index_gl, + const int* recv_i, + gmx::ArrayRef x, + gmx::ArrayRef recv_vr, + gmx::ArrayRef atomInfoForEachMoleculeBlock, + gmx::ArrayRef atomInfo) { gmx_domdec_ind_t *ind, *ind_p; int p, cell, c, cg, cg0, cg1, cg_gl; @@ -1365,7 +1366,7 @@ static void merge_cg_buffers(int ncell, { index_gl[cg + shift] = index_gl[cg]; x[cg + shift] = x[cg]; - cginfo[cg + shift] = cginfo[cg]; + atomInfo[cg + shift] = atomInfo[cg]; } /* Correct the already stored send indices for the shift */ for (p = 1; p <= pulse; p++) @@ -1397,8 +1398,8 @@ static void merge_cg_buffers(int ncell, index_gl[cg1] = recv_i[cg0]; x[cg1] = recv_vr[cg0]; /* Copy information */ - cg_gl = index_gl[cg1]; - cginfo[cg1] = ddcginfo(cginfo_mb, cg_gl); + cg_gl = index_gl[cg1]; + atomInfo[cg1] = ddGetAtomInfo(atomInfoForEachMoleculeBlock, cg_gl); cg0++; cg1++; } @@ -1579,7 +1580,7 @@ static void get_zone_pulse_groups(gmx_domdec_t* dd, gmx_bool bDist2B, gmx_bool bDistMB, gmx::ArrayRef coordinates, - gmx::ArrayRef cginfo, + gmx::ArrayRef atomInfo, std::vector* localAtomGroups, dd_comm_setup_work_t* work) { @@ -1777,7 +1778,7 @@ static void get_zone_pulse_groups(gmx_domdec_t* dd, if (r2 < r_comm2 || (bDistBonded && ((bDistMB && rb2 < r_bcomm2) || (bDist2B && r2 < r_bcomm2)) && (!bBondComm - || (GET_CGINFO_BOND_INTER(cginfo[cg]) + || (GET_CGINFO_BOND_INTER(atomInfo[cg]) && missing_link(*comm->bondedLinks, globalAtomGroupIndices[cg], *dd->ga2la))))) { /* Store the local and global atom group indices and position */ @@ -1903,13 +1904,14 @@ static void setup_dd_communication(gmx_domdec_t* dd, matrix box, gmx_ddbox_t* dd v_1 = ddbox->v[dim1]; } - zone_cg_range = zones->cg_range.data(); - gmx::ArrayRef cginfo_mb = fr->cginfo_mb; + zone_cg_range = zones->cg_range.data(); + gmx::ArrayRef atomInfoForEachMoleculeBlock = + fr->atomInfoForEachMoleculeBlock; zone_cg_range[0] = 0; - zone_cg_range[1] = dd->ncg_home; - comm->zone_ncg1[0] = dd->ncg_home; - pos_cg = dd->ncg_home; + zone_cg_range[1] = dd->numHomeAtoms; + comm->zone_ncg1[0] = dd->numHomeAtoms; + pos_cg = dd->numHomeAtoms; nat_tot = comm->atomRanges.numHomeAtoms(); nzone = 1; @@ -2048,7 +2050,7 @@ static void setup_dd_communication(gmx_domdec_t* dd, matrix box, gmx_ddbox_t* dd bDist2B, bDistMB, state->x, - fr->cginfo, + fr->atomInfo, th == 0 ? &ind->index : &work.localAtomGroupBuffer, &work); } @@ -2123,7 +2125,7 @@ static void setup_dd_communication(gmx_domdec_t* dd, matrix box, gmx_ddbox_t* dd } ddSendrecv(dd, dim_ind, dddirBackward, work.atomGroupBuffer, integerBufferRef); - /* Make space for cginfo */ + /* Make space for atominfo */ dd_resize_atominfo_and_state(fr, state, pos_cg + ind->nrecv[nzone]); /* Communicate the coordinates */ @@ -2147,7 +2149,8 @@ static void setup_dd_communication(gmx_domdec_t* dd, matrix box, gmx_ddbox_t* dd for (int i = 0; i < ind->nrecv[zone]; i++) { int globalAtomIndex = dd->globalAtomGroupIndices[pos_cg]; - fr->cginfo[pos_cg] = ddcginfo(cginfo_mb, globalAtomIndex); + fr->atomInfo[pos_cg] = + ddGetAtomInfo(atomInfoForEachMoleculeBlock, globalAtomIndex); pos_cg++; } if (p == 0) @@ -2169,8 +2172,8 @@ static void setup_dd_communication(gmx_domdec_t* dd, matrix box, gmx_ddbox_t* dd integerBufferRef.data(), state->x, rvecBufferRef, - fr->cginfo_mb, - fr->cginfo); + fr->atomInfoForEachMoleculeBlock, + fr->atomInfo); pos_cg += ind->nrecv[nzone]; } nat_tot += ind->nrecv[nzone + 1]; @@ -2187,10 +2190,11 @@ static void setup_dd_communication(gmx_domdec_t* dd, matrix box, gmx_ddbox_t* dd if (!bBondComm) { - /* We don't need to update cginfo, since that was alrady done above. + /* We don't need to update atominfo, since that was already done above. * So we pass NULL for the forcerec. */ - dd_set_cginfo(dd->globalAtomGroupIndices, dd->ncg_home, dd->globalAtomGroupIndices.size(), nullptr); + dd_set_atominfo( + dd->globalAtomGroupIndices, dd->numHomeAtoms, dd->globalAtomGroupIndices.size(), nullptr); } if (debug) @@ -2565,18 +2569,19 @@ static void dd_sort_state(gmx_domdec_t* dd, t_forcerec* fr, t_state* state) dd_sort_order_nbnxn(fr, &sort->sorted); /* We alloc with the old size, since cgindex is still old */ - DDBufferAccess rvecBuffer(dd->comm->rvecBuffer, dd->ncg_home); + DDBufferAccess rvecBuffer(dd->comm->rvecBuffer, dd->numHomeAtoms); /* Set the new home atom/charge group count */ - dd->ncg_home = sort->sorted.size(); + dd->numHomeAtoms = sort->sorted.size(); if (debug) { - fprintf(debug, "Set the new home atom count to %d\n", dd->ncg_home); + fprintf(debug, "Set the new home atom count to %d\n", dd->numHomeAtoms); } /* Reorder the state */ gmx::ArrayRef cgsort = sort->sorted; - GMX_RELEASE_ASSERT(cgsort.ssize() == dd->ncg_home, "We should sort all the home atom groups"); + GMX_RELEASE_ASSERT(cgsort.ssize() == dd->numHomeAtoms, + "We should sort all the home atom groups"); if (state->flags & enumValueToBitMask(StateEntry::X)) { @@ -2593,10 +2598,10 @@ static void dd_sort_state(gmx_domdec_t* dd, t_forcerec* fr, t_state* state) /* Reorder the global cg index */ orderVector(cgsort, dd->globalAtomGroupIndices, &sort->intBuffer); - /* Reorder the cginfo */ - orderVector(cgsort, fr->cginfo, &sort->intBuffer); + /* Reorder the atom info */ + orderVector(cgsort, fr->atomInfo, &sort->intBuffer); /* Set the home atom number */ - dd->comm->atomRanges.setEnd(DDAtomRanges::Type::Home, dd->ncg_home); + dd->comm->atomRanges.setEnd(DDAtomRanges::Type::Home, dd->numHomeAtoms); /* The atoms are now exactly in grid order, update the grid order */ fr->nbv->setLocalAtomOrder(); @@ -2969,11 +2974,11 @@ void dd_partition_system(FILE* fplog, distributeState(mdlog, dd, top_global, state_global, ddbox, state_local); /* Ensure that we have space for the new distribution */ - dd_resize_atominfo_and_state(fr, state_local, dd->ncg_home); + dd_resize_atominfo_and_state(fr, state_local, dd->numHomeAtoms); inc_nrnb(nrnb, eNR_CGCM, comm->atomRanges.numHomeAtoms()); - dd_set_cginfo(dd->globalAtomGroupIndices, 0, dd->ncg_home, fr); + dd_set_atominfo(dd->globalAtomGroupIndices, 0, dd->numHomeAtoms, fr); } else if (state_local->ddp_count != dd->ddp_count) { @@ -3001,11 +3006,11 @@ void dd_partition_system(FILE* fplog, /* Restore the atom group indices from state_local */ restoreAtomGroups(dd, state_local); make_dd_indices(dd, 0); - ncgindex_set = dd->ncg_home; + ncgindex_set = dd->numHomeAtoms; inc_nrnb(nrnb, eNR_CGCM, comm->atomRanges.numHomeAtoms()); - dd_set_cginfo(dd->globalAtomGroupIndices, 0, dd->ncg_home, fr); + dd_set_atominfo(dd->globalAtomGroupIndices, 0, dd->numHomeAtoms, fr); set_ddbox(*dd, bMasterState, state_local->box, true, state_local->x, &ddbox); @@ -3047,7 +3052,8 @@ void dd_partition_system(FILE* fplog, if (comm->systemInfo.useUpdateGroups) { comm->updateGroupsCog->addCogs( - gmx::arrayRefFromArray(dd->globalAtomGroupIndices.data(), dd->ncg_home), state_local->x); + gmx::arrayRefFromArray(dd->globalAtomGroupIndices.data(), dd->numHomeAtoms), + state_local->x); } /* Check if we should sort the charge groups */ @@ -3063,7 +3069,7 @@ void dd_partition_system(FILE* fplog, { wallcycle_sub_start(wcycle, WallCycleSubCounter::DDRedist); - ncgindex_set = dd->ncg_home; + ncgindex_set = dd->numHomeAtoms; dd_redistribute_cg(fplog, step, dd, ddbox.tric_dir, state_local, fr, nrnb, &ncg_moved); GMX_RELEASE_ASSERT(bSortCG, "Sorting is required after redistribution"); @@ -3071,7 +3077,7 @@ void dd_partition_system(FILE* fplog, if (comm->systemInfo.useUpdateGroups) { comm->updateGroupsCog->addCogs( - gmx::arrayRefFromArray(dd->globalAtomGroupIndices.data(), dd->ncg_home), + gmx::arrayRefFromArray(dd->globalAtomGroupIndices.data(), dd->numHomeAtoms), state_local->x); } @@ -3085,7 +3091,7 @@ void dd_partition_system(FILE* fplog, &ddbox, &comm->cell_x0, &comm->cell_x1, - dd->ncg_home, + dd->numHomeAtoms, as_rvec_array(state_local->x.data()), cell_ns_x0, cell_ns_x1); @@ -3108,7 +3114,7 @@ void dd_partition_system(FILE* fplog, /* Fill the ns grid with the home cell, * so we can sort with the indices. */ - set_zones_ncg_home(dd); + set_zones_numHomeAtoms(dd); set_zones_size(dd, state_local->box, &ddbox, 0, 1, ncg_moved); @@ -3118,16 +3124,16 @@ void dd_partition_system(FILE* fplog, comm->zones.size[0].bb_x0, comm->zones.size[0].bb_x1, comm->updateGroupsCog.get(), - { 0, dd->ncg_home }, + { 0, dd->numHomeAtoms }, comm->zones.dens_zone0, - fr->cginfo, + fr->atomInfo, state_local->x, ncg_moved, bRedist ? comm->movedBuffer.data() : nullptr); if (debug) { - fprintf(debug, "Step %s, sorting the %d home charge groups\n", gmx_step_str(step, sbuf), dd->ncg_home); + fprintf(debug, "Step %s, sorting the %d home charge groups\n", gmx_step_str(step, sbuf), dd->numHomeAtoms); } dd_sort_state(dd, fr, state_local); @@ -3162,14 +3168,14 @@ void dd_partition_system(FILE* fplog, wallcycle_sub_start(wcycle, WallCycleSubCounter::DDSetupComm); /* Set the induces for the home atoms */ - set_zones_ncg_home(dd); + set_zones_numHomeAtoms(dd); 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); /* Set the indices for the halo atoms */ - make_dd_indices(dd, dd->ncg_home); + make_dd_indices(dd, dd->numHomeAtoms); /* Set the charge group boundaries for neighbor searching */ set_cg_boundaries(&comm->zones); @@ -3230,7 +3236,7 @@ void dd_partition_system(FILE* fplog, n = dd_make_local_constraints(dd, n, top_global, - fr->cginfo.data(), + fr->atomInfo.data(), constr, inputrec.nProjOrder, top_local->idef.il); diff --git a/src/gromacs/domdec/redistribute.cpp b/src/gromacs/domdec/redistribute.cpp index d47243969b..4225ff78fc 100644 --- a/src/gromacs/domdec/redistribute.cpp +++ b/src/gromacs/domdec/redistribute.cpp @@ -573,7 +573,7 @@ void dd_redistribute_cg(FILE* fplog, bool bV = (state->flags & enumValueToBitMask(StateEntry::V)) != 0; bool bCGP = (state->flags & enumValueToBitMask(StateEntry::Cgp)) != 0; - DDBufferAccess moveBuffer(comm->intBuffer, dd->ncg_home); + DDBufferAccess moveBuffer(comm->intBuffer, dd->numHomeAtoms); gmx::ArrayRef move = moveBuffer.buffer; const int npbcdim = dd->unitCellInfo.npbcdim; @@ -669,8 +669,8 @@ void dd_redistribute_cg(FILE* fplog, cell_x0, cell_x1, moveLimits, - (thread * dd->ncg_home) / nthread, - ((thread + 1) * dd->ncg_home) / nthread, + (thread * dd->numHomeAtoms) / nthread, + ((thread + 1) * dd->numHomeAtoms) / nthread, move); } } @@ -679,7 +679,7 @@ void dd_redistribute_cg(FILE* fplog, int ncg[DIM * 2] = { 0 }; int nat[DIM * 2] = { 0 }; - for (int cg = 0; cg < dd->ncg_home; cg++) + for (int cg = 0; cg < dd->numHomeAtoms; cg++) { if (move[cg] >= 0) { @@ -709,7 +709,7 @@ void dd_redistribute_cg(FILE* fplog, } inc_nrnb(nrnb, eNR_CGCM, comm->atomRanges.numHomeAtoms()); - inc_nrnb(nrnb, eNR_RESETX, dd->ncg_home); + inc_nrnb(nrnb, eNR_RESETX, dd->numHomeAtoms); *ncg_moved = 0; for (int i = 0; i < dd->ndim * 2; i++) @@ -755,21 +755,22 @@ void dd_redistribute_cg(FILE* fplog, copyMovedAtomsToBufferPerAtom(move, nvec, vectorIndex++, state->cg_p.rvec_array(), comm); } - int* moved = getMovedBuffer(comm, 0, dd->ncg_home); + int* moved = getMovedBuffer(comm, 0, dd->numHomeAtoms); clear_and_mark_ind(move, dd->globalAtomIndices, dd->ga2la, moved); /* Now we can remove the excess global atom-group indices from the list */ - dd->globalAtomGroupIndices.resize(dd->ncg_home); + dd->globalAtomGroupIndices.resize(dd->numHomeAtoms); /* We reuse the intBuffer without reacquiring since we are in the same scope */ DDBufferAccess& flagBuffer = moveBuffer; - gmx::ArrayRef cginfo_mb = fr->cginfo_mb; + gmx::ArrayRef atomInfoForEachMoleculeBlock = + fr->atomInfoForEachMoleculeBlock; /* Temporarily store atoms passed to our rank at the end of the range */ - int home_pos_cg = dd->ncg_home; - int home_pos_at = dd->ncg_home; + int home_pos_cg = dd->numHomeAtoms; + int home_pos_at = dd->numHomeAtoms; for (int d = 0; d < dd->ndim; d++) { DDBufferAccess rvecBuffer(comm->rvecBuffer, 0); @@ -924,7 +925,8 @@ void dd_redistribute_cg(FILE* fplog, buf_pos++; /* Set the cginfo */ - fr->cginfo[home_pos_cg] = ddcginfo(cginfo_mb, globalAtomGroupIndex); + fr->atomInfo[home_pos_cg] = + ddGetAtomInfo(atomInfoForEachMoleculeBlock, globalAtomGroupIndex); auto x = makeArrayRef(state->x); auto v = makeArrayRef(state->v); @@ -978,21 +980,21 @@ void dd_redistribute_cg(FILE* fplog, } /* Note that the indices are now only partially up to date - * and ncg_home and nat_home are not the real count, since there are + * and numHomeAtoms and nat_home are not the real count, since there are * "holes" in the arrays for the charge groups that moved to neighbors. */ /* We need to clear the moved flags for the received atoms, * because the moved buffer will be passed to the nbnxm gridding call. */ - moved = getMovedBuffer(comm, dd->ncg_home, home_pos_cg); + moved = getMovedBuffer(comm, dd->numHomeAtoms, home_pos_cg); - for (int i = dd->ncg_home; i < home_pos_cg; i++) + for (int i = dd->numHomeAtoms; i < home_pos_cg; i++) { moved[i] = 0; } - dd->ncg_home = home_pos_cg; + dd->numHomeAtoms = home_pos_cg; comm->atomRanges.setEnd(DDAtomRanges::Type::Home, home_pos_at); if (debug) @@ -1000,6 +1002,6 @@ void dd_redistribute_cg(FILE* fplog, fprintf(debug, "Finished repartitioning: cgs moved out %d, new home %d\n", *ncg_moved, - dd->ncg_home - *ncg_moved); + dd->numHomeAtoms - *ncg_moved); } } diff --git a/src/gromacs/domdec/utility.cpp b/src/gromacs/domdec/utility.cpp index db2833c0c3..c302b69cf9 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,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. @@ -105,7 +105,7 @@ void check_screw_box(const matrix box) void dd_resize_atominfo_and_state(t_forcerec* fr, t_state* state, const int numAtoms) { - fr->cginfo.resize(numAtoms); + fr->atomInfo.resize(numAtoms); /* We use x during the setup of the atom communication */ state_change_natoms(state, numAtoms); diff --git a/src/gromacs/domdec/utility.h b/src/gromacs/domdec/utility.h index e3fea6e1e7..ce65383f19 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,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. @@ -82,17 +82,19 @@ void make_tric_corr_matrix(int npbcdim, const matrix box, matrix tcm); /*! \brief Ensure box obeys the screw restrictions, fatal error if not */ void check_screw_box(const matrix box); -/*! \brief Return the charge group information flags for charge group cg */ -static inline int ddcginfo(gmx::ArrayRef cginfo_mb, int cg) +/*! \brief Return the atom information flags for atom a */ +static inline int ddGetAtomInfo(gmx::ArrayRef atomInfoForEachMoleculeBlock, + int a) { size_t index = 0; - while (cg >= cginfo_mb[index].cg_end) + while (a >= atomInfoForEachMoleculeBlock[index].indexOfLastAtomInMoleculeBlock) { index++; } - const cginfo_mb_t& cgimb = cginfo_mb[index]; + const AtomInfoWithinMoleculeBlock& atomInfoOfMoleculeBlock = atomInfoForEachMoleculeBlock[index]; - return cgimb.cginfo[(cg - cgimb.cg_start) % cgimb.cg_mod]; + return atomInfoOfMoleculeBlock.atomInfo[(a - atomInfoOfMoleculeBlock.indexOfFirstAtomInMoleculeBlock) + % atomInfoOfMoleculeBlock.atomInfo.size()]; }; /*! \brief Returns the number of MD steps for which load has been recorded */ diff --git a/src/gromacs/mdlib/forcerec.cpp b/src/gromacs/mdlib/forcerec.cpp index 8e8caec27a..0b090cd656 100644 --- a/src/gromacs/mdlib/forcerec.cpp +++ b/src/gromacs/mdlib/forcerec.cpp @@ -190,72 +190,80 @@ std::vector makeLJPmeC6GridCorrectionParameters(const int return grid; } -enum +//! What kind of constraint affects an atom +enum class ConstraintTypeForAtom : int { - acNONE = 0, - acCONSTRAINT, - acSETTLE + None, //!< No constraint active + Constraint, //!< F_CONSTR or F_CONSTRNC active + Settle, //! F_SETTLE active }; -static std::vector init_cginfo_mb(const gmx_mtop_t& mtop, const t_forcerec* fr) +static std::vector makeAtomInfoForEachMoleculeBlock(const gmx_mtop_t& mtop, + const t_forcerec* fr) { - gmx_bool* type_VDW; - int* a_con; - - snew(type_VDW, fr->ntype); + std::vector atomUsesVdw(fr->ntype, false); for (int ai = 0; ai < fr->ntype; ai++) { - type_VDW[ai] = FALSE; for (int j = 0; j < fr->ntype; j++) { - type_VDW[ai] = type_VDW[ai] || fr->haveBuckingham || C6(fr->nbfp, fr->ntype, ai, j) != 0 - || C12(fr->nbfp, fr->ntype, ai, j) != 0; + atomUsesVdw[ai] = atomUsesVdw[ai] || fr->haveBuckingham || C6(fr->nbfp, fr->ntype, ai, j) != 0 + || C12(fr->nbfp, fr->ntype, ai, j) != 0; } } - std::vector cginfoPerMolblock; - int a_offset = 0; + std::vector atomInfoForEachMoleculeBlock; + int indexOfFirstAtomInMoleculeBlock = 0; for (size_t mb = 0; mb < mtop.molblock.size(); mb++) { const gmx_molblock_t& molb = mtop.molblock[mb]; const gmx_moltype_t& molt = mtop.moltype[molb.type]; const auto& excl = molt.excls; - /* Check if the cginfo is identical for all molecules in this block. + /* Check if all molecules in this block have identical + * atominfo. (That's true unless some kind of group- or + * distance-based algorithm is involved, e.g. QM/MM groups + * affecting multiple molecules within a block differently.) * If so, we only need an array of the size of one molecule. - * Otherwise we make an array of #mol times #cgs per molecule. + * Otherwise we make an array of #mol times #atoms per + * molecule. */ - gmx_bool bId = TRUE; + bool allMoleculesWithinBlockAreIdentical = true; for (int m = 0; m < molb.nmol; m++) { - const int am = m * molt.atoms.nr; + const int numAtomsInAllMolecules = m * molt.atoms.nr; for (int a = 0; a < molt.atoms.nr; a++) { - if (getGroupType(mtop.groups, SimulationAtomGroupType::QuantumMechanics, a_offset + am + a) - != getGroupType(mtop.groups, SimulationAtomGroupType::QuantumMechanics, a_offset + a)) + if (getGroupType(mtop.groups, + SimulationAtomGroupType::QuantumMechanics, + indexOfFirstAtomInMoleculeBlock + numAtomsInAllMolecules + a) + != getGroupType(mtop.groups, + SimulationAtomGroupType::QuantumMechanics, + indexOfFirstAtomInMoleculeBlock + a)) { - bId = FALSE; + allMoleculesWithinBlockAreIdentical = false; } if (!mtop.groups.groupNumbers[SimulationAtomGroupType::QuantumMechanics].empty()) { - if (mtop.groups.groupNumbers[SimulationAtomGroupType::QuantumMechanics][a_offset + am + a] - != mtop.groups.groupNumbers[SimulationAtomGroupType::QuantumMechanics][a_offset + a]) + if (mtop.groups.groupNumbers[SimulationAtomGroupType::QuantumMechanics] + [indexOfFirstAtomInMoleculeBlock + numAtomsInAllMolecules + a] + != mtop.groups.groupNumbers[SimulationAtomGroupType::QuantumMechanics] + [indexOfFirstAtomInMoleculeBlock + a]) { - bId = FALSE; + allMoleculesWithinBlockAreIdentical = false; } } } } - cginfo_mb_t cginfo_mb; - cginfo_mb.cg_start = a_offset; - cginfo_mb.cg_end = a_offset + molb.nmol * molt.atoms.nr; - cginfo_mb.cg_mod = (bId ? 1 : molb.nmol) * molt.atoms.nr; - cginfo_mb.cginfo.resize(cginfo_mb.cg_mod); - gmx::ArrayRef cginfo = cginfo_mb.cginfo; + AtomInfoWithinMoleculeBlock atomInfoOfMoleculeBlock; + atomInfoOfMoleculeBlock.indexOfFirstAtomInMoleculeBlock = indexOfFirstAtomInMoleculeBlock; + atomInfoOfMoleculeBlock.indexOfLastAtomInMoleculeBlock = + indexOfFirstAtomInMoleculeBlock + molb.nmol * molt.atoms.nr; + int atomInfoSize = (allMoleculesWithinBlockAreIdentical ? 1 : molb.nmol) * molt.atoms.nr; + atomInfoOfMoleculeBlock.atomInfo.resize(atomInfoSize); /* Set constraints flags for constrained atoms */ - snew(a_con, molt.atoms.nr); + std::vector constraintTypeOfAtom(molt.atoms.nr, ConstraintTypeForAtom::None); for (int ftype = 0; ftype < F_NRE; ftype++) { if (interaction_function[ftype].flags & IF_CONSTRAINT) @@ -263,32 +271,31 @@ static std::vector init_cginfo_mb(const gmx_mtop_t& mtop, const t_f const int nral = NRAL(ftype); for (int ia = 0; ia < molt.ilist[ftype].size(); ia += 1 + nral) { - int a; - - for (a = 0; a < nral; a++) + for (int a = 0; a < nral; a++) { - a_con[molt.ilist[ftype].iatoms[ia + 1 + a]] = - (ftype == F_SETTLE ? acSETTLE : acCONSTRAINT); + constraintTypeOfAtom[molt.ilist[ftype].iatoms[ia + 1 + a]] = + (ftype == F_SETTLE ? ConstraintTypeForAtom::Settle + : ConstraintTypeForAtom::Constraint); } } } } - for (int m = 0; m < (bId ? 1 : molb.nmol); m++) + for (int m = 0; m < (allMoleculesWithinBlockAreIdentical ? 1 : molb.nmol); m++) { - const int molculeOffsetInBlock = m * molt.atoms.nr; + const int moleculeOffsetInBlock = m * molt.atoms.nr; for (int a = 0; a < molt.atoms.nr; a++) { - const t_atom& atom = molt.atoms.atom[a]; - int& atomInfo = cginfo[molculeOffsetInBlock + a]; + const t_atom& atom = molt.atoms.atom[a]; + int& atomInfo = atomInfoOfMoleculeBlock.atomInfo[moleculeOffsetInBlock + a]; - /* Store the energy group in cginfo */ + /* Store the energy group in atomInfo */ int gid = getGroupType(mtop.groups, SimulationAtomGroupType::EnergyOutput, - a_offset + molculeOffsetInBlock + a); + indexOfFirstAtomInMoleculeBlock + moleculeOffsetInBlock + a); SET_CGINFO_GID(atomInfo, gid); - bool bHaveVDW = (type_VDW[atom.type] || type_VDW[atom.typeB]); + bool bHaveVDW = (atomUsesVdw[atom.type] || atomUsesVdw[atom.typeB]); bool bHaveQ = (atom.q != 0 || atom.qB != 0); bool haveExclusions = false; @@ -302,10 +309,10 @@ static std::vector init_cginfo_mb(const gmx_mtop_t& mtop, const t_f } } - switch (a_con[a]) + switch (constraintTypeOfAtom[a]) { - case acCONSTRAINT: SET_CGINFO_CONSTR(atomInfo); break; - case acSETTLE: SET_CGINFO_SETTLE(atomInfo); break; + case ConstraintTypeForAtom::Constraint: SET_CGINFO_CONSTR(atomInfo); break; + case ConstraintTypeForAtom::Settle: SET_CGINFO_SETTLE(atomInfo); break; default: break; } if (haveExclusions) @@ -327,34 +334,34 @@ static std::vector init_cginfo_mb(const gmx_mtop_t& mtop, const t_f } } - sfree(a_con); - - cginfoPerMolblock.push_back(cginfo_mb); + atomInfoForEachMoleculeBlock.push_back(atomInfoOfMoleculeBlock); - a_offset += molb.nmol * molt.atoms.nr; + indexOfFirstAtomInMoleculeBlock += molb.nmol * molt.atoms.nr; } - sfree(type_VDW); - return cginfoPerMolblock; + return atomInfoForEachMoleculeBlock; } -static std::vector cginfo_expand(const int nmb, gmx::ArrayRef cgi_mb) +static std::vector expandAtomInfo(const int nmb, + gmx::ArrayRef atomInfoForEachMoleculeBlock) { - const int ncg = cgi_mb[nmb - 1].cg_end; + const int numAtoms = atomInfoForEachMoleculeBlock[nmb - 1].indexOfLastAtomInMoleculeBlock; - std::vector cginfo(ncg); + std::vector atomInfo(numAtoms); int mb = 0; - for (int cg = 0; cg < ncg; cg++) + for (int a = 0; a < numAtoms; a++) { - while (cg >= cgi_mb[mb].cg_end) + while (a >= atomInfoForEachMoleculeBlock[mb].indexOfLastAtomInMoleculeBlock) { mb++; } - cginfo[cg] = cgi_mb[mb].cginfo[(cg - cgi_mb[mb].cg_start) % cgi_mb[mb].cg_mod]; + atomInfo[a] = atomInfoForEachMoleculeBlock[mb] + .atomInfo[(a - atomInfoForEachMoleculeBlock[mb].indexOfFirstAtomInMoleculeBlock) + % atomInfoForEachMoleculeBlock[mb].atomInfo.size()]; } - return cginfo; + return atomInfo; } /* Sets the sum of charges (squared) and C6 in the system in fr. @@ -1047,10 +1054,10 @@ void init_forcerec(FILE* fplog, } /* Set all the static charge group info */ - forcerec->cginfo_mb = init_cginfo_mb(mtop, forcerec); + forcerec->atomInfoForEachMoleculeBlock = makeAtomInfoForEachMoleculeBlock(mtop, forcerec); if (!DOMAINDECOMP(commrec)) { - forcerec->cginfo = cginfo_expand(mtop.molblock.size(), forcerec->cginfo_mb); + forcerec->atomInfo = expandAtomInfo(mtop.molblock.size(), forcerec->atomInfoForEachMoleculeBlock); } if (!DOMAINDECOMP(commrec)) diff --git a/src/gromacs/mdlib/sim_util.cpp b/src/gromacs/mdlib/sim_util.cpp index e73d83fdac..3b8ef341de 100644 --- a/src/gromacs/mdlib/sim_util.cpp +++ b/src/gromacs/mdlib/sim_util.cpp @@ -1393,7 +1393,7 @@ void do_force(FILE* fplog, nullptr, { 0, mdatoms->homenr }, -1, - fr->cginfo, + fr->atomInfo, x.unpaddedArrayRef(), 0, nullptr); @@ -1402,13 +1402,13 @@ void do_force(FILE* fplog, else { wallcycle_sub_start(wcycle, WallCycleSubCounter::NBSGridNonLocal); - nbnxn_put_on_grid_nonlocal(nbv, domdec_zones(cr->dd), fr->cginfo, x.unpaddedArrayRef()); + nbnxn_put_on_grid_nonlocal(nbv, domdec_zones(cr->dd), fr->atomInfo, x.unpaddedArrayRef()); wallcycle_sub_stop(wcycle, WallCycleSubCounter::NBSGridNonLocal); } nbv->setAtomProperties(gmx::constArrayRefFromArray(mdatoms->typeA, mdatoms->nr), gmx::constArrayRefFromArray(mdatoms->chargeA, mdatoms->nr), - fr->cginfo); + fr->atomInfo); wallcycle_stop(wcycle, WallCycleCounter::NS); diff --git a/src/gromacs/mdrun/runner.cpp b/src/gromacs/mdrun/runner.cpp index 2ebebc70bc..022642cbfc 100644 --- a/src/gromacs/mdrun/runner.cpp +++ b/src/gromacs/mdrun/runner.cpp @@ -1938,9 +1938,9 @@ int Mdrunner::mdrunner() { GMX_RELEASE_ASSERT(fr, "fr was NULL while cr->duty was DUTY_PP"); /* This call is not included in init_domain_decomposition - * because fr->cginfo_mb is set later. + * because fr->atomInfoForEachMoleculeBlock is set later. */ - makeBondedLinks(cr->dd, mtop, fr->cginfo_mb); + makeBondedLinks(cr->dd, mtop, fr->atomInfoForEachMoleculeBlock); } if (runScheduleWork.simulationWork.useGpuBufferOps) diff --git a/src/gromacs/mdrun/tpi.cpp b/src/gromacs/mdrun/tpi.cpp index 3b83b4b89e..606ab186ef 100644 --- a/src/gromacs/mdrun/tpi.cpp +++ b/src/gromacs/mdrun/tpi.cpp @@ -444,10 +444,10 @@ void LegacySimulator::do_tpi() fr->nbv->changePairlistRadii(inputrec->rlist, inputrec->rlist); ngid = groups->groups[SimulationAtomGroupType::EnergyOutput].size(); - gid_tp = GET_CGINFO_GID(fr->cginfo[a_tp0]); + gid_tp = GET_CGINFO_GID(fr->atomInfo[a_tp0]); for (int a = a_tp0 + 1; a < a_tp1; a++) { - if (GET_CGINFO_GID(fr->cginfo[a]) != gid_tp) + if (GET_CGINFO_GID(fr->atomInfo[a]) != gid_tp) { fprintf(fplog, "NOTE: Atoms in the molecule to insert belong to different energy groups.\n" @@ -619,7 +619,7 @@ void LegacySimulator::do_tpi() rvec vzero = { 0, 0, 0 }; rvec boxDiagonal = { box[XX][XX], box[YY][YY], box[ZZ][ZZ] }; nbnxn_put_on_grid( - fr->nbv.get(), box, 0, vzero, boxDiagonal, nullptr, { 0, a_tp0 }, -1, fr->cginfo, x, 0, nullptr); + fr->nbv.get(), box, 0, vzero, boxDiagonal, nullptr, { 0, a_tp0 }, -1, fr->atomInfo, x, 0, nullptr); step = cr->nodeid * stepblocksize; while (step < nsteps) @@ -691,12 +691,12 @@ void LegacySimulator::do_tpi() /* Put the inserted molecule on it's own search grid */ nbnxn_put_on_grid( - fr->nbv.get(), box, 1, x_init, x_init, nullptr, { a_tp0, a_tp1 }, -1, fr->cginfo, x, 0, nullptr); + fr->nbv.get(), box, 1, x_init, x_init, nullptr, { a_tp0, a_tp1 }, -1, fr->atomInfo, x, 0, nullptr); /* TODO: Avoid updating all atoms at every bNS step */ fr->nbv->setAtomProperties(gmx::constArrayRefFromArray(mdatoms->typeA, mdatoms->nr), gmx::constArrayRefFromArray(mdatoms->chargeA, mdatoms->nr), - fr->cginfo); + fr->atomInfo); fr->nbv->constructPairlist(InteractionLocality::Local, top.excls, step, nrnb); diff --git a/src/gromacs/mdtypes/forcerec.h b/src/gromacs/mdtypes/forcerec.h index 8a1ebe14e5..3aa4e28ec3 100644 --- a/src/gromacs/mdtypes/forcerec.h +++ b/src/gromacs/mdtypes/forcerec.h @@ -73,14 +73,10 @@ class PmePpCommGpu; class WholeMoleculeTransform; } // namespace gmx -/* macros for the cginfo data in forcerec +/* macros for the atom info data in forcerec * * Since the tpx format support max 256 energy groups, we do the same here. * Note that we thus have bits 8-14 still unused. - * - * The maximum cg size in cginfo is 63 - * because we only have space for 6 bits in cginfo, - * this cg size entry is actually only read with domain decomposition. */ #define SET_CGINFO_GID(cgi, gid) (cgi) = (((cgi) & ~255) | (gid)) #define GET_CGINFO_GID(cgi) ((cgi)&255) @@ -109,12 +105,30 @@ class WholeMoleculeTransform; //! Check the cuttoff real cutoff_inf(real cutoff); -struct cginfo_mb_t +/*! \brief Contains information about each atom in a molecule block of + * the global topology. */ +struct AtomInfoWithinMoleculeBlock { - int cg_start = 0; - int cg_end = 0; - int cg_mod = 0; - std::vector cginfo; + //! Index within the system of the first atom in the molecule block + int indexOfFirstAtomInMoleculeBlock = 0; + //! Index within the system of the last atom in the molecule block + int indexOfLastAtomInMoleculeBlock = 0; + /*! \brief Atom info for each atom in the block. + * + * The typical case is that all atoms are identical for each + * molecule of the block, and if so this vector has size equal to + * the number of atoms in the molecule. + * + * An example of an atypical case is QM/MM, where multiple + * molecules might be present and different molecules have + * different atoms within any one QM group or region. Now there are + * multiple kinds of molecules with the same connectivity, so we simply + * write out the atom info for the entire molecule block. Then the + * size equals the product of the number of atoms in the + * molecule and the number of molecules. + * + * The vector needs to be indexed accordingly. */ + std::vector atomInfo; }; @@ -224,10 +238,10 @@ struct t_forcerec /* Free energy */ FreeEnergyPerturbationType efep = FreeEnergyPerturbationType::No; - /* Information about atom properties for the molecule blocks in the system */ - std::vector cginfo_mb; + /* Information about atom properties for the molecule blocks in the global topology */ + std::vector atomInfoForEachMoleculeBlock; /* Information about atom properties for local and non-local atoms */ - std::vector cginfo; + std::vector atomInfo; std::vector shift_vec; -- 2.22.0