Move total bonded count to LocalTopologyChecker
authorMark Abraham <mark.j.abraham@gmail.com>
Mon, 31 May 2021 10:14:22 +0000 (10:14 +0000)
committerPaul Bauer <paul.bauer.q@gmail.com>
Mon, 31 May 2021 10:14:22 +0000 (10:14 +0000)
src/gromacs/domdec/domdec.cpp
src/gromacs/domdec/localtopologychecker.cpp
src/gromacs/domdec/localtopologychecker.h
src/gromacs/domdec/reversetopology.cpp
src/gromacs/domdec/reversetopology.h

index 2c648b83d4abfa7e264d6574cf0b78842b5215d4..b3532bd189f612e16ce969139cdd161438b381d0 100644 (file)
@@ -3020,7 +3020,8 @@ gmx_domdec_t* DomainDecompositionBuilder::Impl::build(LocalAtomSetManager* atomS
 
     dd->atomSets = atomSets;
 
-    dd->localTopologyChecker = std::make_unique<LocalTopologyChecker>();
+    dd->localTopologyChecker =
+            std::make_unique<LocalTopologyChecker>(mtop_, dd->comm->systemInfo.useUpdateGroups);
 
     return dd;
 }
index 15f7b4900a4f8952951dfd783c0de11f61cbe90d..0ffb8199deae3ae0cc40b3c99b67893263ede2fa 100644 (file)
@@ -253,7 +253,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,
-                                                       int numBondedInteractionsOverAllDomains,
+                                                       const int numBondedInteractionsOverAllDomains,
+                                                       const int expectedNumGlobalBondedInteractions,
                                                        const gmx_mtop_t&     top_global,
                                                        const gmx_localtop_t* top_local,
                                                        ArrayRef<const RVec>  x,
@@ -267,8 +268,7 @@ static void printMissingInteractionsAtoms(const gmx::MDLogger&          mdlog,
                     "Not all bonded interactions have been properly assigned to the domain "
                     "decomposition cells");
 
