clang-tidy-11 fixes for listed_forces
authorejjordan <ejjordan@kth.se>
Mon, 19 Apr 2021 18:09:25 +0000 (20:09 +0200)
committerAndrey Alekseenko <al42and@gmail.com>
Tue, 20 Apr 2021 05:43:54 +0000 (05:43 +0000)
src/gromacs/listed_forces/gpubonded_impl.cpp
src/gromacs/listed_forces/orires.cpp
src/gromacs/listed_forces/pairs.cpp
src/gromacs/listed_forces/tests/.clang-tidy [new file with mode: 0644]

index ebe0f95085188b5b747650e7723f14cdf7315332..0e3f2cb54cadc06ffeaf4fb0c53a5a6d8ad2f61c 100644 (file)
@@ -45,6 +45,7 @@
 
 #include "config.h"
 
+#include <algorithm>
 #include <string>
 
 #include "gromacs/listed_forces/gpubonded.h"
@@ -58,21 +59,16 @@ namespace gmx
 //! Returns whether there are any interactions in ilists suitable for a GPU.
 static bool someInteractionsCanRunOnGpu(const InteractionLists& ilists)
 {
-    for (int fType : fTypesOnGpu)
-    {
-        if (!ilists[fType].iatoms.empty())
-        {
-            // Perturbation is not implemented in the GPU bonded
-            // kernels. If all the interactions were actually
-            // perturbed, then that will be detected later on each
-            // domain, and work will never run on the GPU. This is
-            // very unlikely to occur, and has little run-time cost,
-            // so we don't complicate the code by catering for it
-            // here.
-            return true;
-        }
-    }
-    return false;
+    // Perturbation is not implemented in the GPU bonded
+    // kernels. If all the interactions were actually
+    // perturbed, then that will be detected later on each
+    // domain, and work will never run on the GPU. This is
+    // very unlikely to occur, and has little run-time cost,
+    // so we don't complicate the code by catering for it
+    // here.
+    return std::any_of(fTypesOnGpu.begin(), fTypesOnGpu.end(), [ilists](int fType) {
+        return !ilists[fType].iatoms.empty();
+    });
 }
 
 //! Returns whether there are any bonded interactions in the global topology suitable for a GPU.
index 8adb3d20a5af90f6f9d713dd817880c0949e8083..17bfa83b655a971f68fdf04c24cd1cc2d07f6c61 100644 (file)
@@ -444,10 +444,10 @@ real calc_orires_dev(const gmx_multisim_t* ms,
     }
 
     clear_rvec(com);
