Rework atom locality validity checks
authorArtem Zhmurov <zhmurov@gmail.com>
Wed, 10 Mar 2021 09:43:52 +0000 (12:43 +0300)
committerAndrey Alekseenko <al42and@gmail.com>
Wed, 10 Mar 2021 14:59:03 +0000 (14:59 +0000)
The function that checks the validity of atom locality partly
duplicates its callers logic. The chacks are done naturally in
the callers and the function is used to construct and print
an error message.

src/gromacs/nbnxm/gpu_common_utils.h

index ea4f2d9d63787326bebc0fb69c2ddd29289c1a60..6694f2b2fb86eee868bdfb1ac1ae893bc43e8461 100644 (file)
@@ -45,7 +45,7 @@
 #include "config.h"
 
 #include "gromacs/listed_forces/gpubonded.h"
-#include "gromacs/utility/fatalerror.h"
+#include "gromacs/utility/exceptions.h"
 #include "gromacs/utility/range.h"
 #include "gromacs/nbnxm/nbnxm_gpu.h"
 
@@ -73,25 +73,6 @@ static inline bool canSkipNonbondedWork(const NbnxmGpu& nb, InteractionLocality
     return (iloc == InteractionLocality::NonLocal && nb.plist[iloc]->nsci == 0);
 }
 
-/*! \brief Check that atom locality values are valid for the GPU module.
- *
- *  In the GPU module atom locality "all" is not supported, the local and
- *  non-local ranges are treated separately.
- *
- *  \param[in] atomLocality atom locality specifier
- */
-static inline void validateGpuAtomLocality(const AtomLocality atomLocality)
-{
-    std::string str = gmx::formatString(
-            "Invalid atom locality passed (%d); valid here is only "
-            "local (%d) or nonlocal (%d)",
-            static_cast<int>(atomLocality),
-            static_cast<int>(AtomLocality::Local),
-            static_cast<int>(AtomLocality::NonLocal));
-
-    GMX_ASSERT(atomLocality == AtomLocality::Local || atomLocality == AtomLocality::NonLocal, str.c_str());
-}
-
 /*! \brief Convert atom locality to interaction locality.
  *
  *  In the current implementation the this is straightforward conversion:
@@ -102,7 +83,6 @@ static inline void validateGpuAtomLocality(const AtomLocality atomLocality)
  */
 static inline InteractionLocality gpuAtomToInteractionLocality(const AtomLocality atomLocality)
 {
-    validateGpuAtomLocality(atomLocality);
 
     /* determine interaction locality from atom locality */
     if (atomLocality == AtomLocality::Local)
@@ -115,7 +95,8 @@ static inline InteractionLocality gpuAtomToInteractionLocality(const AtomLocalit
     }
     else
     {
-        gmx_incons("Wrong locality");
+        GMX_THROW(gmx::InconsistentInputError(
+                "Only Local and NonLocal atom locities can be converted to interaction locality."));
     }
 }
 
@@ -142,17 +123,21 @@ static inline bool haveGpuShortRangeWork(const NbnxmGpu& nb, const gmx::Interact
 static inline gmx::Range<int> getGpuAtomRange(const NBAtomData* atomData, const AtomLocality atomLocality)
 {
     assert(atomData);
-    validateGpuAtomLocality(atomLocality);
 
     /* calculate the atom data index range based on locality */
     if (atomLocality == AtomLocality::Local)
     {
         return gmx::Range<int>(0, atomData->numAtomsLocal);
     }
-    else
+    else if (atomLocality == AtomLocality::NonLocal)
     {
         return gmx::Range<int>(atomData->numAtomsLocal, atomData->numAtoms);
     }
+    else
+    {
+        GMX_THROW(gmx::InconsistentInputError(
+                "Only Local and NonLocal atom locities can be used to get atom ranges in NBNXM."));
+    }
 }
 
 } // namespace Nbnxm