Update clang-tidy to clang version 8
authorMark Abraham <mark.j.abraham@gmail.com>
Sat, 6 Jul 2019 18:37:45 +0000 (20:37 +0200)
committerMark Abraham <mark.j.abraham@gmail.com>
Fri, 23 Aug 2019 09:20:13 +0000 (11:20 +0200)
Some new warnings are well intentioned, but not practical to turn on
in GROMACS given the limited suppression capabilities.

Rationales for suppressions of new warnings can be found in
src/.clang-tidy

Change-Id: I857d3790450e33a669c6a68ad846cae3783875e7

89 files changed:
docs/dev-manual/build-system.rst
docs/dev-manual/tools.rst
src/.clang-tidy
src/.clang-tidy.new.code
src/external/.clang-tidy
src/gromacs/analysisdata/abstractdata.cpp
src/gromacs/analysisdata/abstractdata.h
src/gromacs/analysisdata/datamodulemanager.cpp
src/gromacs/analysisdata/datamodulemanager.h
src/gromacs/awh/pointstate.h
src/gromacs/coordinateio/tests/coordinate_test.h
src/gromacs/domdec/hashedmap.h
src/gromacs/domdec/redistribute.cpp
src/gromacs/fft/fft.cpp
src/gromacs/fft/fft_fftpack.cpp
src/gromacs/fileio/tngio.cpp
src/gromacs/gmxana/gmx_nmeig.cpp
src/gromacs/gmxana/gmx_nmr.cpp
src/gromacs/gmxana/gmx_nmtraj.cpp
src/gromacs/gmxana/gmx_order.cpp
src/gromacs/gmxana/gmx_potential.cpp
src/gromacs/gmxana/gmx_rms.cpp
src/gromacs/gmxana/gmx_rmsdist.cpp
src/gromacs/gmxana/gmx_rotacf.cpp
src/gromacs/gmxana/gmx_vanhove.cpp
src/gromacs/gmxpreprocess/gen_vsite.cpp
src/gromacs/gmxpreprocess/grompp.cpp
src/gromacs/gmxpreprocess/pdb2gmx.cpp
src/gromacs/gmxpreprocess/readir.cpp
src/gromacs/gmxpreprocess/toppush.cpp
src/gromacs/gmxpreprocess/vsite_parm.cpp
src/gromacs/hardware/cpuinfo.cpp
src/gromacs/hardware/hardwaretopology.cpp
src/gromacs/math/gausstransform.cpp
src/gromacs/math/gausstransform.h
src/gromacs/math/tests/functions.cpp
src/gromacs/math/vec.h
src/gromacs/mdlib/calc_verletbuf.cpp
src/gromacs/mdlib/constr.cpp
src/gromacs/mdlib/constr.h
src/gromacs/mdlib/mdebin_bar.cpp
src/gromacs/mdlib/qmmm.cpp
src/gromacs/mdlib/sim_util.cpp
src/gromacs/mdlib/tests/constr.cpp
src/gromacs/mdlib/tests/constrtestdata.cpp
src/gromacs/mdlib/tests/constrtestrunners.cpp
src/gromacs/mdlib/tests/energyoutput.cpp
src/gromacs/mdlib/tests/settletestdata.cpp
src/gromacs/mdlib/updategroupscog.cpp
src/gromacs/mdrun/minimize.cpp
src/gromacs/mdrun/runner.cpp
src/gromacs/mdrun/runner.h
src/gromacs/nbnxm/atomdata.cpp
src/gromacs/nbnxm/grid.cpp
src/gromacs/nbnxm/gridset.h
src/gromacs/nbnxm/kerneldispatch.cpp
src/gromacs/nbnxm/kernels_reference/kernel_gpu_ref.cpp
src/gromacs/nbnxm/kernels_reference/kernel_ref_inner.h
src/gromacs/nbnxm/kernels_simd_2xmm/kernel_inner.h
src/gromacs/nbnxm/kernels_simd_2xmm/kernel_outer.h
src/gromacs/nbnxm/kernels_simd_4xm/kernel_inner.h
src/gromacs/nbnxm/kernels_simd_4xm/kernel_outer.h
src/gromacs/nbnxm/pairlist.cpp
src/gromacs/nbnxm/pairlistsets.h
src/gromacs/random/tabulatednormaldistribution.h
src/gromacs/restraint/manager.cpp
src/gromacs/restraint/manager.h
src/gromacs/selection/indexutil.cpp
src/gromacs/simd/simd.h
src/gromacs/topology/atomprop.cpp
src/gromacs/topology/atomprop.h
src/gromacs/topology/block.h
src/gromacs/topology/forcefieldparameters.cpp
src/gromacs/topology/idef.h
src/gromacs/topology/index.cpp
src/gromacs/topology/residuetypes.cpp
src/gromacs/topology/residuetypes.h
src/gromacs/topology/tests/exclusionblocks.cpp
src/gromacs/topology/topology.cpp
src/gromacs/trajectory/energyframe.cpp
src/gromacs/trajectory/energyframe.h
src/gromacs/utility/binaryinformation.cpp
src/gromacs/utility/cstringutil.cpp
src/gromacs/utility/fatalerror.cpp
src/gromacs/utility/keyvaluetree.h
src/gromacs/utility/strdb.cpp
src/testutils/testasserts.cpp
src/testutils/testasserts.h
src/testutils/textblockmatchers.cpp

index fbdbedb2f462d11f9681667a63d41acf368761cc..f7a3f0ab400ef653e9bc95913007e260046d4d58 100644 (file)
@@ -346,6 +346,28 @@ Variables affecting the ``all`` target
    inconvenient for a general user) can be added to the set controlled by this
    variable.
 
+.. cmake:: GMX_CLANG_TIDY
+
+  `clang-tidy <http://releases.llvm.org/8.0.0/tools/clang/tools/extra/docs/clang-tidy/index.html>`_
+  is used for static code analysis and (some) automated fixing of issues detected. clang-tidy is easy to install. It is contained in
+  the llvm binary `package <http://releases.llvm.org/download.html#8.0.0>`_. Only
+  version 8.0.* with libstdc++<7 or libc++ is supported. Others might miss tests or give false positives.
+  It is run automatically on Jenkins for each commit. Many checks have fixes which can automatically be
+  applied. To run it, the build has to be configured with
+  ``cmake -DGMX_CLANG_TIDY=ON -DGMX_OPENMP=no -DCMAKE_BUILD_TYPE=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS=on``.
+  Any ``CMAKE_BUILD_TYPE`` which enables asserts (e.g. ASAN) works. Such a configured build will
+  run both the compiler as well as clang-tidy when building. The name of the clang-tidy executable is set with
+  ``-DCLANG_TIDY=...``, and the full path to it can be set with ``-DCLANG_TIDY_EXE=...``.
+  To apply the automatic fixes to the issue identified clang-tidy should be run seperately (running clang-tidy
+  with ``-fix-errors`` as part of the build can corrupt header files). To fix a specific file run
+  ``clang-tidy -fix-errors -header-filter '.*' {file}``, to fix all files in parallel
+  ``run-clang-tidy.py -fix -header-filter '.*' '(?<!/selection/parser\.cpp|selection/scanner\.cpp)$'``,
+  and to fix all modified files ``run-clang-tidy.py -fix -header-filter '.*' $(git diff HEAD --name-only)``.
+  The run-clang-tidy.py script is in the
+  ``share/clang/`` subfolder of the llvm distribution. ``clang-tidy`` has to be able to find the
+  ``compile_commands.json`` file. Either run from the build folder or add a symlink to the source folder.
+  :cmake:`GMX_ENABLE_CCACHE` does not work with clang-tidy.
+
 Variables affecting special targets
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
index 0b84988c2736b3aab89dd9daa421d079c9c86d17..ba4130204295bd7f601989616c22cb0fb9e437b4 100644 (file)
@@ -71,32 +71,12 @@ unit testing (CTest)
   for each commit.
   Details can be found on a separate page on :doc:`testutils`.
 
-regression tests
-
-clang-tidy
-  `clang-tidy <http://releases.llvm.org/7.0.0/tools/clang/tools/extra/docs/clang-tidy/index.html>`_
-  is used for static code analysis. clang-tidy is easy to install. It is contained in
-  the llvm binary `package <http://releases.llvm.org/download.html#6.0.0>`_. Only
-  version 7.0.* with libstdc++<7 or libc++ is supported. Others might miss tests or give false positives.
-  It is run automatically on Jenkins for each commit. Many checks have fixes which can automatically be
-  applied. To run it, the build has to be configured with
-  ``cmake -DGMX_CLANG_TIDY=ON -DGMX_OPENMP=no -DCMAKE_BUILD_TYPE=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS=on``.
-  Any ``CMAKE_BUILD_TYPE`` which enables asserts (e.g. ASAN) works. Such a configured build will
-  run both the compiler as well as clang-tidy when building. The name of the clang-tidy executable is set with
-``-DCLANG_TIDY=...``, and the full path to it can be set with ``-DCLANG_TIDY_EXE=...``.
-  To apply the automatic fixes to the issue identified clang-tidy should be run sepereately (running clang-tidy
-  with ``-fix`` as part of the build can corrupt header files). To fix a specific file run
-  ``clang-tidy -fix -header-filter '.*' {file}``, to fix all files in parallel
-  ``run-clang-tidy.py -fix -header-filter '.*' '(?<!/selection/parser\.cpp|selection/scanner\.cpp)$'``,
-  and to fix all modified files ``run-clang-tidy.py -fix -header-filter '.*' $(git diff HEAD --name-only)``.
-  The run-clang-tidy.py script is in the
-  ``share/clang/`` subfolder of the llvm distribution. ``clang-tidy`` has to be able to find the
-  ``compile_commands.json`` file. Eithe run from the build folder or add a symlink to the source folder.
-
 clang static analyzer
 
 coverage
 
+regression tests
+
 .. _dev-formatting-tools:
 
 Code formatting and style
index 2e0898b39f18c833e9ea8b13becb29467d989971..6efdf2d87cbff903b029ec53f16cfcdc61c5c64e 100644 (file)
@@ -1,3 +1,34 @@
+# 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.
+
 Checks:  clang-diagnostic-*,-clang-analyzer-*,-clang-analyzer-security.insecureAPI.strcpy,
          bugprone-*,misc-*,readability-*,performance-*,mpi-*,
          -readability-inconsistent-declaration-parameter-name,
@@ -11,7 +42,16 @@ Checks:  clang-diagnostic-*,-clang-analyzer-*,-clang-analyzer-security.insecureA
          -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
+         -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
 HeaderFilterRegex: .*
 CheckOptions:
   - key:           cppcoreguidelines-special-member-functions.AllowSoleDefaultDtor
@@ -26,3 +66,8 @@ CheckOptions:
     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
index 5434a2da0842d6a73f12cbd00af9dcb4b04ec6ce..98c36ee119803b616b24a6288c586f1d77864b8b 100644 (file)
@@ -15,7 +15,16 @@ Checks:  clang-diagnostic-*,-clang-analyzer-*,
          -cppcoreguidelines-avoid-goto,
          google-*,-google-build-using-namespace,-google-explicit-constructor,
          -google-readability-todo,
-         -google-runtime-int
+         -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
 HeaderFilterRegex: .*
 CheckOptions:
   - key:           cppcoreguidelines-special-member-functions.AllowSoleDefaultDtor
@@ -30,3 +39,8 @@ CheckOptions:
     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
index de0482b7219d6dc0208cad153517064d17db54dd..10766f156640b5494d61c2c8de6464e64b010629 100644 (file)
@@ -1 +1,4 @@
-Checks: -*
+# We don't want any checks at all for external code, but that leads to
+# clang-tidy complaining that it is being run with no checks. So we
+# let it use a single check that is irrelevant for GROMACS.
+Checks: -clang-analyzer*,zircon-temporary-objects
index 341a979347a4673fc255f3f3028fe8d0b70baf88..39af90139bd8b62b5011ef31646e5c1654a83db1 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2010,2011,2012,2013,2014,2015,2018, by the GROMACS development team, led by
+ * Copyright (c) 2010,2011,2012,2013,2014,2015,2018,2019, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -165,21 +165,21 @@ AbstractAnalysisData::requestStorage(int nframes)
 
 
 void
-AbstractAnalysisData::addModule(AnalysisDataModulePointer module)
+AbstractAnalysisData::addModule(const AnalysisDataModulePointer &module)
 {
-    impl_->modules_.addModule(this, std::move(module));
+    impl_->modules_.addModule(this, module);
 }
 
 
 void
 AbstractAnalysisData::addColumnModule(int col, int span,
-                                      AnalysisDataModulePointer module)
+                                      const AnalysisDataModulePointer &module)
 {
     GMX_RELEASE_ASSERT(col >= 0 && span >= 1,
                        "Invalid columns specified for a column module");
     std::shared_ptr<AnalysisDataProxy> proxy(
             new AnalysisDataProxy(col, span, this));
-    proxy->addModule(std::move(module));
+    proxy->addModule(module);
     addModule(proxy);
 }
 
index b4a15e6d25e59856a229decb82571c5862291a64..d57ade64013eaa9f70d3689836e40945d1221b40 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2010,2011,2012,2013,2014,2015, by the GROMACS development team, led by
+ * Copyright (c) 2010,2011,2012,2013,2014,2015,2019, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -273,7 +273,7 @@ class AbstractAnalysisData
          * If the method throws, the state of the data object is not changed.
          * The state of the data module is indeterminate.
          */
-        void addModule(AnalysisDataModulePointer module);
+        void addModule(const AnalysisDataModulePointer &module);
         /*! \brief
          * Adds a module that processes only a subset of the columns.
          *
@@ -297,7 +297,7 @@ class AbstractAnalysisData
          *
          * \see addModule()
          */
-        void addColumnModule(int col, int span, AnalysisDataModulePointer module);
+        void addColumnModule(int col, int span, const AnalysisDataModulePointer &module);
         /*! \brief
          * Applies a module to process data that is ready.
          *
index c8e34606da7e74be5b641036155978e241852d43..58a4aee2cec76e0aa67c11b280e018fc37200817 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2010,2011,2012,2013,2014,2015,2016,2018, by the GROMACS development team, led by
+ * Copyright (c) 2010,2011,2012,2013,2014,2015,2016,2018,2019, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -284,8 +284,8 @@ AnalysisDataModuleManager::dataPropertyAboutToChange(DataProperty property, bool
 }
 
 void
-AnalysisDataModuleManager::addModule(AbstractAnalysisData      *data,
-                                     AnalysisDataModulePointer  module)
+AnalysisDataModuleManager::addModule(AbstractAnalysisData            *data,
+                                     const AnalysisDataModulePointer &module)
 {
     impl_->checkModuleProperties(*module);
     // TODO: Ensure that the system does not end up in an inconsistent state by
index 2bc9bdb64b65a1c5e3f154f6b3744bcb22bc349a..72909dc768ba75f822629f5cc924c77a82a7d0d5 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2010,2011,2012,2013,2014,2015, by the GROMACS development team, led by
+ * Copyright (c) 2010,2011,2012,2013,2014,2015,2019, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -119,8 +119,8 @@ class AnalysisDataModuleManager
          *
          * \see AbstractAnalysisData::addModule()
          */
-        void addModule(AbstractAnalysisData      *data,
-                       AnalysisDataModulePointer  module);
+        void addModule(AbstractAnalysisData            *data,
+                       const AnalysisDataModulePointer &module);
         /*! \brief
          * Applies a module to process data that is ready.
          *
index 221534441870fe925ffcd377676d6788fc44f4ce..4e177c42c9acc44396deb92f6df497a039189896 100644 (file)
@@ -316,7 +316,7 @@ class PointState
                 return false;
             }
 
-            for (int i = 0; i < numUpdatesSkipped; i++)
+            for (int64_t i = 0; i < numUpdatesSkipped; i++)
             {
                 /* This point was non-local at the time of the update meaning no weight */
                 updateFreeEnergyAndWeight(params, 0, weighthistScaling, logPmfSumScaling);
index 5b12ba30a8181066e2ed4ab2f0d2be5e69efc2cf..7fbaca8891da4dc1f771813920e2f2d6cb0ce09d 100644 (file)
@@ -193,7 +193,7 @@ class ModuleTest : public gmx::test::CommandLineTestBase,
          * \param[in] requirements Requirements for adding to the object.
          * \returns The newly created object.
          */