-    mtot       = 0;
-    int  j     = 0;
-    auto massT = md->massT;
-    auto cORF  = md->cORF;
+    mtot        = 0;
+    int   j     = 0;
+    auto* massT = md->massT;
+    auto* cORF  = md->cORF;
     for (int i = 0; i < md->nr; i++)
     {
         if (cORF[i] == 0)
index 0f4bef271474ade17481be5fa35646e764990ace..9e73bfa9f4feb42a8d258a9b4980c334d03b1241 100644 (file)
@@ -427,11 +427,11 @@ static real do_pairs_general(int                 ftype,
 
     const real epsfac = fr->ic->epsfac;
 
-    bFreeEnergy     = FALSE;
-    auto cENER      = md->cENER;
-    auto bPerturbed = md->bPerturbed;
-    auto chargeA    = md->chargeA;
-    auto chargeB    = md->chargeB;
+    bFreeEnergy      = FALSE;
+    auto* cENER      = md->cENER;
+    auto* bPerturbed = md->bPerturbed;
+    auto* chargeA    = md->chargeA;
+    auto* chargeB    = md->chargeB;
     for (i = 0; (i < nbonds);)
     {
         itype = iatoms[i++];
@@ -592,7 +592,7 @@ static void do_pairs_simple(int              nbonds,
     std::int32_t aj[pack_size];
     real         coeff[3 * pack_size];
 #endif
-    auto chargeA = md->chargeA;
+    auto* chargeA = md->chargeA;
 
     /* nbonds is #pairs*nfa1, here we step pack_size pairs */
     for (int i = 0; i < nbonds; i += pack_size * nfa1)
diff --git a/src/gromacs/listed_forces/tests/.clang-tidy b/src/gromacs/listed_forces/tests/.clang-tidy
new file mode 100644 (file)
index 0000000..0adf51e
--- /dev/null
@@ -0,0 +1,91 @@
+# List of rationales for check suppressions (where known).
+# This have to precede the list because inline comments are not
+# supported by clang-tidy.
+#
+#         -cppcoreguidelines-non-private-member-variables-in-classes,
+#         -misc-non-private-member-variables-in-classes,
+# We intend a gradual transition to conform to this guideline, but it
+# is not practical to implement yet.
+#
+#         -readability-isolate-declaration,
+# Declarations like "int a, b;" are readable. Some forms are not, and
+# those might reasonably be suggested against during code review.
+#
+#         -cppcoreguidelines-avoid-c-arrays,
+# C arrays are still necessary in many places with legacy code
+#
+#         -cppcoreguidelines-avoid-magic-numbers,
+#         -readability-magic-numbers,
+# We have many legitimate use cases for magic numbers
+#
+#         -cppcoreguidelines-macro-usage,
+# We do use too many macros, and we should fix many of them, but there
+# is no reasonable way to suppress the check e.g. in src/config.h and
+# configuring the build is a major legitimate use of macros.
+#
+#         -cppcoreguidelines-narrowing-conversions,
+#         -bugprone-narrowing-conversions
+# We have many cases where int is converted to float and we don't care
+# enough about such potential loss of precision to use explicit casts
+# in large numbers of places.
+#
+#         -google-readability-avoid-underscore-in-googletest-name
+# We need to use underscores for readability for our legacy types
+# and command-line parameter names
+#
+#         -misc-no-recursion
+# We have way too many functions and methods relying on recursion
+#
+#         -cppcoreguidelines-avoid-non-const-global-variables
+# There are quite a lot of static variables in the test code that
+# can not be replaced.
+#
+#         -modernize-avoid-bind
+# Some code needs to use std::bind and can't be modernized quickly.
+Checks:  clang-diagnostic-*,-clang-analyzer-*,-clang-analyzer-security.insecureAPI.strcpy,
+         bugprone-*,misc-*,readability-*,performance-*,mpi-*,
+         -readability-inconsistent-declaration-parameter-name,
+         -readability-function-size,-readability-else-after-return,
+         modernize-use-nullptr,modernize-use-emplace,
+         modernize-make-unique,modernize-make-shared,
+         modernize-avoid-bind,
+         modernize-use-override,
+         modernize-redundant-void-arg,modernize-use-bool-literals,
+         cppcoreguidelines-*,-cppcoreguidelines-pro-*,-cppcoreguidelines-owning-memory,
+         -cppcoreguidelines-no-malloc,-cppcoreguidelines-special-member-functions,
+         -cppcoreguidelines-avoid-goto,
+         google-*,-google-build-using-namespace,-google-explicit-constructor,
+         -google-readability-function-size,-google-readability-todo,-google-runtime-int,
+         -cppcoreguidelines-non-private-member-variables-in-classes,
+         -misc-non-private-member-variables-in-classes,
+         -readability-isolate-declaration,
+         -cppcoreguidelines-avoid-c-arrays,
+         -cppcoreguidelines-avoid-magic-numbers,
+         -readability-magic-numbers,
+         -cppcoreguidelines-macro-usage,
+         -cppcoreguidelines-narrowing-conversions,
+         -bugprone-narrowing-conversions,
+         -google-readability-avoid-underscore-in-googletest-name,
+         -cppcoreguidelines-init-variables,
+         -misc-no-recursion,
+         -cppcoreguidelines-avoid-non-const-global-variables,
+         -modernize-avoid-bind
+HeaderFilterRegex: .*
+CheckOptions:
+  - key:           cppcoreguidelines-special-member-functions.AllowSoleDefaultDtor
+    value:         1
+  - key:           modernize-make-unique.IncludeStyle
+    value:         google
+  - key:           modernize-make-shared.IncludeStyle
+    value:         google
+  - key:           readability-implicit-bool-conversion.AllowIntegerConditions
+    value:         1
+  - key:           readability-implicit-bool-conversion.AllowPointerConditions
+    value:         1
+  - key:           bugprone-dangling-handle.HandleClasses
+    value:         std::basic_string_view; nonstd::sv_lite::basic_string_view
+# Permit passing shard pointers by value for sink parameters
+  - key:           performance-unnecessary-copy-initialization.AllowedTypes
+    value:         shared_ptr
+  - key:           performance-unnecessary-value-param.AllowedTypes
+    value:         shared_ptr