From 2996cf83fc3d5b4fb8cf425888853cb2f08299be Mon Sep 17 00:00:00 2001 From: Berk Hess Date: Thu, 19 Sep 2019 15:00:13 +0200 Subject: [PATCH] Remove bLocalCG from DD code Replaced the use of bLocalCG in gmx_domdec_comm_t by ga2la, which can be done since we no longer support charge groups. Change-Id: I601e4a9c63e685b21f764fc99dc71c0080e84a43 --- src/gromacs/domdec/domdec.cpp | 37 ++------ src/gromacs/domdec/domdec.h | 9 +- src/gromacs/domdec/domdec_internal.h | 6 +- src/gromacs/domdec/domdec_topology.cpp | 4 +- src/gromacs/domdec/partition.cpp | 123 ++++++------------------- src/gromacs/domdec/redistribute.cpp | 14 +-- 6 files changed, 50 insertions(+), 143 deletions(-) diff --git a/src/gromacs/domdec/domdec.cpp b/src/gromacs/domdec/domdec.cpp index f707744ce1..655f475582 100644 --- a/src/gromacs/domdec/domdec.cpp +++ b/src/gromacs/domdec/domdec.cpp @@ -2578,27 +2578,13 @@ static void set_dd_limits(const gmx::MDLogger &mdlog, } } -static char *init_bLocalCG(const gmx_mtop_t *mtop) -{ - int ncg, cg; - char *bLocalCG; - - ncg = ncg_mtop(mtop); - snew(bLocalCG, ncg); - for (cg = 0; cg < ncg; cg++) - { - bLocalCG[cg] = FALSE; - } - - return bLocalCG; -} - -void dd_init_bondeds(FILE *fplog, - gmx_domdec_t *dd, - const gmx_mtop_t *mtop, - const gmx_vsite_t *vsite, - const t_inputrec *ir, - gmx_bool bBCheck, cginfo_mb_t *cginfo_mb) +void dd_init_bondeds(FILE *fplog, + gmx_domdec_t *dd, + const gmx_mtop_t *mtop, + const gmx_vsite_t *vsite, + const t_inputrec *ir, + gmx_bool bBCheck, + cginfo_mb_t *cginfo_mb) { gmx_domdec_comm_t *comm; @@ -2609,17 +2595,12 @@ void dd_init_bondeds(FILE *fplog, if (comm->systemInfo.filterBondedCommunication) { /* Communicate atoms beyond the cut-off for bonded interactions */ - comm = dd->comm; - - comm->cglink = make_charge_group_links(mtop, cginfo_mb); - - comm->bLocalCG = init_bLocalCG(mtop); + comm->bondedLinks = makeBondedLinks(mtop, cginfo_mb); } else { /* Only communicate atoms based on cut-off */ - comm->cglink = nullptr; - comm->bLocalCG = nullptr; + comm->bondedLinks = nullptr; } } diff --git a/src/gromacs/domdec/domdec.h b/src/gromacs/domdec/domdec.h index c6d8612375..825a1918f3 100644 --- a/src/gromacs/domdec/domdec.h +++ b/src/gromacs/domdec/domdec.h @@ -319,9 +319,12 @@ void dd_init_local_top(const gmx_mtop_t &top_global, void dd_init_local_state(struct gmx_domdec_t *dd, const t_state *state_global, t_state *local_state); -/*! \brief Generate a list of links between charge groups that are linked by bonded interactions */ -t_blocka *make_charge_group_links(const gmx_mtop_t *mtop, - cginfo_mb_t *cginfo_mb); +/*! \brief Generate a list of links between atoms that are linked by bonded interactions + * + * Also stores whether atoms are linked in \p cginfo_mb. + */ +t_blocka *makeBondedLinks(const gmx_mtop_t *mtop, + cginfo_mb_t *cginfo_mb); /*! \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_internal.h b/src/gromacs/domdec/domdec_internal.h index 457c65fb62..3d24a1885e 100644 --- a/src/gromacs/domdec/domdec_internal.h +++ b/src/gromacs/domdec/domdec_internal.h @@ -588,10 +588,8 @@ struct gmx_domdec_comm_t // NOLINT (clang-analyzer-optin.performance.Padding) std::unique_ptr updateGroupsCog; /* Data for the optional filtering of communication of atoms for bonded interactions */ - /**< Links between cg's through bonded interactions */ - t_blocka *cglink = nullptr; - /**< Local cg availability, TODO: remove when group scheme is removed */ - char *bLocalCG = nullptr; + /**< Links between atoms through bonded interactions */ + t_blocka *bondedLinks = nullptr; /* The DLB state, possible values are defined above */ DlbState dlbState; diff --git a/src/gromacs/domdec/domdec_topology.cpp b/src/gromacs/domdec/domdec_topology.cpp index d079dac6d9..af9626ad94 100644 --- a/src/gromacs/domdec/domdec_topology.cpp +++ b/src/gromacs/domdec/domdec_topology.cpp @@ -1930,8 +1930,8 @@ static std::vector make_at2cg(const t_block &cgs) return at2cg; } -t_blocka *make_charge_group_links(const gmx_mtop_t *mtop, - cginfo_mb_t *cginfo_mb) +t_blocka *makeBondedLinks(const gmx_mtop_t *mtop, + cginfo_mb_t *cginfo_mb) { t_blocka *link; cginfo_mb_t *cgi_mb; diff --git a/src/gromacs/domdec/partition.cpp b/src/gromacs/domdec/partition.cpp index 3d708665c8..a2a8a08e83 100644 --- a/src/gromacs/domdec/partition.cpp +++ b/src/gromacs/domdec/partition.cpp @@ -466,7 +466,7 @@ static void restoreAtomGroups(gmx_domdec_t *dd, //! Sets the cginfo structures. static void dd_set_cginfo(gmx::ArrayRef index_gl, int cg0, int cg1, - t_forcerec *fr, char *bLocalCG) + t_forcerec *fr) { if (fr != nullptr) { @@ -478,14 +478,6 @@ static void dd_set_cginfo(gmx::ArrayRef index_gl, int cg0, int cg1, cginfo[cg] = ddcginfo(cginfo_mb, index_gl[cg]); } } - - if (bLocalCG != nullptr) - { - for (int cg = cg0; cg < cg1; cg++) - { - bLocalCG[index_gl[cg]] = TRUE; - } - } } //! Makes the mappings between global and local atom indices during DD repartioning. @@ -538,45 +530,10 @@ static void make_dd_indices(gmx_domdec_t *dd, } } -//! Checks the charge-group assignements. -static int check_bLocalCG(gmx_domdec_t *dd, int ncg_sys, const char *bLocalCG, - const char *where) -{ - int nerr = 0; - if (bLocalCG == nullptr) - { - return nerr; - } - for (size_t i = 0; i < dd->globalAtomGroupIndices.size(); i++) - { - if (!bLocalCG[dd->globalAtomGroupIndices[i]]) - { - fprintf(stderr, - "DD rank %d, %s: atom group %zu, global atom group %d is not marked in bLocalCG (ncg_home %d)\n", dd->rank, where, i + 1, dd->globalAtomGroupIndices[i] + 1, dd->ncg_home); - nerr++; - } - } - size_t ngl = 0; - for (int i = 0; i < ncg_sys; i++) - { - if (bLocalCG[i]) - { - ngl++; - } - } - if (ngl != dd->globalAtomGroupIndices.size()) - { - fprintf(stderr, "DD rank %d, %s: In bLocalCG %zu atom groups are marked as local, whereas there are %zu\n", dd->rank, where, ngl, dd->globalAtomGroupIndices.size()); - nerr++; - } - - return nerr; -} - //! Checks whether global and local atom indices are consistent. -static void check_index_consistency(gmx_domdec_t *dd, - int natoms_sys, int ncg_sys, - const char *where) +static void check_index_consistency(const gmx_domdec_t *dd, + int natoms_sys, + const char *where) { int nerr = 0; @@ -640,8 +597,6 @@ static void check_index_consistency(gmx_domdec_t *dd, } } - nerr += check_bLocalCG(dd, ncg_sys, dd->comm->bLocalCG, where); - if (nerr > 0) { gmx_fatal(FARGS, "DD rank %d, %s: %d atom(group) index inconsistencies", @@ -649,14 +604,13 @@ static void check_index_consistency(gmx_domdec_t *dd, } } -//! Clear all DD global state indices, starting from \p atomGroupStart and \p atomStart +//! Clear all DD global state indices static void clearDDStateIndices(gmx_domdec_t *dd, - int atomGroupStart, - int atomStart) + const bool keepLocalAtomIndices) { gmx_ga2la_t &ga2la = *dd->ga2la; - if (atomStart == 0) + if (!keepLocalAtomIndices) { /* Clear the whole list without the overhead of searching */ ga2la.clear(); @@ -670,15 +624,6 @@ static void clearDDStateIndices(gmx_domdec_t *dd, } } - char *bLocalCG = dd->comm->bLocalCG; - if (bLocalCG) - { - for (size_t atomGroup = atomGroupStart; atomGroup < dd->globalAtomGroupIndices.size(); atomGroup++) - { - bLocalCG[dd->globalAtomGroupIndices[atomGroup]] = FALSE; - } - } - dd_clear_local_vsite_indices(dd); if (dd->constraints) @@ -1478,21 +1423,19 @@ static void make_cell2at_index(gmx_domdec_comm_dim_t *cd, } //! Returns whether a link is missing. -static gmx_bool missing_link(t_blocka *link, int cg_gl, const char *bLocalCG) +static gmx_bool missing_link(const t_blocka &link, + const int globalAtomIndex, + const gmx_ga2la_t &ga2la) { - int i; - gmx_bool bMiss; - - bMiss = FALSE; - for (i = link->index[cg_gl]; i < link->index[cg_gl+1]; i++) + for (int i = link.index[globalAtomIndex]; i < link.index[globalAtomIndex + 1]; i++) { - if (!bLocalCG[link->a[i]]) + if (!ga2la.findHome(link.a[i])) { - bMiss = TRUE; + return true; } } - return bMiss; + return false; } //! Domain corners for communication, a maximum of 4 i-zones see a j domain @@ -1832,8 +1775,8 @@ get_zone_pulse_cgs(gmx_domdec_t *dd, (bDist2B && r2 < r_bcomm2)) && (!bBondComm || (GET_CGINFO_BOND_INTER(cginfo[cg]) && - missing_link(comm->cglink, globalAtomGroupIndices[cg], - comm->bLocalCG))))) + missing_link(*comm->bondedLinks, globalAtomGroupIndices[cg], + *dd->ga2la))))) { /* Store the local and global atom group indices and position */ localAtomGroups->push_back(cg); @@ -1884,7 +1827,7 @@ static void setup_dd_communication(gmx_domdec_t *dd, { int dim_ind, dim, dim0, dim1, dim2, dimd, nat_tot; int nzone, nzone_send, zone, zonei, cg0, cg1; - int c, i, cg, cg_gl; + int c; int *zone_cg_range, pos_cg; gmx_domdec_comm_t *comm; gmx_domdec_zones_t *zones; @@ -1979,7 +1922,7 @@ static void setup_dd_communication(gmx_domdec_t *dd, /* Check if we need to compute triclinic distances along this dim */ bool distanceIsTriclinic = false; - for (i = 0; i <= dim_ind; i++) + for (int i = 0; i <= dim_ind; i++) { if (ddbox->tric_dir[dd->dim[i]]) { @@ -2028,7 +1971,7 @@ static void setup_dd_communication(gmx_domdec_t *dd, sf2_round[dimd] = 1; if (ddbox->tric_dir[dimd]) { - for (i = dd->dim[dimd]+1; i < DIM; i++) + for (int i = dd->dim[dimd] + 1; i < DIM; i++) { /* If we are shifted in dimension i * and the cell plane is tilted forward @@ -2186,17 +2129,10 @@ static void setup_dd_communication(gmx_domdec_t *dd, zone = (p == 0 ? 0 : nzone - 1); while (zone < nzone) { - for (cg = 0; cg < ind->nrecv[zone]; cg++) + for (int i = 0; i < ind->nrecv[zone]; i++) { - cg_gl = dd->globalAtomGroupIndices[pos_cg]; - fr->cginfo[pos_cg] = ddcginfo(cginfo_mb, cg_gl); - if (bBondComm) - { - /* Update the charge group presence, - * so we can use it in the next pass of the loop. - */ - comm->bLocalCG[cg_gl] = TRUE; - } + int globalAtomIndex = dd->globalAtomGroupIndices[pos_cg]; + fr->cginfo[pos_cg] = ddcginfo(cginfo_mb, globalAtomIndex); pos_cg++; } if (p == 0) @@ -2235,7 +2171,7 @@ static void setup_dd_communication(gmx_domdec_t *dd, */ dd_set_cginfo(dd->globalAtomGroupIndices, dd->ncg_home, dd->globalAtomGroupIndices.size(), - nullptr, comm->bLocalCG); + nullptr); } if (debug) @@ -2959,7 +2895,7 @@ void dd_partition_system(FILE *fplog, if (bMasterState) { /* Clear the old state */ - clearDDStateIndices(dd, 0, 0); + clearDDStateIndices(dd, false); ncgindex_set = 0; auto xGlobal = positionsFromStatePointer(state_global); @@ -2976,7 +2912,7 @@ void dd_partition_system(FILE *fplog, inc_nrnb(nrnb, eNR_CGCM, comm->atomRanges.numHomeAtoms()); - dd_set_cginfo(dd->globalAtomGroupIndices, 0, dd->ncg_home, fr, comm->bLocalCG); + dd_set_cginfo(dd->globalAtomGroupIndices, 0, dd->ncg_home, fr); } else if (state_local->ddp_count != dd->ddp_count) { @@ -2991,7 +2927,7 @@ void dd_partition_system(FILE *fplog, } /* Clear the old state */ - clearDDStateIndices(dd, 0, 0); + clearDDStateIndices(dd, false); /* Restore the atom group indices from state_local */ restoreAtomGroups(dd, state_local); @@ -3000,7 +2936,7 @@ void dd_partition_system(FILE *fplog, inc_nrnb(nrnb, eNR_CGCM, comm->atomRanges.numHomeAtoms()); - dd_set_cginfo(dd->globalAtomGroupIndices, 0, dd->ncg_home, fr, comm->bLocalCG); + dd_set_cginfo(dd->globalAtomGroupIndices, 0, dd->ncg_home, fr); set_ddbox(*dd, bMasterState, state_local->box, true, state_local->x, &ddbox); @@ -3012,7 +2948,7 @@ void dd_partition_system(FILE *fplog, /* We have the full state, only redistribute the cgs */ /* Clear the non-home indices */ - clearDDStateIndices(dd, dd->ncg_home, comm->atomRanges.numHomeAtoms()); + clearDDStateIndices(dd, true); ncgindex_set = 0; /* To avoid global communication, we do not recompute the extent @@ -3341,8 +3277,7 @@ void dd_partition_system(FILE *fplog, if (comm->ddSettings.DD_debug > 0) { /* Set the env var GMX_DD_DEBUG if you suspect corrupted indices */ - check_index_consistency(dd, top_global.natoms, ncg_mtop(&top_global), - "after partitioning"); + check_index_consistency(dd, top_global.natoms, "after partitioning"); } wallcycle_stop(wcycle, ewcDOMDEC); diff --git a/src/gromacs/domdec/redistribute.cpp b/src/gromacs/domdec/redistribute.cpp index f56512a7ed..d27455043b 100644 --- a/src/gromacs/domdec/redistribute.cpp +++ b/src/gromacs/domdec/redistribute.cpp @@ -127,10 +127,8 @@ copyMovedUpdateGroupCogs(gmx::ArrayRef move, } static void clear_and_mark_ind(gmx::ArrayRef move, - gmx::ArrayRef globalAtomGroupIndices, gmx::ArrayRef globalAtomIndices, gmx_ga2la_t *ga2la, - char *bLocalCG, int *cell_index) { for (gmx::index a = 0; a < move.ssize(); a++) @@ -139,10 +137,6 @@ static void clear_and_mark_ind(gmx::ArrayRef move, { /* Clear the global indices */ ga2la->erase(globalAtomIndices[a]); - if (bLocalCG) - { - bLocalCG[globalAtomGroupIndices[a]] = FALSE; - } /* Signal that this atom has moved using the ns cell index. * Here we set it to -1. fill_grid will change it * from -1 to NSGRID_SIGNAL_MOVED_FAC*grid->ncells. @@ -742,8 +736,8 @@ void dd_redistribute_cg(FILE *fplog, int64_t step, int *moved = getMovedBuffer(comm, 0, dd->ncg_home); clear_and_mark_ind(move, - dd->globalAtomGroupIndices, dd->globalAtomIndices, - dd->ga2la, comm->bLocalCG, + dd->globalAtomIndices, + dd->ga2la, moved); /* Now we can remove the excess global atom-group indices from the list */ @@ -913,10 +907,6 @@ void dd_redistribute_cg(FILE *fplog, int64_t step, /* Set the cginfo */ fr->cginfo[home_pos_cg] = ddcginfo(cginfo_mb, globalAtomGroupIndex); - if (comm->bLocalCG) - { - comm->bLocalCG[globalAtomGroupIndex] = TRUE; - } auto x = makeArrayRef(state->x); auto v = makeArrayRef(state->v); -- 2.22.0