-        const TrajectoryFrameWriterPointer
+        TrajectoryFrameWriterPointer
         runTest(const char *filename, const OutputRequirements &requirements)
         {
             return createMinimalTrajectoryFrameWriter(filename,
index bb0ccedab97bf1cff86f49d895c90b595bff93fe..c12706f36f8fa72b2c1466364dcb2342e1eb8591 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2018, by the GROMACS development team, led by
+ * Copyright (c) 2018,2019, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -101,7 +101,7 @@ class HashedMap
             /* Make the hash table a power of 2 and at least 1.5 * #elements */
             int tableSize = 64;
             while (tableSize <= INT_MAX/2 &&
-                   numElementsEstimate*c_relTableSizeSetMin > tableSize)
+                   static_cast<float>(numElementsEstimate)*c_relTableSizeSetMin > tableSize)
             {
                 tableSize *= 2;
             }
index 4e5a5ea5f1f2565efaf2400a1aacaa5d69ccb8d2..d766f3f5910a4772d7632d67ce7b5c5126b09629 100644 (file)
@@ -89,7 +89,7 @@ copyMovedAtomsToBufferPerAtom(gmx::ArrayRef<const int> move,
 {
     int pos_vec[DIM*2] = { 0 };
 
-    for (int i = 0; i < move.ssize(); i++)
+    for (gmx::index i = 0; i < move.ssize(); i++)
     {
         /* Skip moved atoms */
         const int m = move[i];
@@ -110,7 +110,7 @@ copyMovedUpdateGroupCogs(gmx::ArrayRef<const int> move,
 {
     int pos_vec[DIM*2] = { 0 };
 
-    for (int g = 0; g < move.ssize(); g++)
+    for (gmx::index g = 0; g < move.ssize(); g++)
     {
         /* Skip moved atoms */
         const int m = move[g];
@@ -133,7 +133,7 @@ static void clear_and_mark_ind(gmx::ArrayRef<const int>      move,
                                char                         *bLocalCG,
                                int                          *cell_index)
 {
-    for (int a = 0; a < move.ssize(); a++)
+    for (gmx::index a = 0; a < move.ssize(); a++)
     {
         if (move[a] >= 0)
         {
index a141db16bc1d6a7fc5c613c6bd2bbf44bda94b42..23f1d25d927c1e0c8e6e174fa10ed79d7b75b5c8 100644 (file)
@@ -2,7 +2,7 @@
  * This file is part of the GROMACS molecular simulation package.
  *
  * Copyright (c) 1991-2003 Erik Lindahl, David van der Spoel, University of Groningen.
- * Copyright (c) 2013,2014,2015,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015,2017,2018,2019, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -77,7 +77,7 @@ gmx_fft_init_many_1d(gmx_fft_t *        pfft,
     }
     *pfft = nullptr;
 
-    if ( (fft = (gmx_many_fft_t)malloc(sizeof(struct gmx_many_fft))) == nullptr)
+    if ( (fft = static_cast<gmx_many_fft_t>(malloc(sizeof(struct gmx_many_fft)))) == nullptr)
     {
         return ENOMEM;
     }
@@ -86,7 +86,7 @@ gmx_fft_init_many_1d(gmx_fft_t *        pfft,
     fft->howmany = howmany;
     fft->dist    = 2*nx;
 
-    *pfft = (gmx_fft_t)fft;
+    *pfft = reinterpret_cast<gmx_fft_t>(fft);
     return 0;
 }
 
@@ -104,7 +104,7 @@ gmx_fft_init_many_1d_real(gmx_fft_t *        pfft,
     }
     *pfft = nullptr;
 
-    if ( (fft = (gmx_many_fft_t)malloc(sizeof(struct gmx_many_fft))) == nullptr)
+    if ( (fft = static_cast<gmx_many_fft_t>(malloc(sizeof(struct gmx_many_fft)))) == nullptr)
     {
         return ENOMEM;
     }
@@ -113,7 +113,7 @@ gmx_fft_init_many_1d_real(gmx_fft_t *        pfft,
     fft->howmany = howmany;
     fft->dist    = 2*(nx/2+1);
 
-    *pfft = (gmx_fft_t)fft;
+    *pfft = reinterpret_cast<gmx_fft_t>(fft);
     return 0;
 }
 
@@ -123,7 +123,7 @@ gmx_fft_many_1d     (gmx_fft_t                  fft,
                      void *                     in_data,
                      void *                     out_data)
 {
-    gmx_many_fft_t mfft = (gmx_many_fft_t)fft;
+    gmx_many_fft_t mfft = reinterpret_cast<gmx_many_fft_t>(fft);
     int            i, ret;
     for (i = 0; i < mfft->howmany; i++)
     {
@@ -132,8 +132,8 @@ gmx_fft_many_1d     (gmx_fft_t                  fft,
         {
             return ret;
         }
-        in_data  = (real*)in_data+mfft->dist;
-        out_data = (real*)out_data+mfft->dist;
+        in_data  = static_cast<real*>(in_data)+mfft->dist;
+        out_data = static_cast<real*>(out_data)+mfft->dist;
     }
     return 0;
 }
@@ -144,7 +144,7 @@ gmx_fft_many_1d_real     (gmx_fft_t                  fft,
                           void *                     in_data,
                           void *                     out_data)
 {
-    gmx_many_fft_t mfft = (gmx_many_fft_t)fft;
+    gmx_many_fft_t mfft = reinterpret_cast<gmx_many_fft_t>(fft);
     int            i, ret;
     for (i = 0; i < mfft->howmany; i++)
     {
@@ -153,8 +153,8 @@ gmx_fft_many_1d_real     (gmx_fft_t                  fft,
         {
             return ret;
         }
-        in_data  = (real*)in_data+mfft->dist;
-        out_data = (real*)out_data+mfft->dist;
+        in_data  = static_cast<real*>(in_data)+mfft->dist;
+        out_data = static_cast<real*>(out_data)+mfft->dist;
     }
     return 0;
 }
@@ -163,7 +163,7 @@ gmx_fft_many_1d_real     (gmx_fft_t                  fft,
 void
 gmx_many_fft_destroy(gmx_fft_t    fft)
 {
-    gmx_many_fft_t mfft = (gmx_many_fft_t)fft;
+    gmx_many_fft_t mfft = reinterpret_cast<gmx_many_fft_t>(fft);
     if (mfft != nullptr)
     {
         if (mfft->fft != nullptr)
index 33655730bd837e8dfc284669f6935cd628901caf..f87426fa675b988878bb5cb374efd420111c88f4 100644 (file)
@@ -2,7 +2,7 @@
  * This file is part of the GROMACS molecular simulation package.
  *
  * Copyright (c) 1991-2003 David van der Spoel, Erik Lindahl, University of Groningen.
- * Copyright (c) 2013,2014,2015,2016,2017, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015,2016,2017,2019, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -86,7 +86,7 @@ gmx_fft_init_1d(gmx_fft_t *        pfft,
     }
     *pfft = nullptr;
 
-    if ( (fft = (struct gmx_fft *)malloc(sizeof(struct gmx_fft))) == nullptr)
+    if ( (fft = static_cast<struct gmx_fft *>(malloc(sizeof(struct gmx_fft)))) == nullptr)
     {
         return ENOMEM;
     }
@@ -95,7 +95,7 @@ gmx_fft_init_1d(gmx_fft_t *        pfft,
     fft->n    = nx;
 
     /* Need 4*n storage for 1D complex FFT */
-    if ( (fft->work = (real *)malloc(sizeof(real)*(4*nx))) == nullptr)
+    if ( (fft->work = static_cast<real *>(malloc(sizeof(real)*(4*nx)))) == nullptr)
     {
         free(fft);
         return ENOMEM;
@@ -126,7 +126,7 @@ gmx_fft_init_1d_real(gmx_fft_t *        pfft,
     }
     *pfft = nullptr;
 
-    if ( (fft = (struct gmx_fft *)malloc(sizeof(struct gmx_fft))) == nullptr)
+    if ( (fft = static_cast<struct gmx_fft *>(malloc(sizeof(struct gmx_fft)))) == nullptr)
     {
         return ENOMEM;
     }
@@ -135,7 +135,7 @@ gmx_fft_init_1d_real(gmx_fft_t *        pfft,
     fft->n    = nx;
 
     /* Need 2*n storage for 1D real FFT */
-    if ((fft->work = (real *)malloc(sizeof(real)*(2*nx))) == nullptr)
+    if ((fft->work = static_cast<real *>(malloc(sizeof(real)*(2*nx)))) == nullptr)
     {
         free(fft);
         return ENOMEM;
@@ -168,7 +168,7 @@ gmx_fft_init_2d_real(gmx_fft_t *        pfft,
     *pfft = nullptr;
 
     /* Create the X transform */
-    if ( (fft = (struct gmx_fft *)malloc(sizeof(struct gmx_fft))) == nullptr)
+    if ( (fft = static_cast<struct gmx_fft *>(malloc(sizeof(struct gmx_fft)))) == nullptr)
     {
         return ENOMEM;
     }
@@ -178,7 +178,7 @@ gmx_fft_init_2d_real(gmx_fft_t *        pfft,
     /* Need 4*nx storage for 1D complex FFT, and another
      * 2*nx*nyc elements for complex-to-real storage in our high-level routine.
      */
-    if ( (fft->work = (real *)malloc(sizeof(real)*(4*nx+2*nx*nyc))) == nullptr)
+    if ( (fft->work = static_cast<real *>(malloc(sizeof(real)*(4*nx+2*nx*nyc)))) == nullptr)
     {
         free(fft);
         return ENOMEM;
@@ -211,8 +211,8 @@ gmx_fft_1d               (gmx_fft_t                  fft,
 
     if (n == 1)
     {
-        p1    = (real *)in_data;
-        p2    = (real *)out_data;
+        p1    = static_cast<real *>(in_data);
+        p2    = static_cast<real *>(out_data);
         p2[0] = p1[0];
         p2[1] = p1[1];
     }
@@ -222,8 +222,8 @@ gmx_fft_1d               (gmx_fft_t                  fft,
      */
     if (in_data != out_data)
     {
-        p1 = (real *)in_data;
-        p2 = (real *)out_data;
+        p1 = static_cast<real *>(in_data);
+        p2 = static_cast<real *>(out_data);
 
         /* n complex = 2*n real elements */
         for (i = 0; i < 2*n; i++)
@@ -238,11 +238,11 @@ gmx_fft_1d               (gmx_fft_t                  fft,
 
     if (dir == GMX_FFT_FORWARD)
     {
-        fftpack_cfftf1(n, (real *)out_data, fft->work+2*n, fft->work, fft->ifac, -1);
+        fftpack_cfftf1(n, static_cast<real *>(out_data), fft->work+2*n, fft->work, fft->ifac, -1);
     }
     else if (dir == GMX_FFT_BACKWARD)
     {
-        fftpack_cfftf1(n, (real *)out_data, fft->work+2*n, fft->work, fft->ifac, 1);
+        fftpack_cfftf1(n, static_cast<real *>(out_data), fft->work+2*n, fft->work, fft->ifac, 1);
     }
     else
     {
@@ -269,8 +269,8 @@ gmx_fft_1d_real          (gmx_fft_t                  fft,
 
     if (n == 1)
     {
-        p1    = (real *)in_data;
-        p2    = (real *)out_data;
+        p1    = static_cast<real *>(in_data);
+        p2    = static_cast<real *>(out_data);
         p2[0] = p1[0];
         if (dir == GMX_FFT_REAL_TO_COMPLEX)
         {
@@ -286,8 +286,8 @@ gmx_fft_1d_real          (gmx_fft_t                  fft,
          */
         if (in_data != out_data)
         {
-            p1 = (real *)in_data;
-            p2 = (real *)out_data;
+            p1 = static_cast<real *>(in_data);
+            p2 = static_cast<real *>(out_data);
 
             for (i = 0; i < 2*(n/2+1); i++)
             {
@@ -298,14 +298,14 @@ gmx_fft_1d_real          (gmx_fft_t                  fft,
         /* Elements 0 ..   n-1 in work are used for ffac values,
          * Elements n .. 2*n-1 are internal FFTPACK work space.
          */
-        fftpack_rfftf1(n, (real *)out_data, fft->work+n, fft->work, fft->ifac);
+        fftpack_rfftf1(n, static_cast<real *>(out_data), fft->work+n, fft->work, fft->ifac);
 
         /*
          * FFTPACK has a slightly more compact storage than we, time to
          * convert it: ove most of the array one step up to make room for
          * zero imaginary parts.
          */
-        p2 = (real *)out_data;
+        p2 = static_cast<real *>(out_data);
         for (i = n-1; i > 0; i--)
         {
             p2[i+1] = p2[i];
@@ -328,15 +328,15 @@ gmx_fft_1d_real          (gmx_fft_t                  fft,
          * is more compact than ours (2 reals) it will fit, so compact it
          * and copy on-the-fly to the output array.
          */
-        p1 = (real *) in_data;
-        p2 = (real *)out_data;
+        p1 = static_cast<real *>(in_data);
+        p2 = static_cast<real *>(out_data);
 
         p2[0] = p1[0];
         for (i = 1; i < n; i++)
         {
             p2[i] = p1[i+1];
         }
-        fftpack_rfftb1(n, (real *)out_data, fft->work+n, fft->work, fft->ifac);
+        fftpack_rfftb1(n, static_cast<real *>(out_data), fft->work+n, fft->work, fft->ifac);
     }
     else
     {
@@ -378,8 +378,8 @@ gmx_fft_2d_real          (gmx_fft_t                  fft,
          */
         if (in_data != out_data)
         {
-            p1 = (real *)in_data;
-            p2 = (real *)out_data;
+            p1 = static_cast<real *>(in_data);
+            p2 = static_cast<real *>(out_data);
 
             for (i = 0; i < nx; i++)
             {
@@ -454,8 +454,8 @@ gmx_fft_2d_real          (gmx_fft_t                  fft,
             /* Output (pointed to by data) is now in padded format.
              * Pack it into out_data if we were doing an out-of-place transform.
              */
-            p1 = (real *)data;
-            p2 = (real *)out_data;
+            p1 = reinterpret_cast<real *>(data);
+            p2 = static_cast<real *>(out_data);
 
             for (i = 0; i < nx; i++)
             {
index 862bb2c1b025c4e0dd4eee892e13f1dac41eee9e..13474a4fe19e75441bd5fd0282efbfb742a31d1d 100644 (file)
@@ -1323,7 +1323,7 @@ void gmx_tng_setup_atom_subgroup(gmx_tng_trajectory_t     gmx_tng,
         tng_molecule_name_set(tng, mol, name);
         tng_molecule_chain_add(tng, mol, "", &chain);
 
-        for (int i = 0; i < ind.ssize(); i++)
+        for (gmx::index i = 0; i < ind.ssize(); i++)
         {
             char        temp_name[256], temp_type[256];
 
index 078598875a53657fb8cd42330632f362742650ff..3a040fe57d8bd59812b024692104f08d173ac953 100644 (file)
@@ -170,7 +170,7 @@ nma_full_hessian(real                    *hess,
     {
         for (int i = 0; i < (end-begin+1); i++)
         {
-            for (int j = 0; j < atom_index.ssize(); j++)
+            for (gmx::index j = 0; j < atom_index.ssize(); j++)
             {
                 size_t aj = atom_index[j];
                 mass_fac = gmx::invsqrt(top->atoms.atom[aj].m);
@@ -236,7 +236,7 @@ nma_sparse_hessian(gmx_sparsematrix_t      *sparse_hessian,
     {
         for (i = 0; i < neig; i++)
         {
-            for (int j = 0; j < atom_index.ssize(); j++)
+            for (gmx::index j = 0; j < atom_index.ssize(); j++)
             {
                 size_t aj = atom_index[j];
                 mass_fac = gmx::invsqrt(top->atoms.atom[aj].m);
index 929a1d994a36f7ac4b8bfe9450f2b9ca44ca9ee1..a8eff5ea277a5fb43f566d997349eb32ea76022f 100644 (file)
@@ -306,7 +306,7 @@ static void calc_violations(real rt[], real rav3[], int nb, const int index[],
     *sa = sumaver;
 }
 
-static void analyse_disre(const char *voutfn,    int nframes,
+static void analyse_disre(const char *voutfn, int nframes,
                           real violaver[], real bounds[], int index[],
                           int pair[],      int nbounds,
                           const gmx_output_env_t *oenv)
@@ -335,7 +335,7 @@ static void analyse_disre(const char *voutfn,    int nframes,
         sumaver = 0;
         for (j = pair[i]; (j < pair[i+1]); j++)
         {
-            sumaver += gmx::square(violaver[j]/nframes);
+            sumaver += gmx::square(violaver[j]/real(nframes));
         }
         sumaver = std::max(0.0, mypow(sumaver, minsixth)-bounds[i]);
 
@@ -346,7 +346,7 @@ static void analyse_disre(const char *voutfn,    int nframes,
 #ifdef DEBUG
     for (j = 0; (j < dr.ndr); j++)
     {
-        fprintf(vout, "%10d  %10.5e\n", j, mypow(violaver[j]/nframes, minthird));
+        fprintf(vout, "%10d  %10.5e\n", j, mypow(violaver[j]/real(nframes), minthird));
     }
 #endif
     xvgrclose(vout);
@@ -882,7 +882,7 @@ int gmx_nmr(int argc, char *argv[])
         }
         for (i = 0; i < nor; i++)
         {
-            fprintf(out, "%5d  %g\n", or_label[i], orient[i]/norfr);
+            fprintf(out, "%5d  %g\n", or_label[i], orient[i]/real(norfr));
         }
         xvgrclose(out);
     }
@@ -897,7 +897,7 @@ int gmx_nmr(int argc, char *argv[])
         }
         for (i = 0; i < nor; i++)
         {
-            fprintf(out, "%5d  %g\n", or_label[i], orient[i]/norfr-oobs[i]);
+            fprintf(out, "%5d  %g\n", or_label[i], orient[i]/real(norfr)-oobs[i]);
         }
         xvgrclose(out);
     }
@@ -912,7 +912,7 @@ int gmx_nmr(int argc, char *argv[])
         }
         for (i = 0; i < nor; i++)
         {
-            fprintf(out, "%5d  %g\n", or_label[i], std::sqrt(odrms[i]/norfr));
+            fprintf(out, "%5d  %g\n", or_label[i], std::sqrt(odrms[i]/real(norfr)));
         }
         xvgrclose(out);
     }
index 63354ff9e0ee663e856b9a8210e65888d31990f7..b7777611e854aeda2e672b04e4147c45af640059 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014,2015,2017, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015,2017,2019, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -56,6 +56,7 @@
 #include "gromacs/utility/fatalerror.h"
 #include "gromacs/utility/futil.h"
 #include "gromacs/utility/smalloc.h"
+#include "gromacs/utility/strconvert.h"
 #include "gromacs/utility/stringutil.h"
 
 int gmx_nmtraj(int argc, char *argv[])
@@ -110,16 +111,10 @@ int gmx_nmtraj(int argc, char *argv[])
     real        *     eigval;
     int        *      dummy;
     real        *     invsqrtm;
-    real              fraction;
     int              *out_eigidx;
     rvec        *     this_eigvec;
     real              omega, Ekin, m, vel;
-    int               nmodes, nphases;
-    int              *imodes;
     real             *amplitude;
-    real             *phases;
-    const char       *p;
-    char             *pe;
     gmx_output_env_t *oenv;
 
     t_filenm          fnm[] =
@@ -144,43 +139,30 @@ int gmx_nmtraj(int argc, char *argv[])
 
     /* Find vectors and phases */
 
-    /* first find number of args in string */
-    nmodes = gmx::countWords(eignrvec);
-
-    snew(imodes, nmodes);
-    p = eignrvec;
-    for (i = 0; i < nmodes; i++)
+    std::vector<int> imodes;
+    for (const auto &imodeString : gmx::splitString(eignrvec))
     {
-        /* C indices start on 0 */
-        imodes[i] = std::strtol(p, &pe, 10)-1;
-        p         = pe;
+        imodes.emplace_back(gmx::fromStdString<int>(imodeString));
     }
+    int               nmodes = gmx::ssize(imodes);
 
-    /* Now read phases */
-    nphases = gmx::countWords(phasevec);
-
-    if (nphases > nmodes)
+    std::vector<real> phases;
+    phases.reserve(nmodes);
+    for (const auto &phaseString : gmx::splitString(phasevec))
     {
-        gmx_fatal(FARGS, "More phases than eigenvector indices specified.\n");
+        phases.emplace_back(gmx::fromStdString<int>(phaseString));
     }
+    int nphases = gmx::ssize(phases);
 
-    snew(phases, nmodes);
-    p = phasevec;
-
-    for (i = 0; i < nphases; i++)
+    if (nphases > nmodes)
     {
-        phases[i] = strtod(p, &pe);
-        p         = pe;
+        gmx_fatal(FARGS, "More phases than eigenvector indices specified.\n");
     }
 
     if (nmodes > nphases)
     {
         printf("Warning: Setting phase of last %d modes to zero...\n", nmodes-nphases);
-    }
-
-    for (i = nphases; i < nmodes; i++)
-    {
-        phases[i] = 0;
+        phases.resize(nmodes, 0);
     }
 
     atoms = &top.atoms;
@@ -303,7 +285,7 @@ int gmx_nmtraj(int argc, char *argv[])
 
     for (i = 0; i < nframes; i++)
     {
-        fraction = static_cast<real>(i)/nframes;
+        real fraction = static_cast<real>(i)/static_cast<real>(nframes);
         for (j = 0; j < natoms; j++)
         {
             copy_rvec(xav[j], xout[j]);
@@ -322,7 +304,7 @@ int gmx_nmtraj(int argc, char *argv[])
                 }
             }
         }
-        write_trx(out, natoms, dummy, atoms, i, static_cast<real>(i)/nframes, box, xout, nullptr, nullptr);
+        write_trx(out, natoms, dummy, atoms, i, fraction, box, xout, nullptr, nullptr);
     }
 
     fprintf(stderr, "\n");
index 87dda9fbc195807a7064ffe999e4a02753e7099a..0073ec72d218fa3a4d94c44f369332014d246e67 100644 (file)
@@ -89,7 +89,7 @@ static void find_nearest_neighbours(int ePBC,
     real     cost, cost2, *sgmol, *skmol, rmean, rmean2, r2, box2, *r_nn[4];
     t_pbc    pbc;
     int      sl_index;
-    int     *sl_count;
+    real    *sl_count;
     real     onethird = 1.0/3.0;
     /*  dmat = init_mat(maxidx, FALSE); */
     box2 = box[XX][XX] * box[XX][XX];
@@ -194,7 +194,7 @@ static void find_nearest_neighbours(int ePBC,
                 sgmol[i] += cost2;
 
                 /* determine distribution */
-                ibin = static_cast<int>(nsgbin * cost2);
+                ibin = static_cast<int>(static_cast<real>(nsgbin) * cost2);
                 if (ibin < nsgbin)
                 {
                     sgbin[ibin]++;
@@ -222,14 +222,14 @@ static void find_nearest_neighbours(int ePBC,
         *skmean += skmol[i];
 
         /* Compute sliced stuff */
-        sl_index           = static_cast<int>(std::round((1+x[i][slice_dim]/box[slice_dim][slice_dim])*nslice)) % nslice;
+        sl_index           = static_cast<int>(std::round((1+x[i][slice_dim]/box[slice_dim][slice_dim])*static_cast<real>(nslice))) % nslice;
         sgslice[sl_index] += sgmol[i];
         skslice[sl_index] += skmol[i];
         sl_count[sl_index]++;
     } /* loop over entries in index file */
 
-    *sgmean /= maxidx;
-    *skmean /= maxidx;
+    *sgmean /= static_cast<real>(maxidx);
+    *skmean /= static_cast<real>(maxidx);
 
     for (i = 0; (i < nslice); i++)
     {
@@ -338,9 +338,9 @@ static void calc_tetra_order_parm(const char *fnNDX, const char *fnTPS,
     for (i = 0; (i < nslice); i++)
     {
         fprintf(fpsg, "%10g  %10g\n", (i+0.5)*box[slice_dim][slice_dim]/nslice,
-                sg_slice_tot[i]/nframes);
+                sg_slice_tot[i]/static_cast<real>(nframes));
         fprintf(fpsk, "%10g  %10g\n", (i+0.5)*box[slice_dim][slice_dim]/nslice,
-                sk_slice_tot[i]/nframes);
+                sk_slice_tot[i]/static_cast<real>(nframes));
     }
     xvgrclose(fpsg);
     xvgrclose(fpsk);
@@ -397,8 +397,8 @@ static void calc_order(const char *fn, const int *index, int *a, rvec **order,
         nr_tails,                                /* nr tails, to check if index file is correct    */
         size = 0,                                /* nr. of atoms in group. same as nr_tails        */
         i, j, m, k, teller = 0,
-        slice,                                   /* current slice number                           */
-        nr_frames = 0;
+        slice;                                   /* current slice number                           */
+    real         nr_frames = 0;
     int         *slCount;                        /* nr. of atoms in one slice                      */
     real         sdbangle               = 0;     /* sum of these angles                            */
     gmx_bool     use_unitvector         = FALSE; /* use a specified unit vector instead of axis to specify unit normal*/
@@ -473,7 +473,7 @@ static void calc_order(const char *fn, const int *index, int *a, rvec **order,
 
     if (bSliced)
     {
-        *slWidth = box[axis][axis]/nslices;
+        *slWidth = box[axis][axis]/static_cast<real>(nslices);
         fprintf(stderr, "Box divided in %d slices. Initial width of slice: %f\n",
                 nslices, *slWidth);
     }
@@ -494,7 +494,7 @@ static void calc_order(const char *fn, const int *index, int *a, rvec **order,
     {
         if (bSliced)
         {
-            *slWidth = box[axis][axis]/nslices;
+            *slWidth = box[axis][axis]/static_cast<real>(nslices);
         }
         teller++;
 
@@ -639,10 +639,10 @@ static void calc_order(const char *fn, const int *index, int *a, rvec **order,
                     z1    = x1[a[index[i-1]+j]][axis];
                     z2    = x1[a[index[i+1]+j]][axis];
                     z_ave = 0.5 * (z1 + z2);
-                    slice = static_cast<int>((nslices*z_ave)/box[axis][axis]);
+                    slice = static_cast<int>((static_cast<real>(nslices)*z_ave)/box[axis][axis]);
                     while (slice < 0)
                     {
-                        slice += nslices;
+                        slice += static_cast<real>(nslices);
                     }
                     slice =  slice % nslices;
 
@@ -685,7 +685,7 @@ static void calc_order(const char *fn, const int *index, int *a, rvec **order,
 
             for (m = 0; m < DIM; m++)
             {
-                (*order)[i][m] += (frameorder[m]/size);
+                (*order)[i][m] += (frameorder[m]/static_cast<real>(size));
             }
 
             if (!permolecule)
@@ -694,7 +694,7 @@ static void calc_order(const char *fn, const int *index, int *a, rvec **order,
                 {
                     if (slCount[k]) /* if no elements, nothing has to be added */
                     {
-                        (*slOrder)[k][i] += slFrameorder[k]/slCount[k];
+                        (*slOrder)[k][i] += slFrameorder[k]/static_cast<real>(slCount[k]);
                         slFrameorder[k]   = 0; slCount[k] = 0;
                     }
                 }
@@ -734,7 +734,7 @@ static void calc_order(const char *fn, const int *index, int *a, rvec **order,
     if (bUnsat)
     {
         fprintf(stderr, "Average angle between double bond and normal: %f\n",
-                180*sdbangle/(nr_frames * size*M_PI));
+                180*sdbangle/(nr_frames * static_cast<real>(size)*M_PI));
     }
 
     sfree(x0); /* free memory used by coordinate arrays */
@@ -811,7 +811,7 @@ static void order_plot(rvec order[], real *slOrder[], const char *afile, const c
             {
                 S += slOrder[slice][atom];
             }
-            fprintf(slOrd, "%12g     %12g\n", slice*slWidth, S/atom);
+            fprintf(slOrd, "%12g     %12g\n", static_cast<real>(slice)*slWidth, S/static_cast<real>(atom));
         }
 
     }
index 4c39aa2e41d05036344d19aca395480d4b00ba4a..fef1987053cd503f2f0bdbe99a9c987696d5a271 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015,2016,2017,2018,2019, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -167,7 +167,7 @@ static void calc_potential(const char *fn, int **index, int gnx[],
     /*********** Start processing trajectory ***********/
     do
     {
-        *slWidth = box[axis][axis]/(*nslices);
+        *slWidth = box[axis][axis]/static_cast<real>((*nslices));
         teller++;
         gmx_rmpbc(gpbc, natoms, box, x0);
 
@@ -268,7 +268,7 @@ static void calc_potential(const char *fn, int **index, int gnx[],
             {
                 /* get charge per volume */
                 (*slCharge)[n][i] = (*slCharge)[n][i] * (*nslices) /
-                    (nr_frames * box[axis][axis] * box[ax1][ax1] * box[ax2][ax2]);
+                    (static_cast<real>(nr_frames) * box[axis][axis] * box[ax1][ax1] * box[ax2][ax2]);
             }
         }
         /* Now we have charge densities */
index 1e29cc0fd48b41aa2a621627609fce3ce8a671b2..ed445c3aaf77266e00a175930cd864a1241dfef7 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015,2016,2017,2018,2019, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -82,7 +82,7 @@ static void norm_princ(const t_atoms *atoms, int isize, int *index, int natoms,
         {
             vec[m] += gmx::square(x[index[i]][m]);
         }
-        vec[m] = std::sqrt(vec[m] / isize);
+        vec[m] = std::sqrt(vec[m] / static_cast<real>(isize));
         /* calculate scaling constants */
         vec[m] = 1.0 / (std::sqrt(3.0) * vec[m]);
     }
@@ -950,7 +950,7 @@ int gmx_rms(int argc, char *argv[])
         }
         if (bFile2)
         {
-            rmsd_avg /= tel_mat*tel_mat2;
+            rmsd_avg /= static_cast<real>(tel_mat)*static_cast<real>(tel_mat2);
         }
         else
         {
@@ -1037,7 +1037,7 @@ int gmx_rms(int argc, char *argv[])
                             {
                                 mx = gmx::roundToInt(std::log(static_cast<real>(mx))*delta_scalex);
                             }
-                            my             = gmx::roundToInt(rmsd_mat[i][j]*delta_scaley*del_lev);
+                            my             = gmx::roundToInt(rmsd_mat[i][j]*delta_scaley*static_cast<real>(del_lev));
                             delta_tot[mx] += 1.0;
                             if ((rmsd_mat[i][j] >= 0) && (rmsd_mat[i][j] <= delta_maxy))
                             {
@@ -1071,7 +1071,7 @@ int gmx_rms(int argc, char *argv[])
                 }
                 for (i = 0; i < del_lev+1; i++)
                 {
-                    del_yaxis[i] = delta_maxy*i/del_lev;
+                    del_yaxis[i] = delta_maxy*static_cast<real>(i)/static_cast<real>(del_lev);
                 }
                 sprintf(buf, "%s %s vs. delta t", gn_rms[0], whatname[ewhat]);
                 fp = gmx_ffopen("delta.xpm", "w");
@@ -1209,7 +1209,7 @@ int gmx_rms(int argc, char *argv[])
         fp = xvgropen(opt2fn("-a", NFILE, fnm), buf, "Residue", buf2, oenv);
         for (j = 0; (j < nrms); j++)
         {
-            fprintf(fp, "%10d  %10g\n", j, rlstot/teller);
+            fprintf(fp, "%10d  %10g\n", j, rlstot/static_cast<real>(teller));
         }
         xvgrclose(fp);
     }
@@ -1219,7 +1219,7 @@ int gmx_rms(int argc, char *argv[])
         fp = xvgropen("aver.xvg", gn_rms[0], "Residue", whatxvglabel[ewhat], oenv);
         for (j = 0; (j < irms[0]); j++)
         {
-            fprintf(fp, "%10d  %10g\n", j, rlsnorm[j]/teller);
+            fprintf(fp, "%10d  %10g\n", j, rlsnorm[j]/static_cast<real>(teller));
         }
         xvgrclose(fp);
     }
index 0e47df8cc6befd27418fe21e2d05af2ec133e780..e001103edcf6c493e39f0c990a4cfb425316e100 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015,2016,2017,2018,2019, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -126,8 +126,8 @@ static void calc_nmr(int nind, int nframes, real **dtot1_3, real **dtot1_6,
     {
         for (j = i+1; (j < nind); j++)
         {
-            temp1_3 = gmx::invcbrt(dtot1_3[i][j]/nframes);
-            temp1_6 = gmx::invsixthroot(dtot1_6[i][j]/nframes);
+            temp1_3 = gmx::invcbrt(dtot1_3[i][j]/static_cast<real>(nframes));
+            temp1_6 = gmx::invsixthroot(dtot1_6[i][j]/static_cast<real>(nframes));
             if (temp1_3 > *max1_3)
             {
                 *max1_3 = temp1_3;
@@ -488,8 +488,8 @@ static void calc_noe(int isize, const int *noe_index,
     {
         for (j = i+1; j < gnr; j++)
         {
-            noe[i][j].r_3 = gmx::invcbrt(noe[i][j].i_3/noe[i][j].nr);
-            noe[i][j].r_6 = gmx::invsixthroot(noe[i][j].i_6/noe[i][j].nr);
+            noe[i][j].r_3 = gmx::invcbrt(noe[i][j].i_3/static_cast<real>(noe[i][j].nr));
+            noe[i][j].r_6 = gmx::invsixthroot(noe[i][j].i_6/static_cast<real>(noe[i][j].nr));
             noe[j][i]     = noe[i][j];
         }
     }
@@ -588,8 +588,8 @@ static void calc_rms(int nind, int nframes,
     {
         for (j = i+1; (j < nind); j++)
         {
-            mean  = dtot[i][j]/nframes;
-            mean2 = dtot2[i][j]/nframes;
+            mean  = dtot[i][j]/static_cast<real>(nframes);
+            mean2 = dtot2[i][j]/static_cast<real>(nframes);
             rms   = std::sqrt(std::max(0.0_real, mean2-mean*mean));
             rmsc  = rms/mean;
             if (mean > *meanmax)
index be825a4103cf526ac76a83b58705db42f3278852..809f6c051c67bf261af50dce9389bf3500b28090 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015,2016,2017,2018,2019, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -222,7 +222,7 @@ int gmx_rotacf(int argc, char *argv[])
     }
     else
     {
-        dt = (t1 - t0)/(teller-1);
+        dt = (t1 - t0)/(static_cast<real>(teller-1));
 
         mode = eacVector;
 
index 53e57368ef4116ee5d8104de43b6317c8f32a0e4..e72a5f53a08ede107ec7eb50b5c453903fa5a749 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015,2016,2017,2018,2019, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -459,7 +459,7 @@ int gmx_vanhove(int argc, char *argv[])
             fprintf(fp, "%g", i*rbin);
             for (fbin = 0; fbin < nr; fbin++)
             {
-                fprintf(fp, " %g", static_cast<real>(pr[fbin][i])/(rcount[fbin]*isize*rbin*(i == 0 ? 0.5 : 1.0)));
+                fprintf(fp, " %g", static_cast<real>(pr[fbin][i]/(rcount[fbin]*isize*rbin*(i == 0 ? 0.5 : 1.0))));
             }
             fprintf(fp, "\n");
         }
index 76e4c0f843bbb4a30c144b7a28fd719538439402..7255916acb83999a3b1fe3fc0bec5e2954b4a1e0 100644 (file)
@@ -393,8 +393,8 @@ static int nitrogen_is_planar(gmx::ArrayRef<const VirtualSiteConfiguration> vsit
     return res;
 }
 
-static const std::string get_dummymass_name(gmx::ArrayRef<const VirtualSiteConfiguration> vsiteconflist,
-                                            const std::string &atom, const std::string &nextheavy)
+static std::string get_dummymass_name(gmx::ArrayRef<const VirtualSiteConfiguration> vsiteconflist,
+                                      const std::string &atom, const std::string &nextheavy)
 {
     /* Return the dummy mass name if found, or NULL if not set in ddb database */
     const auto found = std::find_if(vsiteconflist.begin(), vsiteconflist.end(),
index 0b30620662926759f9a515686abdbc6fb0556c8f..4165fb295f81d36ebb73ba0afad630b484f36740 100644 (file)
@@ -1982,7 +1982,7 @@ int gmx_grompp(int argc, char *argv[])
 
     /* If we are doing QM/MM, check that we got the atom numbers */
     have_atomnumber = TRUE;
-    for (int i = 0; i < gmx::ssize(atypes); i++)
+    for (gmx::index i = 0; i < gmx::ssize(atypes); i++)
     {
         have_atomnumber = have_atomnumber && (atypes.atomNumberFromAtomType(i) >= 0);
     }
index db8a24d4c086de892e1e719694ae10704ccc90c2..3c040aab0c617d349437db8ff80daf416bf4d0a2 100644 (file)
@@ -262,10 +262,10 @@ static void read_rtprename(const char *fname, FILE *fp,
     }
 }
 
-static const std::string search_resrename(gmx::ArrayRef<const RtpRename> rr,
-                                          const char *name,
-                                          bool bStart, bool bEnd,
-                                          bool bCompareFFRTPname)
+static std::string search_resrename(gmx::ArrayRef<const RtpRename> rr,
+                                    const char *name,
+                                    bool bStart, bool bEnd,
+                                    bool bCompareFFRTPname)
 {
     auto found = std::find_if(rr.begin(), rr.end(), [&name, &bCompareFFRTPname](const auto &rename)
                               { return ((!bCompareFFRTPname && (name == rename.gmx)) ||
index 88a5b4473a7b354e7d7f5dd504cb44c4a11119ae..e34c7b49903a9f0184f5394aef2ea62f28c83b68 100644 (file)
@@ -2694,11 +2694,11 @@ static void calc_nrdf(const gmx_mtop_t *mtop, t_inputrec *ir, char **gnames)
     snew(na_vcm, groups.groups[SimulationAtomGroupType::MassCenterVelocityRemoval].size()+1);
     snew(nrdf_vcm_sub, groups.groups[SimulationAtomGroupType::MassCenterVelocityRemoval].size()+1);
 
-    for (int i = 0; i < gmx::ssize(groups.groups[SimulationAtomGroupType::TemperatureCoupling]); i++)
+    for (gmx::index i = 0; i < gmx::ssize(groups.groups[SimulationAtomGroupType::TemperatureCoupling]); i++)
     {
         nrdf_tc[i] = 0;
     }
-    for (int i = 0; i < gmx::ssize(groups.groups[SimulationAtomGroupType::MassCenterVelocityRemoval])+1; i++)
+    for (gmx::index i = 0; i < gmx::ssize(groups.groups[SimulationAtomGroupType::MassCenterVelocityRemoval])+1; i++)
     {
         nrdf_vcm[i]     = 0;
         clear_ivec(dof_vcm[i]);
@@ -2857,7 +2857,7 @@ static void calc_nrdf(const gmx_mtop_t *mtop, t_inputrec *ir, char **gnames)
          * the number of degrees of freedom in each vcm group when COM
          * translation is removed and 6 when rotation is removed as well.
          */
-        for (int j = 0; j < gmx::ssize(groups.groups[SimulationAtomGroupType::MassCenterVelocityRemoval])+1; j++)
+        for (gmx::index j = 0; j < gmx::ssize(groups.groups[SimulationAtomGroupType::MassCenterVelocityRemoval])+1; j++)
         {
             switch (ir->comm_mode)
             {
@@ -2880,10 +2880,10 @@ static void calc_nrdf(const gmx_mtop_t *mtop, t_inputrec *ir, char **gnames)
             }
         }
 
-        for (int i = 0; i < gmx::ssize(groups.groups[SimulationAtomGroupType::TemperatureCoupling]); i++)
+        for (gmx::index i = 0; i < gmx::ssize(groups.groups[SimulationAtomGroupType::TemperatureCoupling]); i++)
         {
             /* Count the number of atoms of TC group i for every VCM group */
-            for (int j = 0; j < gmx::ssize(groups.groups[SimulationAtomGroupType::MassCenterVelocityRemoval])+1; j++)
+            for (gmx::index j = 0; j < gmx::ssize(groups.groups[SimulationAtomGroupType::MassCenterVelocityRemoval])+1; j++)
             {
                 na_vcm[j] = 0;
             }
@@ -2901,7 +2901,7 @@ static void calc_nrdf(const gmx_mtop_t *mtop, t_inputrec *ir, char **gnames)
              */
             nrdf_uc    = nrdf_tc[i];
             nrdf_tc[i] = 0;
-            for (int j = 0; j < gmx::ssize(groups.groups[SimulationAtomGroupType::MassCenterVelocityRemoval])+1; j++)
+            for (gmx::index j = 0; j < gmx::ssize(groups.groups[SimulationAtomGroupType::MassCenterVelocityRemoval])+1; j++)
             {
                 if (nrdf_vcm[j] > nrdf_vcm_sub[j])
                 {
index bd598b7b46d0d42c1bb4565c2a384df6adfffa59..ff06eb8428b45cd14bc446d3020ea6c7d3bbea64 100644 (file)
@@ -1520,7 +1520,7 @@ static bool findIfAllNBAtomsMatch(gmx::ArrayRef<const int>      atomsFromParamet
     }
     else if (bB)
     {
-        for (int i = 0; i < atomsFromCurrentParameter.ssize(); i++)
+        for (gmx::index i = 0; i < atomsFromCurrentParameter.ssize(); i++)
         {
             if (at->atom[atomsFromCurrentParameter[i]].typeB != atomsFromParameterArray[i])
             {
@@ -1531,7 +1531,7 @@ static bool findIfAllNBAtomsMatch(gmx::ArrayRef<const int>      atomsFromParamet
     }
     else
     {
-        for (int i = 0; i < atomsFromCurrentParameter.ssize(); i++)
+        for (gmx::index i = 0; i < atomsFromCurrentParameter.ssize(); i++)
         {
             if (at->atom[atomsFromCurrentParameter[i]].type != atomsFromParameterArray[i])
             {
@@ -1746,7 +1746,7 @@ static bool findIfAllParameterAtomsMatch(gmx::ArrayRef<const int>      atomsFrom
     }
     else if (bB)
     {
-        for (int i = 0; i < atomsFromCurrentParameter.ssize(); i++)
+        for (gmx::index i = 0; i < atomsFromCurrentParameter.ssize(); i++)
         {
             if (atypes->bondAtomTypeFromAtomType(
                         at->atom[atomsFromCurrentParameter[i]].typeB) != atomsFromParameterArray[i])
@@ -1758,7 +1758,7 @@ static bool findIfAllParameterAtomsMatch(gmx::ArrayRef<const int>      atomsFrom
     }
     else
     {
-        for (int i = 0; i < atomsFromCurrentParameter.ssize(); i++)
+        for (gmx::index i = 0; i < atomsFromCurrentParameter.ssize(); i++)
         {
             if (atypes->bondAtomTypeFromAtomType(
                         at->atom[atomsFromCurrentParameter[i]].type) != atomsFromParameterArray[i])
index b33fcf8f85b0005281411a6d215dbcc3e53e80b4..a54f64b0fff1e9c3c8698056838c3233f4769a32 100644 (file)
@@ -1521,7 +1521,7 @@ void clean_vsite_bondeds(gmx::ArrayRef<InteractionsOfType> plist, int natoms, bo
             if ((interaction_function[ftype].flags & IF_VSITE) &&
                 ftype != F_VSITEN)
             {
-                for (int interactionIndex = 0;
+                for (gmx::index interactionIndex = 0;
                      interactionIndex < gmx::ssize(plist[ftype]);
                      interactionIndex++)
                 {
index b5425e4b4d51c41d17f2db929a3b69a8b1ba7d68..037204b15e5afde7cc2c8f82f854d4c704e30396 100644 (file)
@@ -413,7 +413,7 @@ detectX86Features(std::string *                  brand,
  *  \returns A new std::vector of unsigned integer APIC IDs, one for each
  *           logical processor in the system.
  */
-const std::vector<unsigned int>
+std::vector<unsigned int>
 detectX86ApicIDs(bool gmx_unused haveX2Apic)
 {
     std::vector<unsigned int>  apicID;
@@ -704,7 +704,7 @@ detectX86LogicalProcessors()
  * \return New map with the contents. If the file is not available, the returned
  *         map will be empty.
  */
-const std::map<std::string, std::string>
+std::map<std::string, std::string>
 parseProcCpuInfo()
 {
     std::ifstream                       procCpuInfo("/proc/cpuinfo");
index c8a15545c8c1753901604947cde2ae397ecc4f6c..0d800311abb4433276cdd6b48a13fc8bc99349d9 100644 (file)
@@ -195,7 +195,7 @@ getHwLocObjectMemory(const hwloc_obj* obj)
  *          descendants of the provided object. If no objects of this type
  *          were found, the vector will be empty.
  */
-const std::vector<const hwloc_obj*>
+std::vector<const hwloc_obj*>
 getHwLocDescendantsByType(const hwloc_topology* topo, const hwloc_obj* obj, const hwloc_obj_type_t type)
 {
     GMX_RELEASE_ASSERT(obj, "NULL hwloc object provided to getHwLocDescendantsByType()");
index 085dbf81ad42b1e7a0b0e80501e531508e3801d1..c3b069c13d42bcea7f9ec0915a9404fb04ee9b62 100644 (file)
@@ -247,7 +247,7 @@ mdspan<const float, dynamic_extent, dynamic_extent>
 OuterProductEvaluator::operator()(ArrayRef<const float> x, ArrayRef<const float> y)
 {
     data_.resize(ssize(x), ssize(y));
-    for (int xIndex = 0; xIndex < ssize(x); ++xIndex)
+    for (gmx::index xIndex = 0; xIndex < ssize(x); ++xIndex)
     {
         const auto xValue = x[xIndex];
         std::transform(std::begin(y), std::end(y), begin(data_.asView()[xIndex]),
@@ -274,7 +274,9 @@ IntegerBox spreadRangeWithinLattice(const IVec &center, dynamicExtents3D extent,
 {
     const IVec begin = rangeBeginWithinLattice(center, range);
     const IVec end   = rangeEndWithinLattice(center, extent, range);
-    return {begin, end};
+    return {
+               begin, end
+    };
 }
 /********************************************************************
  * GaussianSpreadKernel
@@ -394,7 +396,7 @@ void GaussTransform3D::setZero()
     std::fill(begin(impl_->data_), end(impl_->data_), 0.);
 }
 
-const basic_mdspan<const float, dynamicExtents3D> GaussTransform3D::view()
+basic_mdspan<const float, dynamicExtents3D> GaussTransform3D::view()
 {
     return impl_->data_.asConstView();
 }
index ef8546fde222c9c1d4c847b34f6f9164f4f05717..fd90c2a371f2945c8711b2ebafbd89d1ac4b42a7 100644 (file)
@@ -189,7 +189,7 @@ class GaussTransform3D
         //! \brief Set all values on the lattice to zero.
         void setZero();
         //! Return a view on the spread lattice.
-        const basic_mdspan<const float, dynamicExtents3D> view();
+        basic_mdspan<const float, dynamicExtents3D> view();
 
     private:
         class Impl;
index abe2d076b3ca65e35715c10d6efc609ec836a207..a0dcc0190765c00bef465ff837c32d9af6b21fb3 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2015,2016,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2015,2016,2017,2018,2019, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -170,7 +170,7 @@ TEST(FunctionTest, InvcbrtFloat)
     gmx::test::TestReferenceChecker  checker(data.rootChecker());
     std::vector<float>               result;
 
-    for (float f : {-5, -4, -3, -2, -1, 1, 2, 3, 4})
+    for (int f : {-5, -4, -3, -2, -1, 1, 2, 3, 4})
     {
         result.push_back(gmx::invcbrt(f));
     }
@@ -311,7 +311,7 @@ TEST(FunctionTest, ErfInvFloat)
 
     for (int i = 0; i < npoints; i++)
     {
-        float r = float(2*i - npoints + 1) / npoints;
+        float r = float(2*i - npoints + 1) / float(npoints);
 
         result.push_back(gmx::erfinv(r));
     }
@@ -340,7 +340,7 @@ TEST(FunctionTest, ErfAndErfInvAreInversesFloat)
 
     for (int i = 0; i < npoints; i++)
     {
-        float r = float(2*i - npoints + 1) / npoints;
+        float r = float(2*i - npoints + 1) / float(npoints);
         EXPECT_FLOAT_EQ_TOL(r, std::erf(gmx::erfinv(r)), gmx::test::ulpTolerance(10));
     }
 }
index b5f4a959fe78c1f7f29b6652dad4bb31daddd2b1..0a522b47be4012f369bf511274ca162c3d362227 100644 (file)
 
 #include <cmath>
 
+#include <type_traits>
+
 #include "gromacs/math/functions.h"
 #include "gromacs/math/vectypes.h"
 #include "gromacs/utility/real.h"
@@ -624,9 +626,19 @@ namespace gmx
  * \return magnitude or squared magnitude of vector
  * \{
  */
-template<typename T> T norm(T* v) {return ::norm(v); }
-template <typename T> T norm2(T* v) { return ::norm2(v); }
+template<typename T> std::remove_const_t<T>
+norm(T* v)
+{
+    return ::norm(v);
+}
+template <typename T> std::remove_const_t<T>
+norm2(T* v)
+{
+    return ::norm2(v);
+}
+
 }      // namespace gmx
+
 /*! \} */
 
 #endif
index 9183b9c0953d5dc65f527561ada8a323c08299a2..fc033fee5daf107d8c1b05e2ed82ca866d80e4ca 100644 (file)
@@ -645,14 +645,14 @@ static real energyDrift(gmx::ArrayRef<const VerletbufAtomtype> att,
 
     // Here add up the contribution of all atom pairs in the system to
     // (estimated) energy drift by looping over all atom type pairs.
-    for (int i = 0; i < att.ssize(); i++)
+    for (gmx::index i = 0; i < att.ssize(); i++)
     {
         // Get the thermal displacement variance for the i-atom type
         const atom_nonbonded_kinetic_prop_t *prop_i = &att[i].prop;
         real                                 s2i_2d, s2i_3d;
         get_atom_sigma2(kT_fac, prop_i, &s2i_2d, &s2i_3d);
 
-        for (int j = i; j < att.ssize(); j++)
+        for (gmx::index j = i; j < att.ssize(); j++)
         {
             // Get the thermal displacement variance for the j-atom type
             const atom_nonbonded_kinetic_prop_t *prop_j = &att[j].prop;
@@ -837,10 +837,11 @@ static real maxSigma(real                                   kT_fac,
 {
     GMX_ASSERT(!att.empty(), "We should have at least one type");
     real smallestMass = att[0].prop.mass;
-    for (int i = 1; i < att.ssize(); i++)
+    for (const auto &atomType : att)
     {
-        smallestMass = std::min(smallestMass, att[i].prop.mass);
+        smallestMass = std::min(smallestMass, atomType.prop.mass);
     }
+    ;
 
     return 2*std::sqrt(kT_fac/smallestMass);
 }
index 0101aa7d859707312166772125937dbdba4fa748..11c7bb7d6d477aa0f53a5bd8252da534aae72199 100644 (file)
@@ -1170,7 +1170,7 @@ void Constraints::saveEdsamPointer(gmx_edsam * ed)
     impl_->ed = ed;
 }
 
-const ArrayRef<const t_blocka>
+ArrayRef<const t_blocka>
 Constraints::atom2constraints_moltype() const
 {
     return impl_->at2con_mt;
index dac41fe3a564d8f0520c692375f41b17ddb69089..452d2ac36d4d6d9d01259731a99d02c2f8ee1768 100644 (file)
@@ -181,7 +181,7 @@ class Constraints
         //! Links the essentialdynamics and constraint code.
         void saveEdsamPointer(gmx_edsam *ed);
         //! Getter for use by domain decomposition.
-        const ArrayRef<const t_blocka> atom2constraints_moltype() const;
+        ArrayRef<const t_blocka> atom2constraints_moltype() const;
         //! Getter for use by domain decomposition.
         ArrayRef < const std::vector < int>> atom2settle_moltype() const;
 
index f733ae2ab059bd56b3d88bfd8f18b4efa1d7631b..f0d1651aa7ad7b068647217971144705dbdb386e 100644 (file)
@@ -746,7 +746,7 @@ void mde_delta_h_coll_restore_energyhistory(t_mde_delta_h_coll      *dhc,
     GMX_RELEASE_ASSERT(deltaH, "Should have delta_h histograms in energy history");
     GMX_RELEASE_ASSERT(deltaH->dh.size() == static_cast<size_t>(dhc->ndh), "energy history number of delta_h histograms should match inputrec's number");
 
-    for (unsigned int i = 0; i < deltaH->dh.size(); i++)
+    for (gmx::index i = 0; i < gmx::ssize(deltaH->dh); i++)
     {
         dhc->dh[i].ndh = deltaH->dh[i].size();
         for (unsigned int j = 0; j < dhc->dh[i].ndh; j++)
index f2552fc67108523bc15e5f003c77a27fcc552ab7..146ab1ff354aadc9326a1e647758265fcf50ea27 100644 (file)
@@ -404,7 +404,7 @@ std::vector<int> qmmmAtomIndices(const t_inputrec &ir, const gmx_mtop_t &mtop)
 void removeQmmmAtomCharges(gmx_mtop_t *mtop, gmx::ArrayRef<const int> qmmmAtoms)
 {
     int molb = 0;
-    for (int i = 0; i < qmmmAtoms.ssize(); i++)
+    for (gmx::index i = 0; i < qmmmAtoms.ssize(); i++)
     {
         int     indexInMolecule;
         mtopGetMolblockIndex(mtop, qmmmAtoms[i], &molb, nullptr, &indexInMolecule);
index 5f4d39c5c69a4ac4890d913c4ed9b9f71cc5e3a4..6a0885f9a25784b40dcfb60c4da970582c522d88 100644 (file)
@@ -865,9 +865,9 @@ void do_force(FILE                                     *fplog,
               gmx_wallcycle_t                           wcycle,
               const gmx_localtop_t                     *top,
               const matrix                              box,
-              gmx::ArrayRefWithPadding<gmx::RVec>       x,     //NOLINT(performance-unnecessary-value-param)
+              gmx::ArrayRefWithPadding<gmx::RVec>       x,
               history_t                                *hist,
-              gmx::ArrayRefWithPadding<gmx::RVec>       force, //NOLINT(performance-unnecessary-value-param)
+              gmx::ArrayRefWithPadding<gmx::RVec>       force,
               tensor                                    vir_force,
               const t_mdatoms                          *mdatoms,
               gmx_enerdata_t                           *enerd,
index 1d6c85affd032774325ddee296f419fdc6adfc2b..5c79f2e23fb7cf96b579171893434d85abf4132d 100644 (file)
@@ -171,7 +171,7 @@ class ConstraintsTest : public ::testing::TestWithParam<ConstraintsTestParameter
         {
 
             // Test if all the constraints are satisfied
-            for (unsigned c = 0; c < testData.constraints_.size()/3; c++)
+            for (index c = 0; c < ssize(testData.constraints_)/3; c++)
             {
                 real r0 = testData.constraintsR0_.at(testData.constraints_.at(3*c));
                 int  i  = testData.constraints_.at(3*c + 1);
@@ -191,7 +191,7 @@ class ConstraintsTest : public ::testing::TestWithParam<ConstraintsTestParameter
                 d0 = norm(xij0);
                 d1 = norm(xij1);
                 EXPECT_REAL_EQ_TOL(r0, d1, tolerance) << gmx::formatString(
-                        "rij = %f, which is not equal to r0 = %f for constraint #%u, between atoms %d and %d"
+                        "rij = %f, which is not equal to r0 = %f for constraint #%zd, between atoms %d and %d"
                         " (before constraining rij was %f).", d1, r0, c, i, j, d0);
             }
         }
@@ -209,7 +209,7 @@ class ConstraintsTest : public ::testing::TestWithParam<ConstraintsTestParameter
         void checkConstrainsDirection(const ConstraintsTestData &testData, t_pbc pbc)
         {
 
-            for (unsigned c = 0; c < testData.constraints_.size()/3; c++)
+            for (index c = 0; c < ssize(testData.constraints_)/3; c++)
             {
                 int  i  = testData.constraints_.at(3*c + 1);
                 int  j  = testData.constraints_.at(3*c + 2);
@@ -228,7 +228,7 @@ class ConstraintsTest : public ::testing::TestWithParam<ConstraintsTestParameter
                 real dot = xij0.dot(xij1);
 
                 EXPECT_GE(dot, 0.0) << gmx::formatString(
-                        "The constraint %u changed direction. Constraining algorithm might have returned the wrong root "
+                        "The constraint %zd changed direction. Constraining algorithm might have returned the wrong root "
                         "of the constraints equation.", c);
 
             }
index 46c72d26a1376b59d292b8bdd54fb080c80e85fa..0873d45c2b61425c72e9c3dd481b74f866e723aa 100644 (file)
@@ -144,7 +144,7 @@ ConstraintsTestData::ConstraintsTestData(const std::string &title,
 
     snew(idef_.il[F_CONSTR].iatoms, constraints.size());
     int maxType = 0;
-    for (unsigned i = 0; i < constraints.size(); i++)
+    for (index i = 0; i < ssize(constraints); i++)
     {
         if (i % 3 == 0)
         {
@@ -156,7 +156,7 @@ ConstraintsTestData::ConstraintsTestData(const std::string &title,
         idef_.il[F_CONSTR].iatoms[i] = constraints.at(i);
     }
     snew(idef_.iparams, maxType + 1);
-    for (unsigned i = 0; i < constraints.size()/3; i++)
+    for (index i = 0; i < ssize(constraints)/3; i++)
     {
         idef_.iparams[constraints.at(3*i)].constr.dA = constraintsR0.at(constraints.at(3*i));
         idef_.iparams[constraints.at(3*i)].constr.dB = constraintsR0.at(constraints.at(3*i));
@@ -165,10 +165,7 @@ ConstraintsTestData::ConstraintsTestData(const std::string &title,
     // Constraints and their parameters (global topology)
     InteractionList interactionList;
     interactionList.iatoms.resize(constraints.size());
-    for (unsigned i = 0; i < constraints.size(); i++)
-    {
-        interactionList.iatoms.at(i) = constraints.at(i);
-    }
+    std::copy(constraints.begin(), constraints.end(), interactionList.iatoms.begin());
     InteractionList interactionListEmpty;
     interactionListEmpty.iatoms.resize(0);
 
index dff35e7870f229b683fcf7eb86891d3182b0c95d..91aded80586b0e5dbeffc78b2c8431dfa437514c 100644 (file)
@@ -160,10 +160,10 @@ void applyLincs(ConstraintsTestData *testData, t_pbc pbc)
                                    maxwarn, &warncount_lincs);
     EXPECT_TRUE(success) << "Test failed with a false return value in LINCS.";
     EXPECT_EQ(warncount_lincs, 0) << "There were warnings in LINCS.";
-    for (unsigned int i = 0; i < testData->mtop_.moltype.size(); i++)
+    for (auto &moltype : at2con_mt)
     {
-        sfree(at2con_mt.at(i).index);
-        sfree(at2con_mt.at(i).a);
+        sfree(moltype.index);
+        sfree(moltype.a);
     }
     done_lincs(lincsd);
 }
index d1fe791568c672dc54c50d661e7d5ac3bdda036c..a2f05a886af48a8661333a7499b04c914587f914 100644 (file)
@@ -95,18 +95,18 @@ void fcloseWrapper(FILE *fp)
  */
 struct EnergyOutputTestParameters
 {
-    //! If output should be initialized as a rerun.
-    bool isRerun;
     //! Thermostat (enum)
     int  temperatureCouplingScheme;
     //! Barostat (enum)
     int  pressureCouplingScheme;
     //! Integrator
     int  integrator;
-    //! Is box triclinic (off-diagonal elements will be printed).
-    bool isBoxTriclinic;
     //! Number of saved energy frames (to test averages output).
     int  numFrames;
+    //! If output should be initialized as a rerun.
+    bool isRerun;
+    //! Is box triclinic (off-diagonal elements will be printed).
+    bool isBoxTriclinic;
 };
 
 /*! \brief Sets of parameters on which to run the tests.
@@ -114,17 +114,17 @@ struct EnergyOutputTestParameters
  * Only several combinations of the parameters are used. Using all possible combinations will require ~10 MB of
  * test data and ~2 sec to run the tests.
  */
-const EnergyOutputTestParameters parametersSets[] = {{false, etcNO,         epcNO,               eiMD, false, 1},
-                                                     {true,  etcNO,         epcNO,               eiMD, false, 1},
-                                                     {false, etcNO,         epcNO,               eiMD, true,  1},
-                                                     {false, etcNO,         epcNO,               eiMD, false, 0},
-                                                     {false, etcNO,         epcNO,               eiMD, false, 10},
-                                                     {false, etcVRESCALE,   epcNO,               eiMD, false, 1},
-                                                     {false, etcNOSEHOOVER, epcNO,               eiMD, false, 1},
-                                                     {false, etcNO,         epcPARRINELLORAHMAN, eiMD, false, 1},
-                                                     {false, etcNO,         epcMTTK,             eiMD, false, 1},
-                                                     {false, etcNO,         epcNO,               eiVV, false, 1},
-                                                     {false, etcNO,         epcMTTK,             eiVV, false, 1}};
+const EnergyOutputTestParameters parametersSets[] = {{etcNO,         epcNO,               eiMD, 1,  false, false},
+                                                     {etcNO,         epcNO,               eiMD, 1,  true,  false},
+                                                     {etcNO,         epcNO,               eiMD, 1,  false, true},
+                                                     {etcNO,         epcNO,               eiMD, 0,  false, false},
+                                                     {etcNO,         epcNO,               eiMD, 10, false, false},
+                                                     {etcVRESCALE,   epcNO,               eiMD, 1,  false, false},
+                                                     {etcNOSEHOOVER, epcNO,               eiMD, 1,  false, false},
+                                                     {etcNO,         epcPARRINELLORAHMAN, eiMD, 1,  false, false},
+                                                     {etcNO,         epcMTTK,             eiMD, 1,  false, false},
+                                                     {etcNO,         epcNO,               eiVV, 1,  false, false},
+                                                     {etcNO,         epcMTTK,             eiVV, 1,  false, false}};
 
 /*! \brief Test fixture to test energy output.
  *
@@ -432,16 +432,16 @@ class EnergyOutputTest : public ::testing::TestWithParam<EnergyOutputTestParamet
             }
 
             // Kinetic energy and related data
-            for (int i = 0; i < gmx::ssize(mtop_.groups.groups[SimulationAtomGroupType::TemperatureCoupling]); i++)
+            for (auto &tcstat : ekindata_.tcstat)
             {
-                ekindata_.tcstat[i].T      = (*testValue += 0.1);
-                ekindata_.tcstat[i].lambda = (*testValue += 0.1);
+                tcstat.T      = (*testValue += 0.1);
+                tcstat.lambda = (*testValue += 0.1);
             }
-            for (int i = 0; i < gmx::ssize(mtop_.groups.groups[SimulationAtomGroupType::Acceleration]); i++)
+            for (auto &grpstat : ekindata_.grpstat)
             {
-                ekindata_.grpstat[i].u[XX] = (*testValue += 0.1);
-                ekindata_.grpstat[i].u[YY] = (*testValue += 0.1);
-                ekindata_.grpstat[i].u[ZZ] = (*testValue += 0.1);
+                grpstat.u[XX] = (*testValue += 0.1);
+                grpstat.u[YY] = (*testValue += 0.1);
+                grpstat.u[ZZ] = (*testValue += 0.1);
             }
 
             // This conditional is to check whether the ebin was allocated.
@@ -531,7 +531,7 @@ class EnergyOutputTest : public ::testing::TestWithParam<EnergyOutputTestParamet
                 inputrec_.opts.ref_t[i] = (*testValue += 0.1);
             }
 
-            for (int k = 0; k < gmx::ssize(mtop_.groups.groups[SimulationAtomGroupType::TemperatureCoupling])*inputrec_.opts.nhchainlength; k++)
+            for (index k = 0; k < ssize(mtop_.groups.groups[SimulationAtomGroupType::TemperatureCoupling])*inputrec_.opts.nhchainlength; k++)
             {
                 state_.nosehoover_xi[k]  = (*testValue += 0.1);
                 state_.nosehoover_vxi[k] = (*testValue += 0.1);
index 38c83ffa2a4766126dee574bcf2b49a8ce03b72f..7b895ebfcc57507d43dc5ec999ce6f67a309b5fc 100644 (file)
@@ -84,26 +84,18 @@ SettleTestData::SettleTestData(int numSettles) :
     // Perturb the atom positions, to appear like an
     // "update," and where there is definitely constraining
     // work to do.
-    for (int i = 0; i < xPrime_.size()*DIM; ++i)
+    const real deltas[] = { 0.01, -0.01, +0.02, -0.02 };
+    int        i        = 0;
+    for (auto &xPrime : xPrime_)
     {
-        if (i % 4 == 0)
-        {
-            xPrime_[i / DIM][i % DIM] += 0.01;
-        }
-        else if (i % 4 == 1)
-        {
-            xPrime_[i / DIM][i % DIM] -= 0.01;
-        }
-        else if (i % 4 == 2)
-        {
-            xPrime_[i / DIM][i % DIM] += 0.02;
-        }
-        else if (i % 4 == 3)
-        {
-            xPrime_[i / DIM][i % DIM] -= 0.02;
-        }
-        v_[i / DIM][i % DIM] = 0.0;
+        xPrime[XX] += deltas[i % 4];
+        ++i;
+        xPrime[YY] += deltas[i % 4];
+        ++i;
+        xPrime[ZZ] += deltas[i % 4];
+        ++i;
     }
+    std::fill(v_.begin(), v_.end(), RVec {0.0, 0.0, 0.0});
 
     // Set up the topology.
     const int settleType = 0;
index f5c972a862151b6910f4661ae7e2c2b82b6f8983..f17b9a9ebd443e8511392c69eee6bd8f23092679 100644 (file)
@@ -94,7 +94,7 @@ void UpdateGroupsCog::addCogs(gmx::ArrayRef<const int>        globalAtomIndices,
     cogIndices_.reserve(globalAtomIndices.size());
 
     int moleculeBlock = 0;
-    for (int localAtom = localAtomBegin; localAtom < globalAtomIndices.ssize(); localAtom++)
+    for (gmx::index localAtom = localAtomBegin; localAtom < globalAtomIndices.ssize(); localAtom++)
     {
         const int   globalAtom = globalAtomIndices[localAtom];
         int         moleculeIndex;
index 76addf8c6552c6cdcd0d8e01b39dcb23038b1119..46afcb94efe48cce6a35f8b8dba1157d0bcb74aa 100644 (file)
@@ -662,7 +662,7 @@ static bool do_em_step(const t_commrec *cr,
 
             /* OpenMP does not supported unsigned loop variables */
 #pragma omp for schedule(static) nowait
-            for (int i = 0; i < gmx::ssize(s2->cg_gl); i++)
+            for (gmx::index i = 0; i < gmx::ssize(s2->cg_gl); i++)
             {
                 s2->cg_gl[i] = s1->cg_gl[i];
             }
@@ -2665,7 +2665,7 @@ void
 LegacySimulator::do_nm()
 {
     const char          *NM = "Normal Mode Analysis";
-    int                  nnodes, node;
+    int                  nnodes;
     gmx_localtop_t       top;
     gmx_global_stat_t    gstat;
     t_graph             *graph;
@@ -2813,7 +2813,7 @@ LegacySimulator::do_nm()
     bool bNS          = true;
     auto state_work_x = makeArrayRef(state_work.s.x);
     auto state_work_f = makeArrayRef(state_work.f);
-    for (unsigned int aid = cr->nodeid; aid < atom_index.size(); aid += nnodes)
+    for (index aid = cr->nodeid; aid < ssize(atom_index); aid += nnodes)
     {
         size_t atom = atom_index[aid];
         for (size_t d = 0; d < DIM; d++)
@@ -2912,7 +2912,7 @@ LegacySimulator::do_nm()
             }
             else
             {
-                for (node = 0; (node < nnodes && aid+node < atom_index.size()); node++)
+                for (index node = 0; (node < nnodes && aid+node < ssize(atom_index)); node++)
                 {
                     if (node > 0)
                     {
index bc1a4bbc6ee418f80ba64e57faccf667526ed0f8..4a7622c19b8cb1da7e41e3e2e3a8daccd64eaddb 100644 (file)
@@ -1635,7 +1635,7 @@ Mdrunner::~Mdrunner()
 };
 
 void Mdrunner::addPotential(std::shared_ptr<gmx::IRestraintPotential> puller,
-                            std::string                               name)
+                            const std::string                        &name)
 {
     GMX_ASSERT(restraintManager_, "Mdrunner must have a restraint manager.");
     // Not sure if this should be logged through the md logger or something else,
@@ -1645,7 +1645,7 @@ void Mdrunner::addPotential(std::shared_ptr<gmx::IRestraintPotential> puller,
     // When multiple restraints are used, it may be wasteful to register them separately.
     // Maybe instead register an entire Restraint Manager as a force provider.
     restraintManager_->addToSpec(std::move(puller),
-                                 std::move(name));
+                                 name);
 }
 
 Mdrunner::Mdrunner(std::unique_ptr<MDModules> mdModules)
index 8b7d639a239a2083b9982525532a948ac14fd634..30b44147b7553b0f1fdb1780e89097a736c9860b 100644 (file)
@@ -166,7 +166,7 @@ class Mdrunner
          * rather than offering this public interface.
          */
         void addPotential(std::shared_ptr<IRestraintPotential> restraint,
-                          std::string                          name);
+                          const std::string                   &name);
 
         //! Called when thread-MPI spawns threads.
         t_commrec *spawnThreads(int numThreadsToLaunch) const;
index 41caa8d4b26a010ec75899a8bb4f22445aa420a9..e78a65945e0df3ea74579344149693a7402eed21 100644 (file)
@@ -1408,7 +1408,7 @@ static void nbnxn_atomdata_add_nbat_f_to_f_stdreduce(nbnxn_atomdata_t *nbat,
                 int i1 = (b+1)*NBNXN_BUFFERFLAG_SIZE*nbat->fstride;
 
                 nfptr = 0;
-                for (int out = 1; out < gmx::ssize(nbat->out); out++)
+                for (gmx::index out = 1; out < gmx::ssize(nbat->out); out++)
                 {
                     if (bitmask_is_set(flags->flag[b], out))
                     {
index fbc52c4bd8e41eb8b21d9b80bd4e0f057c1f027d..a3c4b9d59c26c15738b6f044d07023f2081841fb 100644 (file)
@@ -99,7 +99,7 @@ static real gridAtomDensity(int        numAtoms,
 
     rvec_sub(upperCorner, lowerCorner, size);
 
-    return numAtoms/(size[XX]*size[YY]*size[ZZ]);
+    return static_cast<real>(numAtoms)/(size[XX]*size[YY]*size[ZZ]);
 }
 
 void Grid::setDimensions(const int            ddZone,
index 436438196e9a9967b199d0a5acf71ca7d3551ad8..38d9650e4f1fc49afd4eb12de57f4f97f23a4180 100644 (file)
@@ -122,7 +122,7 @@ class GridSet
                        nbnxn_atomdata_t               *nbat);
 
         //! Returns the domain setup
-        const DomainSetup domainSetup() const
+        DomainSetup domainSetup() const
         {
             return domainSetup_;
         }
index e02b649739996000c653631efa93da61d7afeab2..c608a660c22a0eaf8f9a8b196fc7b43bcb10eea1 100644 (file)
@@ -244,7 +244,7 @@ nbnxn_kernel_cpu(const PairlistSet              &pairlistSet,
     int gmx_unused                        nthreads = gmx_omp_nthreads_get(emntNonbonded);
     wallcycle_sub_start(wcycle, ewcsNONBONDED_CLEAR);
 #pragma omp parallel for schedule(static) num_threads(nthreads)
-    for (int nb = 0; nb < pairlists.ssize(); nb++)
+    for (gmx::index nb = 0; nb < pairlists.ssize(); nb++)
     {
         // Presently, the kernels do not call C++ code that can throw,
         // so no need for a try/catch pair in this OpenMP region.
@@ -568,7 +568,7 @@ nonbonded_verlet_t::dispatchFreeEnergyKernel(Nbnxm::InteractionLocality  iLocali
 
     wallcycle_sub_start(wcycle_, ewcsNONBONDED_FEP);
 #pragma omp parallel for schedule(static) num_threads(nbl_fep.ssize())
-    for (int th = 0; th < nbl_fep.ssize(); th++)
+    for (gmx::index th = 0; th < nbl_fep.ssize(); th++)
     {
         try
         {
@@ -610,7 +610,7 @@ nonbonded_verlet_t::dispatchFreeEnergyKernel(Nbnxm::InteractionLocality  iLocali
             }
             reset_foreign_enerdata(enerd);
 #pragma omp parallel for schedule(static) num_threads(nbl_fep.ssize())
-            for (int th = 0; th < nbl_fep.ssize(); th++)
+            for (gmx::index th = 0; th < nbl_fep.ssize(); th++)
             {
                 try
                 {
index a23bcc6c145d3c527dca56a9bb2e3d7a50600ab9..91bad8a61a414ab43e233752b6bdd1acb4f67b5a 100644 (file)
@@ -93,7 +93,7 @@ nbnxn_kernel_gpu_ref(const NbnxnPairlistGpu     *nbl,
     real                ix, iy, iz, fix, fiy, fiz;
     real                jx, jy, jz;
     real                dx, dy, dz, rsq, rinv;
-    int                 int_bit;
+    real                int_bit;
     real                fexcl;
     real                c6, c12;
     const nbnxn_excl_t *excl[2];
@@ -227,8 +227,8 @@ nbnxn_kernel_gpu_ref(const NbnxnPairlistGpu     *nbl,
                                 }
 
                                 constexpr int clusterPerSplit = c_nbnxnGpuClusterSize/c_nbnxnGpuClusterpairSplit;
-                                int_bit = ((excl[jc/clusterPerSplit]->pair[(jc & (clusterPerSplit - 1))*c_clSize + ic]
-                                            >> (jm*c_numClPerSupercl + im)) & 1);
+                                int_bit = static_cast<real>((excl[jc/clusterPerSplit]->pair[(jc & (clusterPerSplit - 1))*c_clSize + ic]
+                                                             >> (jm*c_numClPerSupercl + im)) & 1);
 
                                 js               = ja*nbat->xstride;
                                 jfs              = ja*nbat->fstride;
@@ -275,7 +275,7 @@ nbnxn_kernel_gpu_ref(const NbnxnPairlistGpu     *nbl,
                                     r     = rsq*rinv;
                                     rt    = r*iconst->coulombEwaldTables->scale;
                                     n0    = static_cast<int>(rt);
-                                    eps   = rt - n0;
+                                    eps   = rt - static_cast<real>(n0);
 
                                     fexcl = (1 - eps)*Ftab[n0] + eps*Ftab[n0+1];
 
index 62e1356b3cb41d53a01fa26e2cbb8a1ea744421a..dc679f72f5da601ecee98fa60e28326bc75a8346 100644 (file)
             /* A multiply mask used to zero an interaction
              * when that interaction should be excluded
              * (e.g. because of bonding). */
-            int interact;
-
-            interact = ((l_cj[cjind].excl>>(i*UNROLLI + j)) & 1);
+            real interact = static_cast<real>((l_cj[cjind].excl>>(i*UNROLLI + j)) & 1);
 #ifndef EXCL_FORCES
             skipmask = interact;
 #else
             skipmask = (cj == ci_sh && j <= i) ? 0.0 : 1.0;
 #endif
 #else
-#define interact 1.0
-            skipmask = 1.0;
+            constexpr real interact = 1.0;
+            skipmask = interact;
 #endif
 
             VLJ = 0;
 #ifdef CALC_COUL_TAB
             rs     = rsq*rinv*tab_coul_scale;
             ri     = int(rs);
-            frac   = rs - ri;
+            frac   = rs - static_cast<real>(ri);
 #if !GMX_DOUBLE
             /* fexcl = F_i + frac * (F_(i+1)-F_i) */
             fexcl  = tab_coul_FDV0[ri*4] + frac*tab_coul_FDV0[ri*4+1];
index 38724cb2b5f7f00bcf74d7d162c308e205aceff3..d4a11e64d306b1867bcec01a4621608c593ef4d7 100644 (file)
     ajz           = ajy + STRIDE;
 
 #ifdef CHECK_EXCLS
-    gmx_load_simd_2xnn_interactions(l_cj[cjind].excl,
+    gmx_load_simd_2xnn_interactions(static_cast<int>(l_cj[cjind].excl),
                                     filter_S0, filter_S2,
                                     &interact_S0, &interact_S2);
 #endif /* CHECK_EXCLS */
index f2d777c4029a48f7fac78a093a679d585813cdf6..5fda72098b377939a0013d5964d0ad717a877ca5 100644 (file)
 
     invtsp_S  = SimdReal(ic->coulombEwaldTables->scale);
 #ifdef CALC_ENERGIES
-    mhalfsp_S = SimdReal(-0.5/ic->coulombEwaldTables->scale);
+    mhalfsp_S = SimdReal(-0.5_real/ic->coulombEwaldTables->scale);
 #endif
 
 #ifdef TAB_FDV0
index 8b842916275578bc806d82c3dc31a676b015485b..11867ab8a3975387a1566604a11fd78619f931d4 100644 (file)
     ajz           = ajy + STRIDE;
 
 #ifdef CHECK_EXCLS
-    gmx_load_simd_4xn_interactions(l_cj[cjind].excl,
+    gmx_load_simd_4xn_interactions(static_cast<int>(l_cj[cjind].excl),
                                    filter_S0, filter_S1,
                                    filter_S2, filter_S3,
                                    nbat->simdMasks.interaction_array.data(),
index 0e7f68b53dedfb1f783860504f3188931ea99087..217985d56bc0f91c762c0b32e8eb95f560c415a7 100644 (file)
 
     invtsp_S  = SimdReal(ic->coulombEwaldTables->scale);
 #ifdef CALC_ENERGIES
-    mhalfsp_S = SimdReal(-0.5/ic->coulombEwaldTables->scale);
+    mhalfsp_S = SimdReal(-0.5_real/ic->coulombEwaldTables->scale);
 #endif
 
 #ifdef TAB_FDV0
index 6059f157665f39ed60ffcf0777cb3fe3ae67596d..296db78c92d7a8ff308b4d73f0ba1309f4ed100a 100644 (file)
@@ -2693,12 +2693,10 @@ static void combine_nblists(gmx::ArrayRef<const NbnxnPairlistGpu>  nbls,
     /* Each thread should copy its own data to the combined arrays,
      * as otherwise data will go back and forth between different caches.
      */
-#if GMX_OPENMP && !(defined __clang_analyzer__)
-    int nthreads = gmx_omp_nthreads_get(emntPairsearch);
-#endif
+    int gmx_unused nthreads = gmx_omp_nthreads_get(emntPairsearch);
 
 #pragma omp parallel for num_threads(nthreads) schedule(static)
-    for (int n = 0; n < nbls.ssize(); n++)
+    for (gmx::index n = 0; n < nbls.ssize(); n++)
     {
         try
         {
@@ -2709,11 +2707,11 @@ static void combine_nblists(gmx::ArrayRef<const NbnxnPairlistGpu>  nbls,
             int cj4_offset  = ncj4;
             int excl_offset = nexcl;
 
-            for (int i = n; i < nbls.ssize(); i++)
+            for (const auto &nbl : nbls)
             {
-                sci_offset  -= nbls[i].sci.size();
-                cj4_offset  -= nbls[i].cj4.size();
-                excl_offset -= nbls[i].excl.size();
+                sci_offset  -= nbl.sci.size();
+                cj4_offset  -= nbl.cj4.size();
+                excl_offset -= nbl.excl.size();
             }
 
             const NbnxnPairlistGpu &nbli = nbls[n];
@@ -3095,7 +3093,8 @@ static int getNumSimpleJClustersInList(const gmx_unused NbnxnPairlistGpu &nbl)
 static void incrementNumSimpleJClustersInList(NbnxnPairlistCpu *nbl,
                                               int               ncj_old_j)
 {
-    nbl->ncjInUse += nbl->cj.size() - ncj_old_j;
+    nbl->ncjInUse += nbl->cj.size();
+    nbl->ncjInUse -= ncj_old_j;
 }
 
 static void incrementNumSimpleJClustersInList(NbnxnPairlistGpu gmx_unused *nbl,
@@ -3311,7 +3310,6 @@ static void nbnxn_make_pairlist_part(const Nbnxm::GridSet &gridSet,
         {
             continue;
         }
-
         ncj_old_i = getNumSimpleJClustersInList(*nbl);
 
         d2cx = 0;
@@ -3323,7 +3321,7 @@ static void nbnxn_make_pairlist_part(const Nbnxm::GridSet &gridSet,
             }
             else
             {
-                bx1 = iGridDims.lowerCorner[XX] + (ci_x+1)*iGridDims.cellSize[XX];
+                bx1 = iGridDims.lowerCorner[XX] + (real(ci_x)+1)*iGridDims.cellSize[XX];
             }
             if (bx1 < jGridDims.lowerCorner[XX])
             {
@@ -3341,7 +3339,7 @@ static void nbnxn_make_pairlist_part(const Nbnxm::GridSet &gridSet,
         /* Loop over shift vectors in three dimensions */
         for (int tz = -shp[ZZ]; tz <= shp[ZZ]; tz++)
         {
-            const real shz = tz*box[ZZ][ZZ];
+            const real shz = real(tz)*box[ZZ][ZZ];
 
             bz0 = bbcz_i[ci].lower + shz;
             bz1 = bbcz_i[ci].upper + shz;
@@ -3366,7 +3364,7 @@ static void nbnxn_make_pairlist_part(const Nbnxm::GridSet &gridSet,
                 continue;
             }
 
-            bz1_frac = bz1/iGrid.numCellsInColumn(ci_xy);
+            bz1_frac = bz1/real(iGrid.numCellsInColumn(ci_xy));
             if (bz1_frac < 0)
             {
                 bz1_frac = 0;
@@ -3375,7 +3373,7 @@ static void nbnxn_make_pairlist_part(const Nbnxm::GridSet &gridSet,
 
             for (int ty = -shp[YY]; ty <= shp[YY]; ty++)
             {
-                const real shy = ty*box[YY][YY] + tz*box[ZZ][YY];
+                const real shy = real(ty)*box[YY][YY] + real(tz)*box[ZZ][YY];
 
                 if (bSimple)
                 {
@@ -3384,8 +3382,8 @@ static void nbnxn_make_pairlist_part(const Nbnxm::GridSet &gridSet,
                 }
                 else
                 {
-                    by0 = iGridDims.lowerCorner[YY] + (ci_y    )*iGridDims.cellSize[YY] + shy;
-                    by1 = iGridDims.lowerCorner[YY] + (ci_y + 1)*iGridDims.cellSize[YY] + shy;
+                    by0 = iGridDims.lowerCorner[YY] + (real(ci_y)    )*iGridDims.cellSize[YY] + shy;
+                    by1 = iGridDims.lowerCorner[YY] + (real(ci_y) + 1)*iGridDims.cellSize[YY] + shy;
                 }
 
                 get_cell_range<YY>(by0, by1,
@@ -3419,7 +3417,7 @@ static void nbnxn_make_pairlist_part(const Nbnxm::GridSet &gridSet,
                         continue;
                     }
 
-                    const real shx = tx*box[XX][XX] + ty*box[YY][XX] + tz*box[ZZ][XX];
+                    const real shx = real(tx)*box[XX][XX] + real(ty)*box[YY][XX] + real(tz)*box[ZZ][XX];
 
                     if (bSimple)
                     {
@@ -3428,8 +3426,8 @@ static void nbnxn_make_pairlist_part(const Nbnxm::GridSet &gridSet,
                     }
                     else
                     {
-                        bx0 = iGridDims.lowerCorner[XX] + (ci_x  )*iGridDims.cellSize[XX] + shx;
-                        bx1 = iGridDims.lowerCorner[XX] + (ci_x+1)*iGridDims.cellSize[XX] + shx;
+                        bx0 = iGridDims.lowerCorner[XX] + (real(ci_x)  )*iGridDims.cellSize[XX] + shx;
+                        bx1 = iGridDims.lowerCorner[XX] + (real(ci_x)+1)*iGridDims.cellSize[XX] + shx;
                     }
 
                     get_cell_range<XX>(bx0, bx1,
@@ -3463,14 +3461,15 @@ static void nbnxn_make_pairlist_part(const Nbnxm::GridSet &gridSet,
 
                     for (int cx = cxf; cx <= cxl; cx++)
                     {
+                        const real cx_real = cx;
                         d2zx = d2z;
-                        if (jGridDims.lowerCorner[XX] + cx*jGridDims.cellSize[XX] > bx1)
+                        if (jGridDims.lowerCorner[XX] + cx_real*jGridDims.cellSize[XX] > bx1)
                         {
-                            d2zx += gmx::square(jGridDims.lowerCorner[XX] + cx*jGridDims.cellSize[XX] - bx1);
+                            d2zx += gmx::square(jGridDims.lowerCorner[XX] + cx_real*jGridDims.cellSize[XX] - bx1);
                         }
-                        else if (jGridDims.lowerCorner[XX] + (cx+1)*jGridDims.cellSize[XX] < bx0)
+                        else if (jGridDims.lowerCorner[XX] + (cx_real+1)*jGridDims.cellSize[XX] < bx0)
                         {
-                            d2zx += gmx::square(jGridDims.lowerCorner[XX] + (cx+1)*jGridDims.cellSize[XX] - bx0);
+                            d2zx += gmx::square(jGridDims.lowerCorner[XX] + (cx_real+1)*jGridDims.cellSize[XX] - bx0);
                         }
 
                         if (isIntraGridList &&
@@ -3490,17 +3489,18 @@ static void nbnxn_make_pairlist_part(const Nbnxm::GridSet &gridSet,
 
                         for (int cy = cyf_x; cy <= cyl; cy++)
                         {
-                            const int columnStart = jGrid.firstCellInColumn(cx*jGridDims.numCells[YY] + cy);
-                            const int columnEnd   = jGrid.firstCellInColumn(cx*jGridDims.numCells[YY] + cy + 1);
+                            const int  columnStart = jGrid.firstCellInColumn(cx*jGridDims.numCells[YY] + cy);
+                            const int  columnEnd   = jGrid.firstCellInColumn(cx*jGridDims.numCells[YY] + cy + 1);
 
+                            const real cy_real = cy;
                             d2zxy = d2zx;
-                            if (jGridDims.lowerCorner[YY] + cy*jGridDims.cellSize[YY] > by1)
+                            if (jGridDims.lowerCorner[YY] + cy_real*jGridDims.cellSize[YY] > by1)
                             {
-                                d2zxy += gmx::square(jGridDims.lowerCorner[YY] + cy*jGridDims.cellSize[YY] - by1);
+                                d2zxy += gmx::square(jGridDims.lowerCorner[YY] + cy_real*jGridDims.cellSize[YY] - by1);
                             }
-                            else if (jGridDims.lowerCorner[YY] + (cy + 1)*jGridDims.cellSize[YY] < by0)
+                            else if (jGridDims.lowerCorner[YY] + (cy_real + 1)*jGridDims.cellSize[YY] < by0)
                             {
-                                d2zxy += gmx::square(jGridDims.lowerCorner[YY] + (cy + 1)*jGridDims.cellSize[YY] - by0);
+                                d2zxy += gmx::square(jGridDims.lowerCorner[YY] + (cy_real + 1)*jGridDims.cellSize[YY] - by0);
                             }
                             if (columnStart < columnEnd && d2zxy < listRangeBBToJCell2)
                             {
@@ -3517,7 +3517,7 @@ static void nbnxn_make_pairlist_part(const Nbnxm::GridSet &gridSet,
                                  * but we do not do this because it would
                                  * complicate this code even more.
                                  */
-                                int midCell = columnStart + static_cast<int>(bz1_frac*(columnEnd - columnStart));
+                                int midCell = columnStart + static_cast<int>(bz1_frac*static_cast<real>(columnEnd - columnStart));
                                 if (midCell >= columnEnd)
                                 {
                                     midCell = columnEnd - 1;
@@ -3746,7 +3746,7 @@ static void copySelectedListRange(const nbnxn_ci_t * gmx_restrict srcCi,
 
     dest->ci.push_back(*srcCi);
     dest->ci.back().cj_ind_start = dest->cj.size();
-    dest->ci.back().cj_ind_end   = dest->cj.size() + ncj;
+    dest->ci.back().cj_ind_end   = dest->ci.back().cj_ind_start + ncj;
 
     if (setFlags)
     {
@@ -3902,7 +3902,7 @@ static bool checkRebalanceSimpleLists(gmx::ArrayRef<const NbnxnPairlistCpu> list
      */
     const real rebalanceTolerance = 1.03;
 
-    return numLists*ncjMax > ncjTotal*rebalanceTolerance;
+    return real(numLists*ncjMax) > real(ncjTotal)*rebalanceTolerance;
 }
 
 /* Perform a count (linear) sort to sort the smaller lists to the end.
@@ -3926,7 +3926,7 @@ static void sort_sci(NbnxnPairlistGpu *nbl)
     NbnxnPairlistGpuWork &work = *nbl->work;
 
     /* We will distinguish differences up to double the average */
-    const int m = (2*nbl->cj4.size())/nbl->sci.size();
+    const int m = static_cast<int>((2*ssize(nbl->cj4))/ssize(nbl->sci));
 
     /* Resize work.sci_sort so we can sort into it */
     work.sci_sort.resize(nbl->sci.size());
@@ -3944,7 +3944,7 @@ static void sort_sci(NbnxnPairlistGpu *nbl)
     /* Calculate the offset for each count */
     int s0  = sort[m];
     sort[m] = 0;
-    for (int i = m - 1; i >= 0; i--)
+    for (gmx::index i = m - 1; i >= 0; i--)
     {
         int s1  = sort[i];
         sort[i] = sort[i + 1] + s0;
index 41e8dc25b50465102a88c8724a099867ffc598b7..2cf5c41cf9f824f699464513705852812fe84e89 100644 (file)
@@ -89,7 +89,7 @@ class PairlistSets
         //! Returns the number of steps performed with the current pair list
         int numStepsWithPairlist(int64_t step) const
         {
-            return step - outerListCreationStep_;
+            return static_cast<int>(step - outerListCreationStep_);
         }
 
         //! Returns whether step is a dynamic list pruning step, for CPU lists
index e87cc4862627c4360573f5a3b26c9ee563b3d123..f1abfe65f75d2c02a6cc64ae0cdf6846575ed790 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2015,2016,2018, by the GROMACS development team, led by
+ * Copyright (c) 2015,2016,2018,2019, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -169,7 +169,7 @@ class TabulatedNormalDistribution
          *  and is exposed only to permit testing. Normal code should not
          *  need to call this function.
          */
-        static const
+        static
         std::array<RealType, 1<<tableBits>
         makeTable()
         {
index 780326ebc210a37ac9e6857edbbae5d44a92277b..e80182c99034959b657adebb44a8b2585ac6f28c 100644 (file)
@@ -69,7 +69,7 @@ class RestraintManager::Impl
          * \param restraint Handle to be added to the manager.
          * \param name Identifying string for restraint.
          */
-        void add(std::shared_ptr<::gmx::IRestraintPotential> restraint, std::string name);
+        void add(std::shared_ptr<::gmx::IRestraintPotential> restraint, const std::string &name);
 
         /*!
          * \brief Clear registered restraints and reset the manager.
@@ -96,7 +96,7 @@ class RestraintManager::Impl
 std::mutex RestraintManager::Impl::initializationMutex_ {};
 
 
-void RestraintManager::Impl::add(std::shared_ptr<::gmx::IRestraintPotential> restraint, std::string name)
+void RestraintManager::Impl::add(std::shared_ptr<::gmx::IRestraintPotential> restraint, const std::string &name)
 {
     (void)name;
     restraint_.emplace_back(std::move(restraint));
@@ -119,9 +119,9 @@ void RestraintManager::clear() noexcept
 }
 
 void RestraintManager::addToSpec(std::shared_ptr<gmx::IRestraintPotential> puller,
-                                 std::string                               name)
+                                 const std::string                        &name)
 {
-    instance_->add(std::move(puller), std::move(name));
+    instance_->add(std::move(puller), name);
 }
 
 std::vector< std::shared_ptr<IRestraintPotential> > RestraintManager::getRestraints() const
index 98c719fe02c11b3d2210bcc4abe9ab3bb6047625..30b6bab3733d3d57c3a6c2cd413229f3f5a109e5 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2018, by the GROMACS development team, led by
+ * Copyright (c) 2018,2019, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -116,7 +116,7 @@ class RestraintManager final
          * \param name key by which to reference the restraint.
          */
         void addToSpec(std::shared_ptr<gmx::IRestraintPotential> restraint,
-                       std::string                               name);
+                       const std::string                        &name);
 
         /*!
          * \brief Get a copy of the current set of restraints to be applied.
index 23911799c27671beb6e14a88f41ba7a1ff64ff32..1c3c27a0d3d4dc307aaa727f09e9da60a36574e6 100644 (file)
@@ -248,9 +248,9 @@ gmx_ana_indexgrps_find(gmx_ana_index_t *dest, std::string *destName,
 void
 gmx_ana_indexgrps_print(gmx::TextWriter *writer, gmx_ana_indexgrps_t *g, int maxn)
 {
-    for (int i = 0; i < gmx::ssize(g->g); ++i)
+    for (gmx::index i = 0; i < gmx::ssize(g->g); ++i)
     {
-        writer->writeString(gmx::formatString(" Group %2d \"%s\" ",
+        writer->writeString(gmx::formatString(" Group %2zd \"%s\" ",
                                               i, g->names[i].c_str()));
         gmx_ana_index_dump(writer, &g->g[i], maxn);
     }
@@ -965,7 +965,7 @@ gmx_ana_index_has_full_blocks(const gmx_ana_index_t        *g,
     while (i < g->isize)
     {
         /* Find the block that begins with the first unmatched atom */
-        while (bi < b->numBlocks() && b->block(bi).begin() != g->index[i])
+        while (bi < b->numBlocks() && *b->block(bi).begin() != g->index[i])
         {
             ++bi;
         }
@@ -975,7 +975,7 @@ gmx_ana_index_has_full_blocks(const gmx_ana_index_t        *g,
             return false;
         }
         /* Check that the block matches the index */
-        for (j = b->block(bi).begin(); j < b->block(bi).end(); ++j, ++i)
+        for (j = *b->block(bi).begin(); j < *b->block(bi).end(); ++j, ++i)
         {
             if (g->index[i] != j)
             {
index 49549d523d4aaa8670ec0ca2f1edc14276afedcb..d7e6320f1fc8e27eed3dd33d552d30dc92b82a22 100644 (file)
@@ -576,7 +576,7 @@ class SimdSetZeroProxy
  *         variable to zero based on the conversion function called when you
  *         assign the result.
  */
-static inline const SimdSetZeroProxy gmx_simdcall
+static inline SimdSetZeroProxy gmx_simdcall
 setZero()
 {
     return {};
index 16bec32ef99f22208e00b9b6b9f30c0017812c99..4333fa7677158a61d06405dd35d3a9f0454e45b3 100644 (file)
@@ -410,7 +410,7 @@ bool AtomProperties::setAtomProperty(int                eprop,
 }
 
 
-const std::string AtomProperties::elementFromAtomNumber(int atomNumber)
+std::string AtomProperties::elementFromAtomNumber(int atomNumber)
 {
     if (setProperties(prop(epropElement), restype(), epropElement, impl_->bWarned))
     {
index 32cd835a39d79ae3544f235dcebca76e332c7c3d..267979c5451388f1ebd9aabc628727196ac125ee 100644 (file)
@@ -70,7 +70,7 @@ class AtomProperties
          * \todo This should be made const once the lazy
          * implementation is done properly for the class.
          */
-        const std::string elementFromAtomNumber(int atomNumber);
+        std::string elementFromAtomNumber(int atomNumber);
         /*! \brief
          * Get atom number from element string.
          *
index f047f6680946b765bd9a1f5b9b3e69e10fa53207..e39e0f72f4d0aea6b19241b372cfa9b00880890e 100644 (file)
@@ -93,9 +93,9 @@ class RangePartitioning
                 }
 
                 /*! \brief Begin iterator/value */
-                const iterator begin() const { return begin_; }
+                iterator begin() const { return begin_; }
                 /*! \brief End iterator/value */
-                const iterator end() const { return end_; }
+                iterator end() const { return end_; }
 
                 /*! \brief The number of items in the block */
                 int size() const
@@ -117,7 +117,7 @@ class RangePartitioning
         /*! \brief Returns the number of blocks */
         int numBlocks() const
         {
-            return static_cast<int>(index_.size() - 1);
+            return static_cast<int>(index_.size()) - 1;
         }
 
         /*! \brief Returns the size of the block with index \p blockIndex */
index 5c7b1cfeecce9cd91cc2acd0e8bad555f0e58c0b..1935cd2f9438f0cf62d6152c4c8fc30bdd830f3f 100644 (file)
@@ -44,7 +44,7 @@
 static void pr_cmap(FILE *fp, int indent, const char *title,
                     const gmx_cmap_t *cmap_grid, gmx_bool bShowNumbers)
 {
-    int  i, j, nelem;
+    int  j, nelem;
     real dx, idx;
 
     if (cmap_grid->grid_spacing != 0)
@@ -61,12 +61,12 @@ static void pr_cmap(FILE *fp, int indent, const char *title,
     {
         fprintf(fp, "%s\n", title);
 
-        for (i = 0; i < gmx::ssize(cmap_grid->cmapdata); i++)
+        for (gmx::index i = 0; i < gmx::ssize(cmap_grid->cmapdata); i++)
         {
             idx = -180.0;
             fprintf(fp, "%8s %8s %8s %8s\n", "V", "dVdx", "dVdy", "d2dV");
 
-            fprintf(fp, "grid[%3d]={\n", bShowNumbers ? i : -1);
+            fprintf(fp, "grid[%3zd]={\n", bShowNumbers ? i : -1);
 
             for (j = 0; j < nelem; j++)
             {
index fa0a06ae048db491cc65a1253efb49f19628bd0d..1cf3c8d37441612316304fbe66815cc3eed46e88 100644 (file)
@@ -255,7 +255,7 @@ struct InteractionListHandle
  * \param[in] ilists  Set of interaction lists
  * \param[in] flags   Bit mask with one or more IF_... bits set
  */
-static inline const std::vector<InteractionListHandle>
+static inline std::vector<InteractionListHandle>
 extractILists(const InteractionLists &ilists,
               int                     flags)
 {
index f36af6a649f336049d30003f97851ff24a402dc5..a0382f3da51f2345b1fe5c8df6a5a6a0c197cf36 100644 (file)
@@ -120,7 +120,7 @@ void add_grp(t_blocka *b, char ***gnames, gmx::ArrayRef<const int> a, const std:
     (*gnames)[b->nr] = gmx_strdup(name.c_str());
 
     srenew(b->a, b->nra+a.size());
-    for (int i = 0; (i < a.ssize()); i++)
+    for (gmx::index i = 0; (i < a.ssize()); i++)
     {
         b->a[b->nra++] = a[i];
     }
@@ -154,7 +154,7 @@ static bool grp_cmp(t_blocka *b, gmx::ArrayRef<const int> a, int index)
     {
         return FALSE;
     }
-    for (int i = 0; i < a.ssize(); i++)
+    for (gmx::index i = 0; i < a.ssize(); i++)
     {
         if (a[i] != b->a[b->index[index]+i])
         {
@@ -616,7 +616,7 @@ void analyse(const t_atoms *atoms, t_blocka *gb, char ***gn, gmx_bool bASK, gmx_
         p_status(restype, previousTypename);
     }
 
-    for (int k = 0; k < gmx::index(previousTypename.size()); k++)
+    for (gmx::index k = 0; k < gmx::ssize(previousTypename); k++)
     {
         aid = mk_aid(atoms, restype, previousTypename[k], TRUE);
 
@@ -854,7 +854,7 @@ int find_group(const char *s, int ngrps, char **grpname)
         minstring(key);
         for (i = 0; i < ngrps; i++)
         {
-            strcpy(string, grpname[i]);
+            strncpy(string, grpname[i], STRLEN-1);
             upstring(string);
             minstring(string);
             if (strstr(string, key) != nullptr)
index 3d6824754f4bb363e1cc5fef25256e92cc2a37b7..8387f8fe33ffae74e24adb3059fcc6761b51e589 100644 (file)
@@ -157,7 +157,7 @@ int ResidueType::indexFromResidueName(const std::string &residueName) const
     return foundIt ? std::distance(temp.begin(), *foundIt) : -1;
 }
 
-const std::string ResidueType::nameFromResidueIndex(int index) const
+std::string ResidueType::nameFromResidueIndex(int index) const
 {
     if (index >= 0 && index < gmx::ssize(impl_->entry))
     {
index b53defa676e0fcb08b4d8b8638bdb36cbda5f66b..afadef8610ae909ffce3d279b6b28d31cfb7db85 100644 (file)
@@ -91,7 +91,7 @@ class ResidueType
          * \param[in] index Which entry should be returned.
          * \returns The name of the entry at \p index, or nullptr.
          */
-        const std::string nameFromResidueIndex(int index) const;
+        std::string nameFromResidueIndex(int index) const;
         /*! \brief
          * Return the residue type if a residue with that name exists, or "Other"
          *
index 1bc41d82dea999cc68dcddde52cb03e66b11921d..2fa0d6b92af8e748cb4c860ec42f564b43f72707 100644 (file)
@@ -59,13 +59,13 @@ namespace
 {
 
 //! Add a new group to t_blocka
-void addGroupToBlocka(t_blocka *b, gmx::ArrayRef<const int> index)
+void addGroupToBlocka(t_blocka *b, gmx::ArrayRef<const int> indices)
 {
     srenew(b->index, b->nr+2);
-    srenew(b->a, b->nra+index.size());
-    for (int i = 0; (i < index.ssize()); i++)
+    srenew(b->a, b->nra+indices.size());
+    for (index i = 0; i < indices.ssize(); i++)
     {
-        b->a[b->nra++] = index[i];
+        b->a[b->nra++] = indices[i];
     }
     b->nr++;
     b->index[b->nr] = b->nra;
@@ -74,12 +74,12 @@ void addGroupToBlocka(t_blocka *b, gmx::ArrayRef<const int> index)
 //! Fill ExclusionBlock with data.
 int fillExclusionBlock(gmx::ArrayRef<ExclusionBlock> b)
 {
-    std::vector < std::vector < int>> index = {{0, 4, 7}, {1, 5, 8, 10}, {2, 6, 9, 11, 12}};
+    std::vector < std::vector < int>> indices = {{0, 4, 7}, {1, 5, 8, 10}, {2, 6, 9, 11, 12}};
     int nra = 0;
-    for (int i = 0; i < b.ssize(); i++)
+    for (index i = 0; i < b.ssize(); i++)
     {
         b[i].atomNumber.clear();
-        for (const auto &j : index[i])
+        for (const auto &j : indices[i])
         {
             b[i].atomNumber.push_back(j);
         }
@@ -93,12 +93,12 @@ void makeTestBlockAData(t_blocka *ba)
 {
     init_blocka(ba);
 
-    std::vector<int> index = {12, 11, 9, 6, 2};
-    addGroupToBlocka(ba, index);
-    index = {10, 8, 5, 1};
-    addGroupToBlocka(ba, index);
-    index = {7, 4, 0};
-    addGroupToBlocka(ba, index);
+    std::vector<int> indices = {12, 11, 9, 6, 2};
+    addGroupToBlocka(ba, indices);
+    indices = {10, 8, 5, 1};
+    addGroupToBlocka(ba, indices);
+    indices = {7, 4, 0};
+    addGroupToBlocka(ba, indices);
 }
 
 class ExclusionBlockTest : public ::testing::Test
@@ -117,7 +117,7 @@ class ExclusionBlockTest : public ::testing::Test
 
         void compareBlocks()
         {
-            for (unsigned i = 0; i < b_.size(); i++)
+            for (index i = 0; i < ssize(b_); i++)
             {
                 int index  = ba_.index[i];
                 for (int j = 0; j < b_[i].nra(); j++)
index d43ae865b6597eaa1cadfb1d3d7d19cf7d2b8eb3..baa0f5bf266a70aec975de69e34f226a45beb47a 100644 (file)
@@ -563,7 +563,7 @@ static void compareMoltypes(FILE *fp, gmx::ArrayRef<const gmx_moltype_t> mt1, gm
 static void compareMoletypeAB(FILE *fp, gmx::ArrayRef<const gmx_moltype_t> mt1, real relativeTolerance, real absoluteTolerance)
 {
     fprintf(fp, "comparing free energy molecule types\n");
-    for (int i = 0; i < mt1.ssize(); i++)
+    for (gmx::index i = 0; i < mt1.ssize(); i++)
     {
         compareAtoms(fp, &mt1[i].atoms, nullptr, relativeTolerance, absoluteTolerance);
     }
@@ -659,9 +659,9 @@ void compareAtomGroups(FILE *fp, const SimulationGroups &g0, const SimulationGro
         cmp_int(fp, buf.c_str(), -1, g0.groups[group].size(), g1.groups[group].size());
         if (g0.groups[group].size() == g1.groups[group].size())
         {
-            for (int j = 0; j < gmx::ssize(g0.groups[group]); j++)
+            for (gmx::index j = 0; j < gmx::ssize(g0.groups[group]); j++)
             {
-                buf = gmx::formatString("grps[%d].name[%d]", static_cast<int>(group), j);
+                buf = gmx::formatString("grps[%d].name[%zd]", static_cast<int>(group), j);
                 cmp_str(fp, buf.c_str(), -1,
                         *g0.groupNames[g0.groups[group][j]],
                         *g1.groupNames[g1.groups[group][j]]);
index 3ef6c4f70ee0ef3323f6f055a69a1f277737fdd3..61f38ec8277d623038a6e5c99f88359050ad2e06 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2018, by the GROMACS development team, led by
+ * Copyright (c) 2018,2019, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -54,7 +54,7 @@ namespace gmx
 {
 
 EnergyFrame::EnergyFrame(const t_enxframe &enxframe,
-                         const std::map<std::string, int> indicesOfEnergyFields)
+                         const std::map<std::string, int> &indicesOfEnergyFields)
     : step_(enxframe.step), time_(enxframe.t)
 {
     for (auto &index : indicesOfEnergyFields)
index 0819a8eccfc66dcc0cf37bac22fa51da48129117..d99153763b7d18e386f0a684807edce40b79edc6 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015,2016,2017,2018,2019, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -88,7 +88,7 @@ class EnergyFrame
         using MapConstIterator = MapType::const_iterator;
         //! Constructor
         EnergyFrame(const t_enxframe &enxframe,
-                    std::map<std::string, int> indicesOfEnergyFields);
+                    const std::map<std::string, int> &indicesOfEnergyFields);
         /*! \brief Return string that helps users identify this frame, containing time and step number.
          *
          * \throws std::bad_alloc  when out of memory */
index f7405352681081690639424994ff142cdd4ee92e..03238a2bceb83c4f454f52eecb61ec7f47684b02 100644 (file)
@@ -68,6 +68,7 @@
 #include <cstring>
 
 #include <algorithm>
+#include <array>
 #include <string>
 
 /* This file is completely threadsafe - keep it that way! */
@@ -166,14 +167,14 @@ void printCopyright(gmx::TextWriter *writer)
     {
         for (int j = 0; j < 4 && i < NCONTRIBUTORS; ++j, ++i)
         {
-            const int width = 18;
-            char      buf[30];
-            const int offset = centeringOffset(width, strlen(Contributors[i]));
-            GMX_RELEASE_ASSERT(static_cast<int>(strlen(Contributors[i])) + offset < asize(buf),
+            const int            width = 18;
+            std::array<char, 30> buf;
+            const int            offset = centeringOffset(width, strlen(Contributors[i]));
+            GMX_RELEASE_ASSERT(static_cast<int>(strlen(Contributors[i])) + offset < gmx::ssize(buf),
                                "Formatting buffer is not long enough");
-            std::fill(buf, buf+width, ' ');
-            std::strcpy(buf+offset, Contributors[i]);
-            writer->writeString(formatString(" %-*s", width, buf));
+            std::fill(buf.begin(), buf.begin()+offset, ' ');
+            std::strncpy(buf.data()+offset, Contributors[i], gmx::ssize(buf) - offset);
+            writer->writeString(formatString(" %-*s", width, buf.data()));
         }
         writer->ensureLineBreak();
     }
index e9deb399b0d71552b8ffe5e8a822bb71a2b606fe..730aaf092dfbc26cb8063d389be85173d079732f 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015,2016,2017,2018,2019, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -278,8 +278,9 @@ char *gmx_strdup(const char *src)
 {
     char *dest;
 
-    snew(dest, strlen(src)+1);
-    strcpy(dest, src);
+    auto  length = strlen(src)+1;
+    snew(dest, length);
+    std::strncpy(dest, src, length);
 
     return dest;
 }
index 37234b54b4576c4ca22c824de49aed023ecef7ba..a4606ffd30d9301500c62bb075c23b7f3ac2eb44 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015,2016,2017,2018,2019, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -241,22 +241,17 @@ void _gmx_error(const char *key, const std::string &msg, const char *file, int l
 void _range_check(int n, int n_min, int n_max, const char *warn_str,
                   const char *var, const char *file, int line)
 {
-    char buf[1024];
-
     if ((n < n_min) || (n >= n_max))
     {
+        std::string buf;
         if (warn_str != nullptr)
         {
-            strcpy(buf, warn_str);
-            strcat(buf, "\n");
-        }
-        else
-        {
-            buf[0] = '\0';
+            buf  = warn_str;
+            buf += "\n";
         }
 
-        sprintf(buf+strlen(buf), "Variable %s has value %d. It should have been "
-                "within [ %d .. %d ]\n", var, n, n_min, n_max);
+        buf += gmx::formatString("Variable %s has value %d. It should have been "
+                                 "within [ %d .. %d ]\n", var, n, n_min, n_max);
 
         _gmx_error("range", buf, file, line);
     }
index 0ce225ea75539b6a321aae3a5d5afd7cd47883ad..a30891179703b740b8b5460d089fa717203eecda 100644 (file)
@@ -256,7 +256,6 @@ class KeyValueTreeObject
             return *this;
         }
         //! Default move constructor.
-        //NOLINTNEXTLINE(performance-noexcept-move-constructor) bug #38733
         KeyValueTreeObject(KeyValueTreeObject &&)            = default;
         //! Default move assignment.
         KeyValueTreeObject &operator=(KeyValueTreeObject &&) = default;
index 233deecc7064f940d445c79bb43f15a09a0a6f26..f46b7b30d48f71e950cc666b8c44c4c030026446 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015,2016,2017,2018,2019, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -93,23 +93,21 @@ gmx_bool get_a_line(FILE *fp, char line[], int n)
 
 gmx_bool get_header(char line[], char *header)
 {
-    char temp[STRLEN], *dum;
-
-    std::strcpy(temp, line);
-    dum = std::strchr(temp, '[');
-    if (dum == nullptr)
+    std::string temp  = line;
+    auto        index = temp.find('[');
+    if (index == std::string::npos)
     {
         return FALSE;
     }
-    dum[0] = ' ';
-    dum    = std::strchr(temp, ']');
-    if (dum == nullptr)
+    temp[index] = ' ';
+    index       = temp.find(']', index);
+    if (index == std::string::npos)
     {
         gmx_fatal(FARGS, "header is not terminated on line:\n'%s'\n", line);
         return FALSE;
     }
-    dum[0] = '\0';
-    return sscanf(temp, "%s%*s", header) == 1;
+    temp.resize(index);
+    return sscanf(temp.c_str(), "%s%*s", header) == 1;
 }
 
 int search_str(int nstr, char **str, char *key)
index f68d401ffe197d36792cfdbaeb35d5e932229f49..0f1e7064d6d0a2fffab19b1629a819a09c4968b0 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2014,2015,2016,2018, by the GROMACS development team, led by
+ * Copyright (c) 2014,2015,2016,2018,2019, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -329,8 +329,8 @@ FloatingPointTolerance
 relativeToleranceAsFloatingPoint(double magnitude, double tolerance)
 {
     const double absoluteTolerance = std::abs(magnitude) * tolerance;
-    return FloatingPointTolerance(absoluteTolerance, absoluteTolerance,
-                                  tolerance, tolerance,
+    return FloatingPointTolerance(static_cast<float>(absoluteTolerance), absoluteTolerance,
+                                  static_cast<float>(tolerance), tolerance,
                                   UINT64_MAX, UINT64_MAX,
                                   false);
 }
index c4a2cce9ecdc76e0c8dfc33dd1d06540d24e3adc..28482844986931a03aa27a46b264a897404f4986 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015,2016,2017,2018,2019, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -446,7 +446,7 @@ relativeToleranceAsPrecisionDependentUlp(double       magnitude,
                                          uint64_t     singleUlpDiff,
                                          uint64_t     doubleUlpDiff)
 {
-    return FloatingPointTolerance(magnitude*singleUlpDiff*GMX_FLOAT_EPS,
+    return FloatingPointTolerance(float(magnitude)*singleUlpDiff*GMX_FLOAT_EPS,
                                   magnitude*doubleUlpDiff*GMX_DOUBLE_EPS,
                                   0.0, 0.0,
                                   singleUlpDiff, doubleUlpDiff, false);
@@ -460,7 +460,7 @@ relativeToleranceAsPrecisionDependentUlp(double       magnitude,
 static inline FloatingPointTolerance
 absoluteTolerance(double tolerance)
 {
-    return FloatingPointTolerance(tolerance, tolerance, 0.0, 0.0,
+    return FloatingPointTolerance(float(tolerance), tolerance, 0.0, 0.0,
                                   UINT64_MAX, UINT64_MAX, false);
 }
 
index 0dfec75d9f57e0ec55779316b5bea7e2cc9eedc5..159b75c93bf2c9fc155afaf866f954719f901768 100644 (file)
@@ -148,7 +148,7 @@ TextBlockMatcherPointer NoTextMatch::createMatcher() const
 }
 
 FilteringExactTextMatch::FilteringExactTextMatch(std::vector<std::string> linesToSkip)
-    : linesToSkip_(linesToSkip)
+    : linesToSkip_(std::move(linesToSkip))
 {}
 
 void FilteringExactTextMatch::addRegexToSkip(const std::string &lineToSkip)