From 658819431c0dabdb13ef01f32bf59e0c0eca82ff Mon Sep 17 00:00:00 2001 From: Mark Abraham Date: Sat, 6 Jul 2019 20:37:45 +0200 Subject: [PATCH] Update clang-tidy to clang version 8 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 --- docs/dev-manual/build-system.rst | 22 ++++++ docs/dev-manual/tools.rst | 24 +------ src/.clang-tidy | 47 ++++++++++++- src/.clang-tidy.new.code | 16 ++++- src/external/.clang-tidy | 5 +- src/gromacs/analysisdata/abstractdata.cpp | 10 +-- src/gromacs/analysisdata/abstractdata.h | 6 +- .../analysisdata/datamodulemanager.cpp | 6 +- src/gromacs/analysisdata/datamodulemanager.h | 6 +- src/gromacs/awh/pointstate.h | 2 +- .../coordinateio/tests/coordinate_test.h | 2 +- src/gromacs/domdec/hashedmap.h | 4 +- src/gromacs/domdec/redistribute.cpp | 6 +- src/gromacs/fft/fft.cpp | 24 +++---- src/gromacs/fft/fft_fftpack.cpp | 52 +++++++------- src/gromacs/fileio/tngio.cpp | 2 +- src/gromacs/gmxana/gmx_nmeig.cpp | 4 +- src/gromacs/gmxana/gmx_nmr.cpp | 12 ++-- src/gromacs/gmxana/gmx_nmtraj.cpp | 50 +++++--------- src/gromacs/gmxana/gmx_order.cpp | 34 +++++----- src/gromacs/gmxana/gmx_potential.cpp | 6 +- src/gromacs/gmxana/gmx_rms.cpp | 14 ++-- src/gromacs/gmxana/gmx_rmsdist.cpp | 14 ++-- src/gromacs/gmxana/gmx_rotacf.cpp | 4 +- src/gromacs/gmxana/gmx_vanhove.cpp | 4 +- src/gromacs/gmxpreprocess/gen_vsite.cpp | 4 +- src/gromacs/gmxpreprocess/grompp.cpp | 2 +- src/gromacs/gmxpreprocess/pdb2gmx.cpp | 8 +-- src/gromacs/gmxpreprocess/readir.cpp | 12 ++-- src/gromacs/gmxpreprocess/toppush.cpp | 8 +-- src/gromacs/gmxpreprocess/vsite_parm.cpp | 2 +- src/gromacs/hardware/cpuinfo.cpp | 4 +- src/gromacs/hardware/hardwaretopology.cpp | 2 +- src/gromacs/math/gausstransform.cpp | 8 ++- src/gromacs/math/gausstransform.h | 2 +- src/gromacs/math/tests/functions.cpp | 8 +-- src/gromacs/math/vec.h | 16 ++++- src/gromacs/mdlib/calc_verletbuf.cpp | 9 +-- src/gromacs/mdlib/constr.cpp | 2 +- src/gromacs/mdlib/constr.h | 2 +- src/gromacs/mdlib/mdebin_bar.cpp | 2 +- src/gromacs/mdlib/qmmm.cpp | 2 +- src/gromacs/mdlib/sim_util.cpp | 4 +- src/gromacs/mdlib/tests/constr.cpp | 8 +-- src/gromacs/mdlib/tests/constrtestdata.cpp | 9 +-- src/gromacs/mdlib/tests/constrtestrunners.cpp | 6 +- src/gromacs/mdlib/tests/energyoutput.cpp | 46 ++++++------- src/gromacs/mdlib/tests/settletestdata.cpp | 28 +++----- src/gromacs/mdlib/updategroupscog.cpp | 2 +- src/gromacs/mdrun/minimize.cpp | 8 +-- src/gromacs/mdrun/runner.cpp | 4 +- src/gromacs/mdrun/runner.h | 2 +- src/gromacs/nbnxm/atomdata.cpp | 2 +- src/gromacs/nbnxm/grid.cpp | 2 +- src/gromacs/nbnxm/gridset.h | 2 +- src/gromacs/nbnxm/kerneldispatch.cpp | 6 +- .../kernels_reference/kernel_gpu_ref.cpp | 8 +-- .../kernels_reference/kernel_ref_inner.h | 10 ++- .../nbnxm/kernels_simd_2xmm/kernel_inner.h | 2 +- .../nbnxm/kernels_simd_2xmm/kernel_outer.h | 2 +- .../nbnxm/kernels_simd_4xm/kernel_inner.h | 2 +- .../nbnxm/kernels_simd_4xm/kernel_outer.h | 2 +- src/gromacs/nbnxm/pairlist.cpp | 68 +++++++++---------- src/gromacs/nbnxm/pairlistsets.h | 2 +- .../random/tabulatednormaldistribution.h | 4 +- src/gromacs/restraint/manager.cpp | 8 +-- src/gromacs/restraint/manager.h | 4 +- src/gromacs/selection/indexutil.cpp | 8 +-- src/gromacs/simd/simd.h | 2 +- src/gromacs/topology/atomprop.cpp | 2 +- src/gromacs/topology/atomprop.h | 2 +- src/gromacs/topology/block.h | 6 +- src/gromacs/topology/forcefieldparameters.cpp | 6 +- src/gromacs/topology/idef.h | 2 +- src/gromacs/topology/index.cpp | 8 +-- src/gromacs/topology/residuetypes.cpp | 2 +- src/gromacs/topology/residuetypes.h | 2 +- .../topology/tests/exclusionblocks.cpp | 28 ++++---- src/gromacs/topology/topology.cpp | 6 +- src/gromacs/trajectory/energyframe.cpp | 4 +- src/gromacs/trajectory/energyframe.h | 4 +- src/gromacs/utility/binaryinformation.cpp | 15 ++-- src/gromacs/utility/cstringutil.cpp | 7 +- src/gromacs/utility/fatalerror.cpp | 17 ++--- src/gromacs/utility/keyvaluetree.h | 1 - src/gromacs/utility/strdb.cpp | 20 +++--- src/testutils/testasserts.cpp | 6 +- src/testutils/testasserts.h | 6 +- src/testutils/textblockmatchers.cpp | 2 +- 89 files changed, 454 insertions(+), 412 deletions(-) diff --git a/docs/dev-manual/build-system.rst b/docs/dev-manual/build-system.rst index fbdbedb2f4..f7a3f0ab40 100644 --- a/docs/dev-manual/build-system.rst +++ b/docs/dev-manual/build-system.rst @@ -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 `_ + 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 `_. 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 '.*' '(?`_ - is used for static code analysis. clang-tidy is easy to install. It is contained in - the llvm binary `package `_. 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 '.*' '(?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 proxy( new AnalysisDataProxy(col, span, this)); - proxy->addModule(std::move(module)); + proxy->addModule(module); addModule(proxy); } diff --git a/src/gromacs/analysisdata/abstractdata.h b/src/gromacs/analysisdata/abstractdata.h index b4a15e6d25..d57ade6401 100644 --- a/src/gromacs/analysisdata/abstractdata.h +++ b/src/gromacs/analysisdata/abstractdata.h @@ -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. * diff --git a/src/gromacs/analysisdata/datamodulemanager.cpp b/src/gromacs/analysisdata/datamodulemanager.cpp index c8e34606da..58a4aee2ce 100644 --- a/src/gromacs/analysisdata/datamodulemanager.cpp +++ b/src/gromacs/analysisdata/datamodulemanager.cpp @@ -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 diff --git a/src/gromacs/analysisdata/datamodulemanager.h b/src/gromacs/analysisdata/datamodulemanager.h index 2bc9bdb64b..72909dc768 100644 --- a/src/gromacs/analysisdata/datamodulemanager.h +++ b/src/gromacs/analysisdata/datamodulemanager.h @@ -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. * diff --git a/src/gromacs/awh/pointstate.h b/src/gromacs/awh/pointstate.h index 2215344418..4e177c42c9 100644 --- a/src/gromacs/awh/pointstate.h +++ b/src/gromacs/awh/pointstate.h @@ -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); diff --git a/src/gromacs/coordinateio/tests/coordinate_test.h b/src/gromacs/coordinateio/tests/coordinate_test.h index 5b12ba30a8..7fbaca8891 100644 --- a/src/gromacs/coordinateio/tests/coordinate_test.h +++ b/src/gromacs/coordinateio/tests/coordinate_test.h @@ -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, diff --git a/src/gromacs/domdec/hashedmap.h b/src/gromacs/domdec/hashedmap.h index bb0ccedab9..c12706f36f 100644 --- a/src/gromacs/domdec/hashedmap.h +++ b/src/gromacs/domdec/hashedmap.h @@ -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(numElementsEstimate)*c_relTableSizeSetMin > tableSize) { tableSize *= 2; } diff --git a/src/gromacs/domdec/redistribute.cpp b/src/gromacs/domdec/redistribute.cpp index 4e5a5ea5f1..d766f3f591 100644 --- a/src/gromacs/domdec/redistribute.cpp +++ b/src/gromacs/domdec/redistribute.cpp @@ -89,7 +89,7 @@ copyMovedAtomsToBufferPerAtom(gmx::ArrayRef 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 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 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) { diff --git a/src/gromacs/fft/fft.cpp b/src/gromacs/fft/fft.cpp index a141db16bc..23f1d25d92 100644 --- a/src/gromacs/fft/fft.cpp +++ b/src/gromacs/fft/fft.cpp @@ -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(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(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(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(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(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(in_data)+mfft->dist; + out_data = static_cast(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(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(in_data)+mfft->dist; + out_data = static_cast(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(fft); if (mfft != nullptr) { if (mfft->fft != nullptr) diff --git a/src/gromacs/fft/fft_fftpack.cpp b/src/gromacs/fft/fft_fftpack.cpp index 33655730bd..f87426fa67 100644 --- a/src/gromacs/fft/fft_fftpack.cpp +++ b/src/gromacs/fft/fft_fftpack.cpp @@ -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(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(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(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(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(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(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(in_data); + p2 = static_cast(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(in_data); + p2 = static_cast(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(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(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(in_data); + p2 = static_cast(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(in_data); + p2 = static_cast(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(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(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(in_data); + p2 = static_cast(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(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(in_data); + p2 = static_cast(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(data); + p2 = static_cast(out_data); for (i = 0; i < nx; i++) { diff --git a/src/gromacs/fileio/tngio.cpp b/src/gromacs/fileio/tngio.cpp index 862bb2c1b0..13474a4fe1 100644 --- a/src/gromacs/fileio/tngio.cpp +++ b/src/gromacs/fileio/tngio.cpp @@ -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]; diff --git a/src/gromacs/gmxana/gmx_nmeig.cpp b/src/gromacs/gmxana/gmx_nmeig.cpp index 078598875a..3a040fe57d 100644 --- a/src/gromacs/gmxana/gmx_nmeig.cpp +++ b/src/gromacs/gmxana/gmx_nmeig.cpp @@ -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); diff --git a/src/gromacs/gmxana/gmx_nmr.cpp b/src/gromacs/gmxana/gmx_nmr.cpp index 929a1d994a..a8eff5ea27 100644 --- a/src/gromacs/gmxana/gmx_nmr.cpp +++ b/src/gromacs/gmxana/gmx_nmr.cpp @@ -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); } diff --git a/src/gromacs/gmxana/gmx_nmtraj.cpp b/src/gromacs/gmxana/gmx_nmtraj.cpp index 63354ff9e0..b7777611e8 100644 --- a/src/gromacs/gmxana/gmx_nmtraj.cpp +++ b/src/gromacs/gmxana/gmx_nmtraj.cpp @@ -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 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(imodeString)); } + int nmodes = gmx::ssize(imodes); - /* Now read phases */ - nphases = gmx::countWords(phasevec); - - if (nphases > nmodes) + std::vector 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(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(i)/nframes; + real fraction = static_cast(i)/static_cast(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(i)/nframes, box, xout, nullptr, nullptr); + write_trx(out, natoms, dummy, atoms, i, fraction, box, xout, nullptr, nullptr); } fprintf(stderr, "\n"); diff --git a/src/gromacs/gmxana/gmx_order.cpp b/src/gromacs/gmxana/gmx_order.cpp index 87dda9fbc1..0073ec72d2 100644 --- a/src/gromacs/gmxana/gmx_order.cpp +++ b/src/gromacs/gmxana/gmx_order.cpp @@ -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(nsgbin * cost2); + ibin = static_cast(static_cast(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(std::round((1+x[i][slice_dim]/box[slice_dim][slice_dim])*nslice)) % nslice; + sl_index = static_cast(std::round((1+x[i][slice_dim]/box[slice_dim][slice_dim])*static_cast(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(maxidx); + *skmean /= static_cast(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(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(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(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(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((nslices*z_ave)/box[axis][axis]); + slice = static_cast((static_cast(nslices)*z_ave)/box[axis][axis]); while (slice < 0) { - slice += nslices; + slice += static_cast(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(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(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(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(slice)*slWidth, S/static_cast(atom)); } } diff --git a/src/gromacs/gmxana/gmx_potential.cpp b/src/gromacs/gmxana/gmx_potential.cpp index 4c39aa2e41..fef1987053 100644 --- a/src/gromacs/gmxana/gmx_potential.cpp +++ b/src/gromacs/gmxana/gmx_potential.cpp @@ -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((*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(nr_frames) * box[axis][axis] * box[ax1][ax1] * box[ax2][ax2]); } } /* Now we have charge densities */ diff --git a/src/gromacs/gmxana/gmx_rms.cpp b/src/gromacs/gmxana/gmx_rms.cpp index 1e29cc0fd4..ed445c3aaf 100644 --- a/src/gromacs/gmxana/gmx_rms.cpp +++ b/src/gromacs/gmxana/gmx_rms.cpp @@ -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(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(tel_mat)*static_cast(tel_mat2); } else { @@ -1037,7 +1037,7 @@ int gmx_rms(int argc, char *argv[]) { mx = gmx::roundToInt(std::log(static_cast(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(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(i)/static_cast(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(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(teller)); } xvgrclose(fp); } diff --git a/src/gromacs/gmxana/gmx_rmsdist.cpp b/src/gromacs/gmxana/gmx_rmsdist.cpp index 0e47df8cc6..e001103edc 100644 --- a/src/gromacs/gmxana/gmx_rmsdist.cpp +++ b/src/gromacs/gmxana/gmx_rmsdist.cpp @@ -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(nframes)); + temp1_6 = gmx::invsixthroot(dtot1_6[i][j]/static_cast(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(noe[i][j].nr)); + noe[i][j].r_6 = gmx::invsixthroot(noe[i][j].i_6/static_cast(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(nframes); + mean2 = dtot2[i][j]/static_cast(nframes); rms = std::sqrt(std::max(0.0_real, mean2-mean*mean)); rmsc = rms/mean; if (mean > *meanmax) diff --git a/src/gromacs/gmxana/gmx_rotacf.cpp b/src/gromacs/gmxana/gmx_rotacf.cpp index be825a4103..809f6c051c 100644 --- a/src/gromacs/gmxana/gmx_rotacf.cpp +++ b/src/gromacs/gmxana/gmx_rotacf.cpp @@ -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(teller-1)); mode = eacVector; diff --git a/src/gromacs/gmxana/gmx_vanhove.cpp b/src/gromacs/gmxana/gmx_vanhove.cpp index 53e57368ef..e72a5f53a0 100644 --- a/src/gromacs/gmxana/gmx_vanhove.cpp +++ b/src/gromacs/gmxana/gmx_vanhove.cpp @@ -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(pr[fbin][i])/(rcount[fbin]*isize*rbin*(i == 0 ? 0.5 : 1.0))); + fprintf(fp, " %g", static_cast(pr[fbin][i]/(rcount[fbin]*isize*rbin*(i == 0 ? 0.5 : 1.0)))); } fprintf(fp, "\n"); } diff --git a/src/gromacs/gmxpreprocess/gen_vsite.cpp b/src/gromacs/gmxpreprocess/gen_vsite.cpp index 76e4c0f843..7255916acb 100644 --- a/src/gromacs/gmxpreprocess/gen_vsite.cpp +++ b/src/gromacs/gmxpreprocess/gen_vsite.cpp @@ -393,8 +393,8 @@ static int nitrogen_is_planar(gmx::ArrayRef vsit return res; } -static const std::string get_dummymass_name(gmx::ArrayRef vsiteconflist, - const std::string &atom, const std::string &nextheavy) +static std::string get_dummymass_name(gmx::ArrayRef 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(), diff --git a/src/gromacs/gmxpreprocess/grompp.cpp b/src/gromacs/gmxpreprocess/grompp.cpp index 0b30620662..4165fb295f 100644 --- a/src/gromacs/gmxpreprocess/grompp.cpp +++ b/src/gromacs/gmxpreprocess/grompp.cpp @@ -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); } diff --git a/src/gromacs/gmxpreprocess/pdb2gmx.cpp b/src/gromacs/gmxpreprocess/pdb2gmx.cpp index db8a24d4c0..3c040aab0c 100644 --- a/src/gromacs/gmxpreprocess/pdb2gmx.cpp +++ b/src/gromacs/gmxpreprocess/pdb2gmx.cpp @@ -262,10 +262,10 @@ static void read_rtprename(const char *fname, FILE *fp, } } -static const std::string search_resrename(gmx::ArrayRef rr, - const char *name, - bool bStart, bool bEnd, - bool bCompareFFRTPname) +static std::string search_resrename(gmx::ArrayRef 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)) || diff --git a/src/gromacs/gmxpreprocess/readir.cpp b/src/gromacs/gmxpreprocess/readir.cpp index 88a5b4473a..e34c7b4990 100644 --- a/src/gromacs/gmxpreprocess/readir.cpp +++ b/src/gromacs/gmxpreprocess/readir.cpp @@ -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]) { diff --git a/src/gromacs/gmxpreprocess/toppush.cpp b/src/gromacs/gmxpreprocess/toppush.cpp index bd598b7b46..ff06eb8428 100644 --- a/src/gromacs/gmxpreprocess/toppush.cpp +++ b/src/gromacs/gmxpreprocess/toppush.cpp @@ -1520,7 +1520,7 @@ static bool findIfAllNBAtomsMatch(gmx::ArrayRef 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 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 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 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]) diff --git a/src/gromacs/gmxpreprocess/vsite_parm.cpp b/src/gromacs/gmxpreprocess/vsite_parm.cpp index b33fcf8f85..a54f64b0ff 100644 --- a/src/gromacs/gmxpreprocess/vsite_parm.cpp +++ b/src/gromacs/gmxpreprocess/vsite_parm.cpp @@ -1521,7 +1521,7 @@ void clean_vsite_bondeds(gmx::ArrayRef 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++) { diff --git a/src/gromacs/hardware/cpuinfo.cpp b/src/gromacs/hardware/cpuinfo.cpp index b5425e4b4d..037204b15e 100644 --- a/src/gromacs/hardware/cpuinfo.cpp +++ b/src/gromacs/hardware/cpuinfo.cpp @@ -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 +std::vector detectX86ApicIDs(bool gmx_unused haveX2Apic) { std::vector 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::map parseProcCpuInfo() { std::ifstream procCpuInfo("/proc/cpuinfo"); diff --git a/src/gromacs/hardware/hardwaretopology.cpp b/src/gromacs/hardware/hardwaretopology.cpp index c8a15545c8..0d800311ab 100644 --- a/src/gromacs/hardware/hardwaretopology.cpp +++ b/src/gromacs/hardware/hardwaretopology.cpp @@ -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 +std::vector 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()"); diff --git a/src/gromacs/math/gausstransform.cpp b/src/gromacs/math/gausstransform.cpp index 085dbf81ad..c3b069c13d 100644 --- a/src/gromacs/math/gausstransform.cpp +++ b/src/gromacs/math/gausstransform.cpp @@ -247,7 +247,7 @@ mdspan OuterProductEvaluator::operator()(ArrayRef x, ArrayRef 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 ¢er, 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 GaussTransform3D::view() +basic_mdspan GaussTransform3D::view() { return impl_->data_.asConstView(); } diff --git a/src/gromacs/math/gausstransform.h b/src/gromacs/math/gausstransform.h index ef8546fde2..fd90c2a371 100644 --- a/src/gromacs/math/gausstransform.h +++ b/src/gromacs/math/gausstransform.h @@ -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 view(); + basic_mdspan view(); private: class Impl; diff --git a/src/gromacs/math/tests/functions.cpp b/src/gromacs/math/tests/functions.cpp index abe2d076b3..a0dcc01907 100644 --- a/src/gromacs/math/tests/functions.cpp +++ b/src/gromacs/math/tests/functions.cpp @@ -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 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)); } } diff --git a/src/gromacs/math/vec.h b/src/gromacs/math/vec.h index b5f4a959fe..0a522b47be 100644 --- a/src/gromacs/math/vec.h +++ b/src/gromacs/math/vec.h @@ -105,6 +105,8 @@ #include +#include + #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 T norm(T* v) {return ::norm(v); } -template T norm2(T* v) { return ::norm2(v); } +template std::remove_const_t +norm(T* v) +{ + return ::norm(v); +} +template std::remove_const_t +norm2(T* v) +{ + return ::norm2(v); +} + } // namespace gmx + /*! \} */ #endif diff --git a/src/gromacs/mdlib/calc_verletbuf.cpp b/src/gromacs/mdlib/calc_verletbuf.cpp index 9183b9c095..fc033fee5d 100644 --- a/src/gromacs/mdlib/calc_verletbuf.cpp +++ b/src/gromacs/mdlib/calc_verletbuf.cpp @@ -645,14 +645,14 @@ static real energyDrift(gmx::ArrayRef 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); } diff --git a/src/gromacs/mdlib/constr.cpp b/src/gromacs/mdlib/constr.cpp index 0101aa7d85..11c7bb7d6d 100644 --- a/src/gromacs/mdlib/constr.cpp +++ b/src/gromacs/mdlib/constr.cpp @@ -1170,7 +1170,7 @@ void Constraints::saveEdsamPointer(gmx_edsam * ed) impl_->ed = ed; } -const ArrayRef +ArrayRef Constraints::atom2constraints_moltype() const { return impl_->at2con_mt; diff --git a/src/gromacs/mdlib/constr.h b/src/gromacs/mdlib/constr.h index dac41fe3a5..452d2ac36d 100644 --- a/src/gromacs/mdlib/constr.h +++ b/src/gromacs/mdlib/constr.h @@ -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 atom2constraints_moltype() const; + ArrayRef atom2constraints_moltype() const; //! Getter for use by domain decomposition. ArrayRef < const std::vector < int>> atom2settle_moltype() const; diff --git a/src/gromacs/mdlib/mdebin_bar.cpp b/src/gromacs/mdlib/mdebin_bar.cpp index f733ae2ab0..f0d1651aa7 100644 --- a/src/gromacs/mdlib/mdebin_bar.cpp +++ b/src/gromacs/mdlib/mdebin_bar.cpp @@ -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(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++) diff --git a/src/gromacs/mdlib/qmmm.cpp b/src/gromacs/mdlib/qmmm.cpp index f2552fc671..146ab1ff35 100644 --- a/src/gromacs/mdlib/qmmm.cpp +++ b/src/gromacs/mdlib/qmmm.cpp @@ -404,7 +404,7 @@ std::vector qmmmAtomIndices(const t_inputrec &ir, const gmx_mtop_t &mtop) void removeQmmmAtomCharges(gmx_mtop_t *mtop, gmx::ArrayRef 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); diff --git a/src/gromacs/mdlib/sim_util.cpp b/src/gromacs/mdlib/sim_util.cpp index 5f4d39c5c6..6a0885f9a2 100644 --- a/src/gromacs/mdlib/sim_util.cpp +++ b/src/gromacs/mdlib/sim_util.cpp @@ -865,9 +865,9 @@ void do_force(FILE *fplog, gmx_wallcycle_t wcycle, const gmx_localtop_t *top, const matrix box, - gmx::ArrayRefWithPadding x, //NOLINT(performance-unnecessary-value-param) + gmx::ArrayRefWithPadding x, history_t *hist, - gmx::ArrayRefWithPadding force, //NOLINT(performance-unnecessary-value-param) + gmx::ArrayRefWithPadding force, tensor vir_force, const t_mdatoms *mdatoms, gmx_enerdata_t *enerd, diff --git a/src/gromacs/mdlib/tests/constr.cpp b/src/gromacs/mdlib/tests/constr.cpp index 1d6c85affd..5c79f2e23f 100644 --- a/src/gromacs/mdlib/tests/constr.cpp +++ b/src/gromacs/mdlib/tests/constr.cpp @@ -171,7 +171,7 @@ class ConstraintsTest : public ::testing::TestWithParammtop_.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); } diff --git a/src/gromacs/mdlib/tests/energyoutput.cpp b/src/gromacs/mdlib/tests/energyoutput.cpp index d1fe791568..a2f05a886a 100644 --- a/src/gromacs/mdlib/tests/energyoutput.cpp +++ b/src/gromacs/mdlib/tests/energyoutput.cpp @@ -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 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; diff --git a/src/gromacs/mdrun/minimize.cpp b/src/gromacs/mdrun/minimize.cpp index 76addf8c65..46afcb94ef 100644 --- a/src/gromacs/mdrun/minimize.cpp +++ b/src/gromacs/mdrun/minimize.cpp @@ -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) { diff --git a/src/gromacs/mdrun/runner.cpp b/src/gromacs/mdrun/runner.cpp index bc1a4bbc6e..4a7622c19b 100644 --- a/src/gromacs/mdrun/runner.cpp +++ b/src/gromacs/mdrun/runner.cpp @@ -1635,7 +1635,7 @@ Mdrunner::~Mdrunner() }; void Mdrunner::addPotential(std::shared_ptr 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 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) diff --git a/src/gromacs/mdrun/runner.h b/src/gromacs/mdrun/runner.h index 8b7d639a23..30b44147b7 100644 --- a/src/gromacs/mdrun/runner.h +++ b/src/gromacs/mdrun/runner.h @@ -166,7 +166,7 @@ class Mdrunner * rather than offering this public interface. */ void addPotential(std::shared_ptr restraint, - std::string name); + const std::string &name); //! Called when thread-MPI spawns threads. t_commrec *spawnThreads(int numThreadsToLaunch) const; diff --git a/src/gromacs/nbnxm/atomdata.cpp b/src/gromacs/nbnxm/atomdata.cpp index 41caa8d4b2..e78a65945e 100644 --- a/src/gromacs/nbnxm/atomdata.cpp +++ b/src/gromacs/nbnxm/atomdata.cpp @@ -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)) { diff --git a/src/gromacs/nbnxm/grid.cpp b/src/gromacs/nbnxm/grid.cpp index fbc52c4bd8..a3c4b9d59c 100644 --- a/src/gromacs/nbnxm/grid.cpp +++ b/src/gromacs/nbnxm/grid.cpp @@ -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(numAtoms)/(size[XX]*size[YY]*size[ZZ]); } void Grid::setDimensions(const int ddZone, diff --git a/src/gromacs/nbnxm/gridset.h b/src/gromacs/nbnxm/gridset.h index 436438196e..38d9650e4f 100644 --- a/src/gromacs/nbnxm/gridset.h +++ b/src/gromacs/nbnxm/gridset.h @@ -122,7 +122,7 @@ class GridSet nbnxn_atomdata_t *nbat); //! Returns the domain setup - const DomainSetup domainSetup() const + DomainSetup domainSetup() const { return domainSetup_; } diff --git a/src/gromacs/nbnxm/kerneldispatch.cpp b/src/gromacs/nbnxm/kerneldispatch.cpp index e02b649739..c608a660c2 100644 --- a/src/gromacs/nbnxm/kerneldispatch.cpp +++ b/src/gromacs/nbnxm/kerneldispatch.cpp @@ -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 { diff --git a/src/gromacs/nbnxm/kernels_reference/kernel_gpu_ref.cpp b/src/gromacs/nbnxm/kernels_reference/kernel_gpu_ref.cpp index a23bcc6c14..91bad8a61a 100644 --- a/src/gromacs/nbnxm/kernels_reference/kernel_gpu_ref.cpp +++ b/src/gromacs/nbnxm/kernels_reference/kernel_gpu_ref.cpp @@ -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((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(rt); - eps = rt - n0; + eps = rt - static_cast(n0); fexcl = (1 - eps)*Ftab[n0] + eps*Ftab[n0+1]; diff --git a/src/gromacs/nbnxm/kernels_reference/kernel_ref_inner.h b/src/gromacs/nbnxm/kernels_reference/kernel_ref_inner.h index 62e1356b3c..dc679f72f5 100644 --- a/src/gromacs/nbnxm/kernels_reference/kernel_ref_inner.h +++ b/src/gromacs/nbnxm/kernels_reference/kernel_ref_inner.h @@ -100,17 +100,15 @@ /* 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((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; @@ -306,7 +304,7 @@ #ifdef CALC_COUL_TAB rs = rsq*rinv*tab_coul_scale; ri = int(rs); - frac = rs - ri; + frac = rs - static_cast(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]; diff --git a/src/gromacs/nbnxm/kernels_simd_2xmm/kernel_inner.h b/src/gromacs/nbnxm/kernels_simd_2xmm/kernel_inner.h index 38724cb2b5..d4a11e64d3 100644 --- a/src/gromacs/nbnxm/kernels_simd_2xmm/kernel_inner.h +++ b/src/gromacs/nbnxm/kernels_simd_2xmm/kernel_inner.h @@ -218,7 +218,7 @@ ajz = ajy + STRIDE; #ifdef CHECK_EXCLS - gmx_load_simd_2xnn_interactions(l_cj[cjind].excl, + gmx_load_simd_2xnn_interactions(static_cast(l_cj[cjind].excl), filter_S0, filter_S2, &interact_S0, &interact_S2); #endif /* CHECK_EXCLS */ diff --git a/src/gromacs/nbnxm/kernels_simd_2xmm/kernel_outer.h b/src/gromacs/nbnxm/kernels_simd_2xmm/kernel_outer.h index f2d777c402..5fda72098b 100644 --- a/src/gromacs/nbnxm/kernels_simd_2xmm/kernel_outer.h +++ b/src/gromacs/nbnxm/kernels_simd_2xmm/kernel_outer.h @@ -229,7 +229,7 @@ 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 diff --git a/src/gromacs/nbnxm/kernels_simd_4xm/kernel_inner.h b/src/gromacs/nbnxm/kernels_simd_4xm/kernel_inner.h index 8b84291627..11867ab8a3 100644 --- a/src/gromacs/nbnxm/kernels_simd_4xm/kernel_inner.h +++ b/src/gromacs/nbnxm/kernels_simd_4xm/kernel_inner.h @@ -268,7 +268,7 @@ ajz = ajy + STRIDE; #ifdef CHECK_EXCLS - gmx_load_simd_4xn_interactions(l_cj[cjind].excl, + gmx_load_simd_4xn_interactions(static_cast(l_cj[cjind].excl), filter_S0, filter_S1, filter_S2, filter_S3, nbat->simdMasks.interaction_array.data(), diff --git a/src/gromacs/nbnxm/kernels_simd_4xm/kernel_outer.h b/src/gromacs/nbnxm/kernels_simd_4xm/kernel_outer.h index 0e7f68b53d..217985d56b 100644 --- a/src/gromacs/nbnxm/kernels_simd_4xm/kernel_outer.h +++ b/src/gromacs/nbnxm/kernels_simd_4xm/kernel_outer.h @@ -247,7 +247,7 @@ 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 diff --git a/src/gromacs/nbnxm/pairlist.cpp b/src/gromacs/nbnxm/pairlist.cpp index 6059f15766..296db78c92 100644 --- a/src/gromacs/nbnxm/pairlist.cpp +++ b/src/gromacs/nbnxm/pairlist.cpp @@ -2693,12 +2693,10 @@ static void combine_nblists(gmx::ArrayRef 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 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(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(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(bz1_frac*(columnEnd - columnStart)); + int midCell = columnStart + static_cast(bz1_frac*static_cast(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 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((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; diff --git a/src/gromacs/nbnxm/pairlistsets.h b/src/gromacs/nbnxm/pairlistsets.h index 41e8dc25b5..2cf5c41cf9 100644 --- a/src/gromacs/nbnxm/pairlistsets.h +++ b/src/gromacs/nbnxm/pairlistsets.h @@ -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(step - outerListCreationStep_); } //! Returns whether step is a dynamic list pruning step, for CPU lists diff --git a/src/gromacs/random/tabulatednormaldistribution.h b/src/gromacs/random/tabulatednormaldistribution.h index e87cc48626..f1abfe65f7 100644 --- a/src/gromacs/random/tabulatednormaldistribution.h +++ b/src/gromacs/random/tabulatednormaldistribution.h @@ -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 makeTable() { diff --git a/src/gromacs/restraint/manager.cpp b/src/gromacs/restraint/manager.cpp index 780326ebc2..e80182c990 100644 --- a/src/gromacs/restraint/manager.cpp +++ b/src/gromacs/restraint/manager.cpp @@ -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 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 > RestraintManager::getRestraints() const diff --git a/src/gromacs/restraint/manager.h b/src/gromacs/restraint/manager.h index 98c719fe02..30b6bab373 100644 --- a/src/gromacs/restraint/manager.h +++ b/src/gromacs/restraint/manager.h @@ -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 restraint, - std::string name); + const std::string &name); /*! * \brief Get a copy of the current set of restraints to be applied. diff --git a/src/gromacs/selection/indexutil.cpp b/src/gromacs/selection/indexutil.cpp index 23911799c2..1c3c27a0d3 100644 --- a/src/gromacs/selection/indexutil.cpp +++ b/src/gromacs/selection/indexutil.cpp @@ -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) { diff --git a/src/gromacs/simd/simd.h b/src/gromacs/simd/simd.h index 49549d523d..d7e6320f1f 100644 --- a/src/gromacs/simd/simd.h +++ b/src/gromacs/simd/simd.h @@ -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 {}; diff --git a/src/gromacs/topology/atomprop.cpp b/src/gromacs/topology/atomprop.cpp index 16bec32ef9..4333fa7677 100644 --- a/src/gromacs/topology/atomprop.cpp +++ b/src/gromacs/topology/atomprop.cpp @@ -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)) { diff --git a/src/gromacs/topology/atomprop.h b/src/gromacs/topology/atomprop.h index 32cd835a39..267979c545 100644 --- a/src/gromacs/topology/atomprop.h +++ b/src/gromacs/topology/atomprop.h @@ -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. * diff --git a/src/gromacs/topology/block.h b/src/gromacs/topology/block.h index f047f66809..e39e0f72f4 100644 --- a/src/gromacs/topology/block.h +++ b/src/gromacs/topology/block.h @@ -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(index_.size() - 1); + return static_cast(index_.size()) - 1; } /*! \brief Returns the size of the block with index \p blockIndex */ diff --git a/src/gromacs/topology/forcefieldparameters.cpp b/src/gromacs/topology/forcefieldparameters.cpp index 5c7b1cfeec..1935cd2f94 100644 --- a/src/gromacs/topology/forcefieldparameters.cpp +++ b/src/gromacs/topology/forcefieldparameters.cpp @@ -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++) { diff --git a/src/gromacs/topology/idef.h b/src/gromacs/topology/idef.h index fa0a06ae04..1cf3c8d374 100644 --- a/src/gromacs/topology/idef.h +++ b/src/gromacs/topology/idef.h @@ -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 +static inline std::vector extractILists(const InteractionLists &ilists, int flags) { diff --git a/src/gromacs/topology/index.cpp b/src/gromacs/topology/index.cpp index f36af6a649..a0382f3da5 100644 --- a/src/gromacs/topology/index.cpp +++ b/src/gromacs/topology/index.cpp @@ -120,7 +120,7 @@ void add_grp(t_blocka *b, char ***gnames, gmx::ArrayRef 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 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) diff --git a/src/gromacs/topology/residuetypes.cpp b/src/gromacs/topology/residuetypes.cpp index 3d6824754f..8387f8fe33 100644 --- a/src/gromacs/topology/residuetypes.cpp +++ b/src/gromacs/topology/residuetypes.cpp @@ -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)) { diff --git a/src/gromacs/topology/residuetypes.h b/src/gromacs/topology/residuetypes.h index b53defa676..afadef8610 100644 --- a/src/gromacs/topology/residuetypes.h +++ b/src/gromacs/topology/residuetypes.h @@ -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" * diff --git a/src/gromacs/topology/tests/exclusionblocks.cpp b/src/gromacs/topology/tests/exclusionblocks.cpp index 1bc41d82de..2fa0d6b92a 100644 --- a/src/gromacs/topology/tests/exclusionblocks.cpp +++ b/src/gromacs/topology/tests/exclusionblocks.cpp @@ -59,13 +59,13 @@ namespace { //! Add a new group to t_blocka -void addGroupToBlocka(t_blocka *b, gmx::ArrayRef index) +void addGroupToBlocka(t_blocka *b, gmx::ArrayRef 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 index) //! Fill ExclusionBlock with data. int fillExclusionBlock(gmx::ArrayRef 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 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 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++) diff --git a/src/gromacs/topology/topology.cpp b/src/gromacs/topology/topology.cpp index d43ae865b6..baa0f5bf26 100644 --- a/src/gromacs/topology/topology.cpp +++ b/src/gromacs/topology/topology.cpp @@ -563,7 +563,7 @@ static void compareMoltypes(FILE *fp, gmx::ArrayRef mt1, gm static void compareMoletypeAB(FILE *fp, gmx::ArrayRef 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(group), j); + buf = gmx::formatString("grps[%d].name[%zd]", static_cast(group), j); cmp_str(fp, buf.c_str(), -1, *g0.groupNames[g0.groups[group][j]], *g1.groupNames[g1.groups[group][j]]); diff --git a/src/gromacs/trajectory/energyframe.cpp b/src/gromacs/trajectory/energyframe.cpp index 3ef6c4f70e..61f38ec827 100644 --- a/src/gromacs/trajectory/energyframe.cpp +++ b/src/gromacs/trajectory/energyframe.cpp @@ -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 indicesOfEnergyFields) + const std::map &indicesOfEnergyFields) : step_(enxframe.step), time_(enxframe.t) { for (auto &index : indicesOfEnergyFields) diff --git a/src/gromacs/trajectory/energyframe.h b/src/gromacs/trajectory/energyframe.h index 0819a8eccf..d99153763b 100644 --- a/src/gromacs/trajectory/energyframe.h +++ b/src/gromacs/trajectory/energyframe.h @@ -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 indicesOfEnergyFields); + const std::map &indicesOfEnergyFields); /*! \brief Return string that helps users identify this frame, containing time and step number. * * \throws std::bad_alloc when out of memory */ diff --git a/src/gromacs/utility/binaryinformation.cpp b/src/gromacs/utility/binaryinformation.cpp index f740535268..03238a2bce 100644 --- a/src/gromacs/utility/binaryinformation.cpp +++ b/src/gromacs/utility/binaryinformation.cpp @@ -68,6 +68,7 @@ #include #include +#include #include /* 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(strlen(Contributors[i])) + offset < asize(buf), + const int width = 18; + std::array buf; + const int offset = centeringOffset(width, strlen(Contributors[i])); + GMX_RELEASE_ASSERT(static_cast(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(); } diff --git a/src/gromacs/utility/cstringutil.cpp b/src/gromacs/utility/cstringutil.cpp index e9deb399b0..730aaf092d 100644 --- a/src/gromacs/utility/cstringutil.cpp +++ b/src/gromacs/utility/cstringutil.cpp @@ -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; } diff --git a/src/gromacs/utility/fatalerror.cpp b/src/gromacs/utility/fatalerror.cpp index 37234b54b4..a4606ffd30 100644 --- a/src/gromacs/utility/fatalerror.cpp +++ b/src/gromacs/utility/fatalerror.cpp @@ -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); } diff --git a/src/gromacs/utility/keyvaluetree.h b/src/gromacs/utility/keyvaluetree.h index 0ce225ea75..a308911797 100644 --- a/src/gromacs/utility/keyvaluetree.h +++ b/src/gromacs/utility/keyvaluetree.h @@ -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; diff --git a/src/gromacs/utility/strdb.cpp b/src/gromacs/utility/strdb.cpp index 233deecc70..f46b7b30d4 100644 --- a/src/gromacs/utility/strdb.cpp +++ b/src/gromacs/utility/strdb.cpp @@ -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) diff --git a/src/testutils/testasserts.cpp b/src/testutils/testasserts.cpp index f68d401ffe..0f1e7064d6 100644 --- a/src/testutils/testasserts.cpp +++ b/src/testutils/testasserts.cpp @@ -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(absoluteTolerance), absoluteTolerance, + static_cast(tolerance), tolerance, UINT64_MAX, UINT64_MAX, false); } diff --git a/src/testutils/testasserts.h b/src/testutils/testasserts.h index c4a2cce9ec..2848284498 100644 --- a/src/testutils/testasserts.h +++ b/src/testutils/testasserts.h @@ -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); } diff --git a/src/testutils/textblockmatchers.cpp b/src/testutils/textblockmatchers.cpp index 0dfec75d9f..159b75c93b 100644 --- a/src/testutils/textblockmatchers.cpp +++ b/src/testutils/textblockmatchers.cpp @@ -148,7 +148,7 @@ TextBlockMatcherPointer NoTextMatch::createMatcher() const } FilteringExactTextMatch::FilteringExactTextMatch(std::vector linesToSkip) - : linesToSkip_(linesToSkip) + : linesToSkip_(std::move(linesToSkip)) {} void FilteringExactTextMatch::addRegexToSkip(const std::string &lineToSkip) -- 2.22.0