+int numBondedInteractions(const gmx_domdec_t& dd)
+{
+ return dd.reverse_top->impl_->numBondedInteractions;
+}
+
+void setNumberOfBondedInteractionsOverAllDomains(const gmx_domdec_t& dd, int newValue)
+{
+ GMX_RELEASE_ASSERT(!dd.reverse_top->impl_->numBondedInteractionsOverAllDomains.has_value(),
+ "Cannot set number of bonded interactions because it is already set");
+ dd.reverse_top->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,
+ gmx::ArrayRef<const gmx::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->reverse_top->impl_->shouldCheckNumberOfBondedInteractions)
+ {
+ GMX_RELEASE_ASSERT(cr->dd->reverse_top->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->reverse_top->impl_->numBondedInteractionsOverAllDomains.value()
+ != cr->dd->reverse_top->impl_->expectedNumGlobalBondedInteractions)
+ {
+ dd_print_missing_interactions(
+ mdlog,
+ cr,
+ cr->dd->reverse_top->impl_->numBondedInteractionsOverAllDomains.value(),
+ top_global,
+ 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->reverse_top->impl_->shouldCheckNumberOfBondedInteractions = false;
+ }