-    const int ndiff_tot = numBondedInteractionsOverAllDomains
-                          - dd->reverse_top->expectedNumGlobalBondedInteractions();
+    const int ndiff_tot = numBondedInteractionsOverAllDomains - expectedNumGlobalBondedInteractions;
 
     for (int ftype = 0; ftype < F_NRE; ftype++)
     {
@@ -281,7 +281,7 @@ static void printMissingInteractionsAtoms(const gmx::MDLogger&          mdlog,
     if (DDMASTER(dd))
     {
         GMX_LOG(mdlog.warning).appendText("A list of missing interactions:");
-        int rest_global = dd->reverse_top->expectedNumGlobalBondedInteractions();
+        int rest_global = expectedNumGlobalBondedInteractions;
         int rest        = numBondedInteractionsOverAllDomains;
         for (int ftype = 0; ftype < F_NRE; ftype++)
         {
@@ -336,13 +336,42 @@ static void printMissingInteractionsAtoms(const gmx::MDLogger&          mdlog,
                 "two-body cut-off distance (%g nm), see option -rdd, for pairs and tabulated bonds "
                 "also see option -ddcheck",
                 -ndiff_tot,
-                dd->reverse_top->expectedNumGlobalBondedInteractions(),
+                expectedNumGlobalBondedInteractions,
                 dd_cutoff_multibody(dd),
                 dd_cutoff_twobody(dd));
     }
     gmx_fatal_collective(FARGS, cr->mpi_comm_mygroup, MASTER(cr), "%s", errorMessage.c_str());
 }
 
+namespace gmx
+{
+
+/*! \brief Compute the total bonded interaction count
+ *
+ * \param[in] mtop              The global system topology
+ * \param[in] useUpdateGroups   Whether update groups are in use
+ *
+ * When using domain decomposition without update groups,
+ * constraint-type interactions can be split across domains, and so we
+ * do not consider them in this correctness check. Otherwise, we
+ * include them.
+ */
+static int computeExpectedNumGlobalBondedInteractions(const gmx_mtop_t& mtop, const bool useUpdateGroups)
+{
+    int expectedNumGlobalBondedInteractions = gmx_mtop_interaction_count(mtop, IF_BOND);
+    if (useUpdateGroups)
+    {
+        expectedNumGlobalBondedInteractions += gmx_mtop_interaction_count(mtop, IF_CONSTRAINT);
+    }
+    return expectedNumGlobalBondedInteractions;
+}
+
+LocalTopologyChecker::LocalTopologyChecker(const gmx_mtop_t& mtop, const bool useUpdateGroups) :
+    expectedNumGlobalBondedInteractions(computeExpectedNumGlobalBondedInteractions(mtop, useUpdateGroups))
+{
+}
+
+} // namespace gmx
 
 void scheduleCheckOfLocalTopology(gmx_domdec_t* dd, const int numBondedInteractionsToReduce)
 {
@@ -390,12 +419,13 @@ void checkNumberOfBondedInteractions(const gmx::MDLogger&  mdlog,
                            "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->reverse_top->expectedNumGlobalBondedInteractions())
+            != cr->dd->localTopologyChecker->expectedNumGlobalBondedInteractions)
         {
             dd_print_missing_interactions(
                     mdlog,
                     cr,
                     cr->dd->localTopologyChecker->numBondedInteractionsOverAllDomains.value(),
+                    cr->dd->localTopologyChecker->expectedNumGlobalBondedInteractions,
                     top_global,
                     top_local,
                     x,
index d2026222231769893911bedf296197dffd17f543..69b3a2e3bdfd21e964881ae9afe128ea7915c2ae 100644 (file)
@@ -68,6 +68,8 @@ namespace gmx
 struct 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.
@@ -93,6 +95,8 @@ public:
      * 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;
     /*! \} */
 };
 
index 0601c441f7b2d59f39c489a5ee0f0e5c5f3cd8c8..f733d6ad5395588792753f191a3c208d46a517e3 100644 (file)
@@ -97,9 +97,6 @@ struct gmx_reverse_top_t::Impl
     //! \brief Intermolecular reverse ilist
     reverse_ilist_t ril_intermol;
 
-    //! The number of bonded interactions computed from the full topology
-    int expectedNumGlobalBondedInteractions = 0;
-
     /* Work data structures for multi-threading */
     //! \brief Thread work array for local topology generation
     std::vector<thread_work_t> th_work;
@@ -299,11 +296,6 @@ const reverse_ilist_t& gmx_reverse_top_t::interactionListForMoleculeType(int mol
     return impl_->ril_mt[moleculeType];
 }
 
-int gmx_reverse_top_t::expectedNumGlobalBondedInteractions() const
-{
-    return impl_->expectedNumGlobalBondedInteractions;
-}
-
 ArrayRef<const MolblockIndices> gmx_reverse_top_t::molblockIndices() const
 {
     return impl_->mbi;
@@ -339,45 +331,13 @@ bool gmx_reverse_top_t::doSorting() const
     return impl_->ilsort != ilsortNO_FE;
 }
 
-/*! \brief Compute the total bonded interaction count
- *
- * \param[in] mtop                The global system topology
- * \param[in] includeConstraints  Whether constraint interactions are included in the count
- * \param[in] includeSettles      Whether settle interactions are included in the count
- *
- * When using domain decomposition without update groups,
- * constraint-type interactions can be split across domains, and so we
- * do not consider them in this correctness check. Otherwise, we
- * include them.
- */
-static int computeExpectedNumGlobalBondedInteractions(const gmx_mtop_t& mtop,
-                                                      const bool        includeConstraints,
-                                                      const bool        includeSettles)
-{
-    int expectedNumGlobalBondedInteractions = gmx_mtop_interaction_count(mtop, IF_BOND);
-    if (includeConstraints)
-    {
-        expectedNumGlobalBondedInteractions +=
-                gmx_mtop_ftype_count(mtop, F_CONSTR) + gmx_mtop_ftype_count(mtop, F_CONSTRNC);
-    }
-    if (includeSettles)
-    {
-        expectedNumGlobalBondedInteractions += gmx_mtop_ftype_count(mtop, F_SETTLE);
-    }
-    return expectedNumGlobalBondedInteractions;
-}
-
 /*! \brief Generate the reverse topology */
 gmx_reverse_top_t::Impl::Impl(const gmx_mtop_t&        mtop,
                               const bool               useFreeEnergy,
                               const ReverseTopOptions& reverseTopOptions) :
     options(reverseTopOptions),
     hasPositionRestraints(gmx_mtop_ftype_count(mtop, F_POSRES) + gmx_mtop_ftype_count(mtop, F_FBPOSRES) > 0),
-    bInterAtomicInteractions(mtop.bIntermolecularInteractions),
-    expectedNumGlobalBondedInteractions(
-            computeExpectedNumGlobalBondedInteractions(mtop,
-                                                       reverseTopOptions.includeConstraints,
-                                                       reverseTopOptions.includeSettles))
+    bInterAtomicInteractions(mtop.bIntermolecularInteractions)
 {
     bInterAtomicInteractions = mtop.bIntermolecularInteractions;
     ril_mt.resize(mtop.moltype.size());
index 6e3b7c1f54b87903fe61aebcfe1110cef9d374df..278a69f77ae710f7447fdea1fa888bd839aced01 100644 (file)
@@ -140,9 +140,6 @@ public:
     //! Gets the interaction list for the given molecule type
     const reverse_ilist_t& interactionListForMoleculeType(int moleculeType) const;
 
-    //! Returns the total count of bonded interactions, used for checking partitioning
-    int expectedNumGlobalBondedInteractions() const;
-
     //! Returns the molecule block indices
     gmx::ArrayRef<const MolblockIndices> molblockIndices() const;
     //! Returns whether the reverse topology describes intermolecular interactions