Make LocalTopologyChecker class and hide implementation details
authorMark Abraham <mark.j.abraham@gmail.com>
Tue, 1 Jun 2021 09:51:58 +0000 (11:51 +0200)
committerPascal Merz <pascal.merz@me.com>
Mon, 7 Jun 2021 18:13:46 +0000 (18:13 +0000)
This allows capturing useful state that is only used when writing the
error output, without leaking dependencies for implementation details
to high-level code.

Some minor improvements to const correctness of the error output. Also
moved it into gmx namespace.

Minor improvement to include order

Removed unused forward declaration in domdec.h

Refs #3887

13 files changed:
src/gromacs/domdec/domdec.cpp
src/gromacs/domdec/domdec.h
src/gromacs/domdec/domdec_struct.h
src/gromacs/domdec/localtopologychecker.cpp
src/gromacs/domdec/localtopologychecker.h
src/gromacs/domdec/partition.cpp
src/gromacs/mdlib/stat.cpp
src/gromacs/mdlib/update_vv.cpp
src/gromacs/mdlib/update_vv.h
src/gromacs/mdrun/md.cpp
src/gromacs/mdrun/mimic.cpp
src/gromacs/mdrun/rerun.cpp
src/gromacs/modularsimulator/computeglobalselement.cpp

index de3aaf1cb9e7afefbbf5f2a2977b8ea18450426b..4aa94fa887de4697271403f7dfda19cb87e260ae 100644 (file)
@@ -3022,8 +3022,8 @@ gmx_domdec_t* DomainDecompositionBuilder::Impl::build(LocalAtomSetManager* atomS
 
     dd->atomSets = atomSets;
 
-    dd->localTopologyChecker =
-            std::make_unique<LocalTopologyChecker>(mtop_, dd->comm->systemInfo.useUpdateGroups);
+    dd->localTopologyChecker = std::make_unique<LocalTopologyChecker>(
+            mdlog_, cr_, mtop_, dd->comm->systemInfo.useUpdateGroups);
 
     return dd;
 }
@@ -3220,6 +3220,16 @@ void communicateGpuHaloForces(const t_commrec& cr, bool accumulateForces)
     }
 }
 
+const gmx::LocalTopologyChecker& dd_localTopologyChecker(const gmx_domdec_t& dd)
+{
+    return *dd.localTopologyChecker;
+}
+
+gmx::LocalTopologyChecker* dd_localTopologyChecker(gmx_domdec_t* dd)
+{
+    return dd->localTopologyChecker.get();
+}
+
 void dd_init_local_state(const gmx_domdec_t& dd, const t_state* state_global, t_state* state_local)
 {
     std::array<int, 5> buf;
index d35b02c5391980be0345620fe3d9c31dc187a0c9..20a7c6994563644e27c5e591c342e5268681a7fb 100644 (file)
@@ -87,12 +87,12 @@ namespace gmx
 struct AtomInfoWithinMoleculeBlock;
 class DeviceStreamManager;
 class ForceWithShiftForces;
+class LocalTopologyChecker;
 class MDLogger;
 class RangePartitioning;
 class VirtualSitesHandler;
 template<typename>
 class ArrayRef;
-enum class DDBondedChecking : bool;
 } // namespace gmx
 
 /*! \brief Returns the global topology atom number belonging to local atom index i.
@@ -239,7 +239,15 @@ void dd_move_x_and_v_vsites(const gmx_domdec_t& dd, const matrix box, rvec* x, r
  */
 gmx::ArrayRef<const int> dd_constraints_nlocalatoms(const gmx_domdec_t* dd);
 
-/* In domdec_top.c */
+/*! Const getter for the local topology checker
+ *
+ * \returns Const handle to local topology checker */
+const gmx::LocalTopologyChecker& dd_localTopologyChecker(const gmx_domdec_t& dd);
+
+/*! Getter for the local topology checker
+ *
+ * \returns Handle to local topology checker */
+gmx::LocalTopologyChecker* dd_localTopologyChecker(gmx_domdec_t* dd);
 
 /*! \brief Construct local state */
 void dd_init_local_state(const gmx_domdec_t& dd, const t_state* state_global, t_state* local_state);
index 98467b8f1a8d71894fa9c1c5521ec12bad3264d8..613a62e4665b47e429f837dc9dcf386e3aa7fa77 100644 (file)
@@ -78,7 +78,7 @@ namespace gmx
 template<typename T>
 class HashedMap;
 class LocalAtomSetManager;
-struct LocalTopologyChecker;
+class LocalTopologyChecker;
 class GpuHaloExchange;
 } // namespace gmx
 
index 0ffb8199deae3ae0cc40b3c99b67893263ede2fa..c4af1d1d320e7666d899da05cfd43075840ecc6d 100644 (file)
 
 #include "gmxpre.h"
 
+#include "gromacs/domdec/localtopologychecker.h"
+
+#include <optional>
 #include <string>
 #include <vector>
 
-#include "gromacs/domdec/localtopologychecker.h"
-
 #include "gromacs/domdec/domdec_internal.h"
 #include "gromacs/domdec/reversetopology.h"
 #include "gromacs/gmxlib/network.h"
@@ -64,8 +65,8 @@
 
 #include "dump.h"
 
-using gmx::ArrayRef;
-using gmx::RVec;
+namespace gmx
+{
 
 /*! \brief Checks whether interactions have been assigned for one function type
  *
@@ -76,7 +77,7 @@ using gmx::RVec;
 static void flagInteractionsForType(const int              ftype,
                                     const InteractionList& il,
                                     const reverse_ilist_t& ril,
-                                    const gmx::Range<int>& atomRange,
+                                    const Range<int>&      atomRange,
                                     const int              numAtomsPerMolecule,
                                     ArrayRef<const int>    globalAtomIndices,
                                     ArrayRef<int>          isAssigned)
@@ -140,19 +141,19 @@ static void flagInteractionsForType(const int              ftype,
  *
  * \note This function needs to be called on all ranks (contains a global summation)
  */
-static std::string printMissingInteractionsMolblock(t_commrec*               cr,
+static std::string printMissingInteractionsMolblock(const t_commrec*         cr,
                                                     const gmx_reverse_top_t& rt,
                                                     const char*              moltypename,
                                                     const reverse_ilist_t&   ril,
-                                                    const gmx::Range<int>&   atomRange,
+                                                    const Range<int>&        atomRange,
                                                     const int                numAtomsPerMolecule,
                                                     const int                numMolecules,
                                                     const InteractionDefinitions& idef)
 {
-    const int               nril_mol = ril.index[numAtomsPerMolecule];
-    std::vector<int>        isAssigned(numMolecules * nril_mol, 0);
-    gmx::StringOutputStream stream;
-    gmx::TextWriter         log(&stream);
+    const int          nril_mol = ril.index[numAtomsPerMolecule];
+    std::vector<int>   isAssigned(numMolecules * nril_mol, 0);
+    StringOutputStream stream;
+    TextWriter         log(&stream);
 
     for (int ftype = 0; ftype < F_NRE; ftype++)
     {
@@ -220,8 +221,8 @@ static std::string printMissingInteractionsMolblock(t_commrec*               cr,
 }
 
 /*! \brief Help print error output when interactions are missing */
-static void printMissingInteractionsAtoms(const gmx::MDLogger&          mdlog,
-                                          t_commrec*                    cr,
+static void printMissingInteractionsAtoms(const MDLogger&               mdlog,
+                                          const t_commrec*              cr,
                                           const gmx_mtop_t&             mtop,
                                           const InteractionDefinitions& idef)
 {
@@ -234,7 +235,7 @@ static void printMissingInteractionsAtoms(const gmx::MDLogger&          mdlog,
         const gmx_moltype_t& moltype = mtop.moltype[molb.type];
         const int            a_start = a_end;
         a_end                        = a_start + molb.nmol * moltype.atoms.nr;
-        const gmx::Range<int> atomRange(a_start, a_end);
+        const Range<int> atomRange(a_start, a_end);
 
         auto warning = printMissingInteractionsMolblock(
                 cr,
@@ -251,8 +252,8 @@ static void printMissingInteractionsAtoms(const gmx::MDLogger&          mdlog,
 }
 
 /*! \brief Print error output when interactions are missing */
-[[noreturn]] static void dd_print_missing_interactions(const gmx::MDLogger& mdlog,
-                                                       t_commrec*           cr,
+[[noreturn]] static void dd_print_missing_interactions(const MDLogger&  mdlog,
+                                                       const t_commrec* cr,
                                                        const int numBondedInteractionsOverAllDomains,
                                                        const int expectedNumGlobalBondedInteractions,
                                                        const gmx_mtop_t&     top_global,
@@ -330,7 +331,7 @@ static void printMissingInteractionsAtoms(const gmx::MDLogger&          mdlog,
     }
     else
     {
-        errorMessage = gmx::formatString(
+        errorMessage = formatString(
                 "%d of the %d bonded interactions could not be calculated because some atoms "
                 "involved moved further apart than the multi-body cut-off distance (%g nm) or the "
                 "two-body cut-off distance (%g nm), see option -rdd, for pairs and tabulated bonds "
@@ -343,8 +344,50 @@ static void printMissingInteractionsAtoms(const gmx::MDLogger&          mdlog,
     gmx_fatal_collective(FARGS, cr->mpi_comm_mygroup, MASTER(cr), "%s", errorMessage.c_str());
 }
 
-namespace gmx
+/*! \brief Data to help check local topology construction
+ *
+ * Partitioning could incorrectly miss a bonded interaction.
+ * However, checking for that requires a global communication
+ * stage, which does not otherwise happen during partitioning. So,
+ * for performance, we do that alongside the first global energy
+ * reduction after a new DD is made. These variables handle
+ * whether the check happens, its input for this domain, output
+ * across all domains, and the expected value it should match. */
+class LocalTopologyChecker::Impl
 {
+public:
+    //! Constructor
+    Impl(const MDLogger& mdlog, const t_commrec* cr, const gmx_mtop_t& mtop, bool useUpdateGroups);
+
+    //! Objects used when reporting that interactions are missing
+    //! {
+    //! Logger
+    const MDLogger& mdlog_;
+    //! Communication record
+    const t_commrec* cr_;
+    //! Global system topology
+    const gmx_mtop_t& mtop_;
+    //! }
+
+    /*! \brief Number of bonded interactions found in the local
+     * topology for this domain. */
+    int numBondedInteractionsToReduce_ = 0;
+    /*! \brief Whether to check at the next global communication
+     * stage the total number of bonded interactions found.
+     *
+     * Cleared after that number is found. */
+    bool shouldCheckNumberOfBondedInteractions_ = false;
+    /*! \brief The total number of bonded interactions found in
+     * the local topology across all domains.
+     *
+     * Only has a value after reduction across all ranks, which is
+     * removed when it is again time to check after a new
+     * partition. */
+    std::optional<int> numBondedInteractionsOverAllDomains_;
+    //! The number of bonded interactions computed from the full system topology
+    int expectedNumGlobalBondedInteractions_ = 0;
+};
+
 
 /*! \brief Compute the total bonded interaction count
  *
@@ -366,74 +409,90 @@ static int computeExpectedNumGlobalBondedInteractions(const gmx_mtop_t& mtop, co
     return expectedNumGlobalBondedInteractions;
 }
 
-LocalTopologyChecker::LocalTopologyChecker(const gmx_mtop_t& mtop, const bool useUpdateGroups) :
-    expectedNumGlobalBondedInteractions(computeExpectedNumGlobalBondedInteractions(mtop, useUpdateGroups))
+LocalTopologyChecker::Impl::Impl(const MDLogger&   mdlog,
+                                 const t_commrec*  cr,
+                                 const gmx_mtop_t& mtop,
+                                 const bool        useUpdateGroups) :
+    mdlog_(mdlog),
+    cr_(cr),
+    mtop_(mtop),
+    expectedNumGlobalBondedInteractions_(computeExpectedNumGlobalBondedInteractions(mtop, useUpdateGroups))
 {
 }
 
-} // namespace gmx
+LocalTopologyChecker::LocalTopologyChecker(const MDLogger&   mdlog,
+                                           const t_commrec*  cr,
+                                           const gmx_mtop_t& mtop,
+                                           const bool        useUpdateGroups) :
+    impl_(std::make_unique<Impl>(mdlog, cr, mtop, useUpdateGroups))
+{
+}
+
+LocalTopologyChecker::~LocalTopologyChecker() = default;
 
-void scheduleCheckOfLocalTopology(gmx_domdec_t* dd, const int numBondedInteractionsToReduce)
+LocalTopologyChecker::LocalTopologyChecker(LocalTopologyChecker&&) noexcept = default;
+
+LocalTopologyChecker& LocalTopologyChecker::operator=(LocalTopologyChecker&& other) noexcept
 {
-    dd->localTopologyChecker->numBondedInteractionsToReduce = numBondedInteractionsToReduce;
+    impl_ = std::move(other.impl_);
+    return *this;
+}
+
+void LocalTopologyChecker::scheduleCheckOfLocalTopology(const int numBondedInteractionsToReduce)
+{
+    impl_->numBondedInteractionsToReduce_ = numBondedInteractionsToReduce;
     // Note that it's possible for this to still be true from the last
     // time it was set, e.g. if repartitioning was triggered before
     // global communication that would have acted on the true
     // value. This could happen for example when replica exchange took
     // place soon after a partition.
-    dd->localTopologyChecker->shouldCheckNumberOfBondedInteractions = true;
+    impl_->shouldCheckNumberOfBondedInteractions_ = true;
     // Clear the old global value, which is now invalid
-    dd->localTopologyChecker->numBondedInteractionsOverAllDomains.reset();
+    impl_->numBondedInteractionsOverAllDomains_.reset();
 }
 
-bool shouldCheckNumberOfBondedInteractions(const gmx_domdec_t& dd)
+bool LocalTopologyChecker::shouldCheckNumberOfBondedInteractions() const
 {
-    return dd.localTopologyChecker->shouldCheckNumberOfBondedInteractions;
+    return impl_->shouldCheckNumberOfBondedInteractions_;
 }
 
-int numBondedInteractions(const gmx_domdec_t& dd)
+int LocalTopologyChecker::numBondedInteractions() const
 {
-    return dd.localTopologyChecker->numBondedInteractionsToReduce;
+    return impl_->numBondedInteractionsToReduce_;
 }
 
-void setNumberOfBondedInteractionsOverAllDomains(gmx_domdec_t* dd, int newValue)
+void LocalTopologyChecker::setNumberOfBondedInteractionsOverAllDomains(const int newValue)
 {
-    GMX_RELEASE_ASSERT(!dd->localTopologyChecker->numBondedInteractionsOverAllDomains.has_value(),
+    GMX_RELEASE_ASSERT(!impl_->numBondedInteractionsOverAllDomains_.has_value(),
                        "Cannot set number of bonded interactions because it is already set");
-    dd->localTopologyChecker->numBondedInteractionsOverAllDomains.emplace(newValue);
+    impl_->numBondedInteractionsOverAllDomains_.emplace(newValue);
 }
 
-void checkNumberOfBondedInteractions(const gmx::MDLogger&  mdlog,
-                                     t_commrec*            cr,
-                                     const gmx_mtop_t&     top_global,
-                                     const gmx_localtop_t* top_local,
-                                     ArrayRef<const RVec>  x,
-                                     const matrix          box)
+void LocalTopologyChecker::checkNumberOfBondedInteractions(const gmx_localtop_t* top_local,
+                                                           ArrayRef<const RVec>  x,
+                                                           const matrix          box)
 {
-    GMX_RELEASE_ASSERT(
-            DOMAINDECOMP(cr),
-            "No need to check number of bonded interactions when not using domain decomposition");
-    if (cr->dd->localTopologyChecker->shouldCheckNumberOfBondedInteractions)
+    if (impl_->shouldCheckNumberOfBondedInteractions_)
     {
-        GMX_RELEASE_ASSERT(cr->dd->localTopologyChecker->numBondedInteractionsOverAllDomains.has_value(),
+        GMX_RELEASE_ASSERT(impl_->numBondedInteractionsOverAllDomains_.has_value(),
                            "The check for the total number of bonded interactions requires the "
                            "value to have been reduced across all domains");
-        if (cr->dd->localTopologyChecker->numBondedInteractionsOverAllDomains.value()
-            != cr->dd->localTopologyChecker->expectedNumGlobalBondedInteractions)
+        if (impl_->numBondedInteractionsOverAllDomains_.value() != impl_->expectedNumGlobalBondedInteractions_)
         {
-            dd_print_missing_interactions(
-                    mdlog,
-                    cr,
-                    cr->dd->localTopologyChecker->numBondedInteractionsOverAllDomains.value(),
-                    cr->dd->localTopologyChecker->expectedNumGlobalBondedInteractions,
-                    top_global,
-                    top_local,
-                    x,
-                    box); // Does not return
+            dd_print_missing_interactions(impl_->mdlog_,
+                                          impl_->cr_,
+                                          impl_->numBondedInteractionsOverAllDomains_.value(),
+                                          impl_->expectedNumGlobalBondedInteractions_,
+                                          impl_->mtop_,
+                                          top_local,
+                                          x,
+                                          box); // Does not return
         }
         // Now that the value is set and the check complete, future
         // global communication should not compute the value until
         // after the next partitioning.
-        cr->dd->localTopologyChecker->shouldCheckNumberOfBondedInteractions = false;
+        impl_->shouldCheckNumberOfBondedInteractions_ = false;
     }
 }
+
+} // namespace gmx
index 69b3a2e3bdfd21e964881ae9afe128ea7915c2ae..49766aa35e3096eda1bccba265b5d06f27e87348 100644 (file)
 #ifndef GMX_DOMDEC_LOCALTOPOLOGYCHECKER_H
 #define GMX_DOMDEC_LOCALTOPOLOGYCHECKER_H
 
-#include <optional>
+#include <memory>
 
 #include "gromacs/math/vectypes.h"
 
-struct gmx_domdec_t;
 struct gmx_localtop_t;
 struct gmx_mtop_t;
 struct t_commrec;
@@ -59,79 +58,70 @@ namespace gmx
 class MDLogger;
 template<typename>
 class ArrayRef;
-enum class DDBondedChecking : bool;
 } // namespace gmx
 
 namespace gmx
 {
 
-struct LocalTopologyChecker
+/*! \brief Has responsibility for checking that the local topology
+ * distributed across domains describes a total number of bonded
+ * interactions that matches the system topology
+ *
+ * Because this check is not urgent, the communication that it
+ * requires is done at the next opportunity, rather than requiring
+ * extra communication. If the check fails, a fatal error stops
+ * execution. In principle, if there was a bug, GROMACS might crash in
+ * the meantime because of the wrong forces. However as a bug is
+ * unlikely, we optimize by avoiding creating extra overhead from
+ * communication.
+ */
+class LocalTopologyChecker
 {
 public:
-    //! Constructor
-    LocalTopologyChecker(const gmx_mtop_t& mtop, bool useUpdateGroups);
-    /*! \brief Data to help check local topology construction
-     *
-     * Partitioning could incorrectly miss a bonded interaction.
-     * However, checking for that requires a global communication
-     * stage, which does not otherwise happen during partitioning. So,
-     * for performance, we do that alongside the first global energy
-     * reduction after a new DD is made. These variables handle
-     * whether the check happens, its input for this domain, output
-     * across all domains, and the expected value it should match. */
-    /*! \{ */
-    /*! \brief Number of bonded interactions found in the local
-     * topology for this domain. */
-    int numBondedInteractionsToReduce = 0;
-    /*! \brief Whether to check at the next global communication
-     * stage the total number of bonded interactions found.
-     *
-     * Cleared after that number is found. */
-    bool shouldCheckNumberOfBondedInteractions = false;
-    /*! \brief The total number of bonded interactions found in
-     * the local topology across all domains.
-     *
-     * Only has a value after reduction across all ranks, which is
-     * removed when it is again time to check after a new
-     * partition. */
-    std::optional<int> numBondedInteractionsOverAllDomains;
-    //! The number of bonded interactions computed from the full system topology
-    int expectedNumGlobalBondedInteractions = 0;
-    /*! \} */
-};
+    /*! \brief Constructor
+     * \param[in]    mdlog            Logger
+     * \param[in]    cr               Communication object
+     * \param[in]    mtop             Global system topology
+     * \param[in]    useUpdateGroups  Whether update groups are in use
+     */
+    LocalTopologyChecker(const MDLogger& mdlog, const t_commrec* cr, const gmx_mtop_t& mtop, bool useUpdateGroups);
+    //! Destructor
+    ~LocalTopologyChecker();
+    //! Move constructor
+    LocalTopologyChecker(LocalTopologyChecker&& other) noexcept;
+    //! Move assignment
+    LocalTopologyChecker& operator=(LocalTopologyChecker&& other) noexcept;
 
-} // namespace gmx
+    /*! \brief Set that the local topology should be checked via
+     * observables reduction whenever that reduction is required by
+     * another module. */
+    void scheduleCheckOfLocalTopology(int numBondedInteractionsToReduce);
 
-//! Set that the local topology should be checked via observables reduction
-void scheduleCheckOfLocalTopology(gmx_domdec_t* dd, int numBondedInteractionsToReduce);
+    /*! \brief Return whether the total bonded interaction count across
+     * domains should be checked in observables reduction this step. */
+    bool shouldCheckNumberOfBondedInteractions() const;
 
-/*! \brief Return whether the total bonded interaction count across
- * domains should be checked in observables reduction. */
-bool shouldCheckNumberOfBondedInteractions(const gmx_domdec_t& dd);
+    //! Return the number of bonded interactions in this domain.
+    int numBondedInteractions() const;
 
-//! Return the number of bonded interactions in this domain.
-int numBondedInteractions(const gmx_domdec_t& dd);
+    /*! \brief Set total bonded interaction count across domains. */
+    void setNumberOfBondedInteractionsOverAllDomains(int newValue);
 
-/*! \brief Set total bonded interaction count across domains. */
-void setNumberOfBondedInteractionsOverAllDomains(gmx_domdec_t* dd, int newValue);
+    /*! \brief Check whether bonded interactions are missing from the reverse topology
+     * produced by domain decomposition.
+     *
+     * \param[in]    top_local  Local topology for the error message
+     * \param[in]    x          Position vector for the error message
+     * \param[in]    box        Box matrix for the error message
+     */
+    void checkNumberOfBondedInteractions(const gmx_localtop_t* top_local,
+                                         ArrayRef<const RVec>  x,
+                                         const matrix          box);
 
-/*! \brief Check whether bonded interactions are missing from the reverse topology
- * produced by domain decomposition.
- *
- * Must only be called when DD is active.
- *
- * \param[in]    mdlog                                  Logger
- * \param[in]    cr                                     Communication object
- * \param[in]    top_global                             Global topology for the error message
- * \param[in]    top_local                              Local topology for the error message
- * \param[in]    x                                      Position vector for the error message
- * \param[in]    box                                    Box matrix for the error message
- */
-void checkNumberOfBondedInteractions(const gmx::MDLogger&           mdlog,
-                                     t_commrec*                     cr,
-                                     const gmx_mtop_t&              top_global,
-                                     const gmx_localtop_t*          top_local,
-                                     gmx::ArrayRef<const gmx::RVec> x,
-                                     const matrix                   box);
+private:
+    class Impl;
+    std::unique_ptr<Impl> impl_;
+};
 
+} // namespace gmx
 #endif
index 46cef192345cf1dd94c2b43328c051bb09ee9cb4..7dca75dc80ad03aa7315a1a9c56cb97fbc5c99c6 100644 (file)
@@ -3208,7 +3208,7 @@ void dd_partition_system(FILE*                     fplog,
                                                           state_local->x,
                                                           top_global,
                                                           top_local);
-    scheduleCheckOfLocalTopology(dd, numBondedInteractionsToReduce);
+    dd->localTopologyChecker->scheduleCheckOfLocalTopology(numBondedInteractionsToReduce);
 
     wallcycle_sub_stop(wcycle, WallCycleSubCounter::DDMakeTop);
 
index 83ff1665daec2030c1530ed413be4998913b1909..c7e47c267f87d76ca3ecbbf96483228a7a30cc23 100644 (file)
@@ -276,7 +276,7 @@ void global_stat(const gmx_global_stat& gs,
         GMX_RELEASE_ASSERT(DOMAINDECOMP(cr),
                            "No need to check number of bonded interactions when not using domain "
                            "decomposition");
-        nb  = numBondedInteractions(*cr->dd);
+        nb  = cr->dd->localTopologyChecker->numBondedInteractions();
         inb = add_bind(rb, 1, &nb);
     }
     if (!sig.empty())
@@ -374,7 +374,7 @@ void global_stat(const gmx_global_stat& gs,
         GMX_RELEASE_ASSERT(DOMAINDECOMP(cr),
                            "No need to check number of bonded interactions when not using domain "
                            "decomposition");
-        setNumberOfBondedInteractionsOverAllDomains(cr->dd, gmx::roundToInt(nb));
+        cr->dd->localTopologyChecker->setNumberOfBondedInteractionsOverAllDomains(gmx::roundToInt(nb));
     }
 
     if (!sig.empty())
index e1738b52854ee8151077f4bb5d85c0d318e536e9..f29eabb9261105cecba2fa80ffe03218633696be 100644 (file)
@@ -82,7 +82,6 @@ void integrateVVFirstStep(int64_t                   step,
                           const t_fcdata&           fcdata,
                           t_extmass*                MassQ,
                           t_vcm*                    vcm,
-                          const gmx_mtop_t&         top_global,
                           const gmx_localtop_t&     top,
                           gmx_enerdata_t*           enerd,
                           gmx_ekindata_t*           ekind,
@@ -109,7 +108,6 @@ void integrateVVFirstStep(int64_t                   step,
                           gmx::SimulationSignaller* nullSignaller,
                           gmx::EnumerationArray<TrotterSequence, std::vector<int>> trotter_seq,
                           t_nrnb*                                                  nrnb,
-                          const gmx::MDLogger&                                     mdlog,
                           FILE*                                                    fplog,
                           gmx_wallcycle*                                           wcycle)
 {
@@ -192,7 +190,7 @@ void integrateVVFirstStep(int64_t                   step,
                     ((bGStat ? CGLO_GSTAT : 0) | (bCalcEner ? CGLO_ENERGY : 0)
                      | (bTemp ? CGLO_TEMPERATURE : 0) | (bPres ? CGLO_PRESSURE : 0)
                      | (bPres ? CGLO_CONSTRAINT : 0) | (bStopCM ? CGLO_STOPCM : 0) | CGLO_SCALEEKIN);
-            if (DOMAINDECOMP(cr) && shouldCheckNumberOfBondedInteractions(*cr->dd))
+            if (DOMAINDECOMP(cr) && dd_localTopologyChecker(*cr->dd).shouldCheckNumberOfBondedInteractions())
             {
                 cglo_flags |= CGLO_CHECK_NUMBER_OF_BONDED_INTERACTIONS;
             }
@@ -227,8 +225,8 @@ void integrateVVFirstStep(int64_t                   step,
                 EkinAveVel because it's needed for the pressure */
             if (DOMAINDECOMP(cr))
             {
-                checkNumberOfBondedInteractions(
-                        mdlog, cr, top_global, &top, makeConstArrayRef(state->x), state->box);
+                dd_localTopologyChecker(cr->dd)->checkNumberOfBondedInteractions(
+                        &top, makeConstArrayRef(state->x), state->box);
             }
             if (bStopCM)
             {
index f900c470ab90df688ea9ca03004e99b165c1f5e1..50ebbda78ff5b4ca5bc099a2d0fe5c756bb110f1 100644 (file)
@@ -89,7 +89,6 @@ enum class StartingBehavior : int;
  * \param[in]  fcdata            Force calculation data.
  * \param[in]  MassQ             Mass/pressure data.
  * \param[in]  vcm               Center of mass motion removal.
- * \param[in]  top_global        Global topology.
  * \param[in]  top               Local topology.
  * \param[in]  enerd             Energy data.
  * \param[in]  ekind             Kinetic energy data.
@@ -116,7 +115,6 @@ enum class StartingBehavior : int;
  * \param[in]  nullSignaller     Simulation signaller.
  * \param[in]  trotter_seq       NPT variables.
  * \param[in]  nrnb              Cycle counters.
- * \param[in]  mdlog             Logger.
  * \param[in]  fplog             Another logger.
  * \param[in]  wcycle            Wall-clock cycle counter.
  */
@@ -133,7 +131,6 @@ void integrateVVFirstStep(int64_t                   step,
                           const t_fcdata&           fcdata,
                           t_extmass*                MassQ,
                           t_vcm*                    vcm,
-                          const gmx_mtop_t&         top_global,
                           const gmx_localtop_t&     top,
                           gmx_enerdata_t*           enerd,
                           gmx_ekindata_t*           ekind,
@@ -160,7 +157,6 @@ void integrateVVFirstStep(int64_t                   step,
                           gmx::SimulationSignaller* nullSignaller,
                           gmx::EnumerationArray<TrotterSequence, std::vector<int>> trotter_seq,
                           t_nrnb*                                                  nrnb,
-                          const gmx::MDLogger&                                     mdlog,
                           FILE*                                                    fplog,
                           gmx_wallcycle*                                           wcycle);
 
index a7d344c4a079df185a29d3572bba7ea003637be6..80a820784d720b296678b3e88201f2c6e5daad6f 100644 (file)
@@ -662,7 +662,8 @@ void gmx::LegacySimulator::do_md()
             cglo_flags_iteration |= CGLO_STOPCM;
             cglo_flags_iteration &= ~CGLO_TEMPERATURE;
         }
-        if (DOMAINDECOMP(cr) && shouldCheckNumberOfBondedInteractions(*cr->dd) && cgloIteration == 0)
+        if (DOMAINDECOMP(cr) && dd_localTopologyChecker(*cr->dd).shouldCheckNumberOfBondedInteractions()
+            && cgloIteration == 0)
         {
             cglo_flags_iteration |= CGLO_CHECK_NUMBER_OF_BONDED_INTERACTIONS;
         }
@@ -702,8 +703,8 @@ void gmx::LegacySimulator::do_md()
     }
     if (DOMAINDECOMP(cr))
     {
-        checkNumberOfBondedInteractions(
-                mdlog, cr, top_global, &top, makeConstArrayRef(state->x), state->box);
+        dd_localTopologyChecker(cr->dd)->checkNumberOfBondedInteractions(
+                &top, makeConstArrayRef(state->x), state->box);
     }
     if (ir->eI == IntegrationAlgorithm::VVAK)
     {
@@ -1057,7 +1058,7 @@ void gmx::LegacySimulator::do_md()
              * the full step kinetic energy and possibly for T-coupling.*/
             /* This may not be quite working correctly yet . . . . */
             int cglo_flags = CGLO_GSTAT | CGLO_TEMPERATURE;
-            if (DOMAINDECOMP(cr) && shouldCheckNumberOfBondedInteractions(*cr->dd))
+            if (DOMAINDECOMP(cr) && dd_localTopologyChecker(*cr->dd).shouldCheckNumberOfBondedInteractions())
             {
                 cglo_flags |= CGLO_CHECK_NUMBER_OF_BONDED_INTERACTIONS;
             }
@@ -1085,8 +1086,8 @@ void gmx::LegacySimulator::do_md()
                             cglo_flags);
             if (DOMAINDECOMP(cr))
             {
-                checkNumberOfBondedInteractions(
-                        mdlog, cr, top_global, &top, makeConstArrayRef(state->x), state->box);
+                dd_localTopologyChecker(cr->dd)->checkNumberOfBondedInteractions(
+                        &top, makeConstArrayRef(state->x), state->box);
             }
         }
         clear_mat(force_vir);
@@ -1237,7 +1238,6 @@ void gmx::LegacySimulator::do_md()
                                  fcdata,
                                  &MassQ,
                                  &vcm,
-                                 top_global,
                                  top,
                                  enerd,
                                  ekind,
@@ -1264,7 +1264,6 @@ void gmx::LegacySimulator::do_md()
                                  &nullSignaller,
                                  trotter_seq,
                                  nrnb,
-                                 mdlog,
                                  fplog,
                                  wcycle);
             if (vsite != nullptr && needVirtualVelocitiesThisStep)
@@ -1718,13 +1717,13 @@ void gmx::LegacySimulator::do_md()
                                 | (!EI_VV(ir->eI) && bStopCM ? CGLO_STOPCM : 0)
                                 | (!EI_VV(ir->eI) ? CGLO_TEMPERATURE : 0)
                                 | (!EI_VV(ir->eI) ? CGLO_PRESSURE : 0) | CGLO_CONSTRAINT
-                                | (DOMAINDECOMP(cr) && shouldCheckNumberOfBondedInteractions(*cr->dd)
+                                | (DOMAINDECOMP(cr) && dd_localTopologyChecker(*cr->dd).shouldCheckNumberOfBondedInteractions()
                                            ? CGLO_CHECK_NUMBER_OF_BONDED_INTERACTIONS
                                            : 0));
                 if (DOMAINDECOMP(cr))
                 {
-                    checkNumberOfBondedInteractions(
-                            mdlog, cr, top_global, &top, makeConstArrayRef(state->x), state->box);
+                    dd_localTopologyChecker(cr->dd)->checkNumberOfBondedInteractions(
+                            &top, makeConstArrayRef(state->x), state->box);
                 }
                 if (!EI_VV(ir->eI) && bStopCM)
                 {
index b55f3cf550d04411880bd4bb79ce5f8c6bfaeff3..5c6fa4debb91d0a3499cdb4492aa5c734da67f60 100644 (file)
@@ -342,7 +342,7 @@ void gmx::LegacySimulator::do_mimic()
 
     {
         int cglo_flags = CGLO_GSTAT;
-        if (DOMAINDECOMP(cr) && shouldCheckNumberOfBondedInteractions(*cr->dd))
+        if (DOMAINDECOMP(cr) && dd_localTopologyChecker(*cr->dd).shouldCheckNumberOfBondedInteractions())
         {
             cglo_flags |= CGLO_CHECK_NUMBER_OF_BONDED_INTERACTIONS;
         }
@@ -372,8 +372,8 @@ void gmx::LegacySimulator::do_mimic()
                         cglo_flags);
         if (DOMAINDECOMP(cr))
         {
-            checkNumberOfBondedInteractions(
-                    mdlog, cr, top_global, &top, makeConstArrayRef(state->x), state->box);
+            dd_localTopologyChecker(cr->dd)->checkNumberOfBondedInteractions(
+                    &top, makeConstArrayRef(state->x), state->box);
         }
     }
 
@@ -631,7 +631,7 @@ void gmx::LegacySimulator::do_mimic()
             SimulationSignaller signaller(&signals, cr, ms, doInterSimSignal, doIntraSimSignal);
 
             int cglo_flags = CGLO_GSTAT | CGLO_ENERGY;
-            if (DOMAINDECOMP(cr) && shouldCheckNumberOfBondedInteractions(*cr->dd))
+            if (DOMAINDECOMP(cr) && dd_localTopologyChecker(*cr->dd).shouldCheckNumberOfBondedInteractions())
             {
                 cglo_flags |= CGLO_CHECK_NUMBER_OF_BONDED_INTERACTIONS;
             }
@@ -659,8 +659,8 @@ void gmx::LegacySimulator::do_mimic()
                             cglo_flags);
             if (DOMAINDECOMP(cr))
             {
-                checkNumberOfBondedInteractions(
-                        mdlog, cr, top_global, &top, makeConstArrayRef(state->x), state->box);
+                dd_localTopologyChecker(cr->dd)->checkNumberOfBondedInteractions(
+                        &top, makeConstArrayRef(state->x), state->box);
             }
         }
 
index d0783eb77508bae6f6bbf9cbd1f1e6c7d9c64967..407c0190f6daf49aeacbfee850c1ac53e22d805c 100644 (file)
@@ -387,7 +387,7 @@ void gmx::LegacySimulator::do_rerun()
 
     {
         int cglo_flags = CGLO_GSTAT;
-        if (DOMAINDECOMP(cr) && shouldCheckNumberOfBondedInteractions(*cr->dd))
+        if (DOMAINDECOMP(cr) && dd_localTopologyChecker(*cr->dd).shouldCheckNumberOfBondedInteractions())
         {
             cglo_flags |= CGLO_CHECK_NUMBER_OF_BONDED_INTERACTIONS;
         }
@@ -417,8 +417,8 @@ void gmx::LegacySimulator::do_rerun()
                         cglo_flags);
         if (DOMAINDECOMP(cr))
         {
-            checkNumberOfBondedInteractions(
-                    mdlog, cr, top_global, &top, makeConstArrayRef(state->x), state->box);
+            dd_localTopologyChecker(cr->dd)->checkNumberOfBondedInteractions(
+                    &top, makeConstArrayRef(state->x), state->box);
         }
     }
 
@@ -742,7 +742,7 @@ void gmx::LegacySimulator::do_rerun()
             SimulationSignaller signaller(&signals, cr, ms, doInterSimSignal, doIntraSimSignal);
 
             int cglo_flags = CGLO_GSTAT | CGLO_ENERGY;
-            if (DOMAINDECOMP(cr) && shouldCheckNumberOfBondedInteractions(*cr->dd))
+            if (DOMAINDECOMP(cr) && dd_localTopologyChecker(*cr->dd).shouldCheckNumberOfBondedInteractions())
             {
                 cglo_flags |= CGLO_CHECK_NUMBER_OF_BONDED_INTERACTIONS;
             }
@@ -770,8 +770,8 @@ void gmx::LegacySimulator::do_rerun()
                             cglo_flags);
             if (DOMAINDECOMP(cr))
             {
-                checkNumberOfBondedInteractions(
-                        mdlog, cr, top_global, &top, makeConstArrayRef(state->x), state->box);
+                dd_localTopologyChecker(cr->dd)->checkNumberOfBondedInteractions(
+                        &top, makeConstArrayRef(state->x), state->box);
             }
         }
 
index abfa5b37709f29198e1a3d975a35edbdfcf8844b..bd1d75a1c389550afb22b713396f5621d0858d60 100644 (file)
@@ -282,7 +282,7 @@ void ComputeGlobalsElement<algorithm>::compute(gmx::Step            step,
     const auto* lastbox = useLastBox ? statePropagatorData_->constPreviousBox()
                                      : statePropagatorData_->constBox();
 
-    if (DOMAINDECOMP(cr_) && shouldCheckNumberOfBondedInteractions(*cr_->dd))
+    if (DOMAINDECOMP(cr_) && dd_localTopologyChecker(*cr_->dd).shouldCheckNumberOfBondedInteractions())
     {
         flags |= CGLO_CHECK_NUMBER_OF_BONDED_INTERACTIONS;
     }
@@ -311,7 +311,7 @@ void ComputeGlobalsElement<algorithm>::compute(gmx::Step            step,
                     flags);
     if (DOMAINDECOMP(cr_))
     {
-        checkNumberOfBondedInteractions(mdlog_, cr_, top_global_, localTopology_, x, box);
+        dd_localTopologyChecker(cr_->dd)->checkNumberOfBondedInteractions(localTopology_, x, box);
     }
     if (flags & CGLO_STOPCM && !isInit)
     {