inconvenient for a general user) can be added to the set controlled by this
variable.
+.. cmake:: GMX_CLANG_TIDY
+
+ `clang-tidy <http://releases.llvm.org/8.0.0/tools/clang/tools/extra/docs/clang-tidy/index.html>`_
+ is used for static code analysis and (some) automated fixing of issues detected. clang-tidy is easy to install. It is contained in
+ the llvm binary `package <http://releases.llvm.org/download.html#8.0.0>`_. Only
+ version 8.0.* with libstdc++<7 or libc++ is supported. Others might miss tests or give false positives.
+ It is run automatically on Jenkins for each commit. Many checks have fixes which can automatically be
+ applied. To run it, the build has to be configured with
+ ``cmake -DGMX_CLANG_TIDY=ON -DGMX_OPENMP=no -DCMAKE_BUILD_TYPE=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS=on``.
+ Any ``CMAKE_BUILD_TYPE`` which enables asserts (e.g. ASAN) works. Such a configured build will
+ run both the compiler as well as clang-tidy when building. The name of the clang-tidy executable is set with
+ ``-DCLANG_TIDY=...``, and the full path to it can be set with ``-DCLANG_TIDY_EXE=...``.
+ To apply the automatic fixes to the issue identified clang-tidy should be run seperately (running clang-tidy
+ with ``-fix-errors`` as part of the build can corrupt header files). To fix a specific file run
+ ``clang-tidy -fix-errors -header-filter '.*' {file}``, to fix all files in parallel
+ ``run-clang-tidy.py -fix -header-filter '.*' '(?<!/selection/parser\.cpp|selection/scanner\.cpp)$'``,
+ and to fix all modified files ``run-clang-tidy.py -fix -header-filter '.*' $(git diff HEAD --name-only)``.
+ The run-clang-tidy.py script is in the
+ ``share/clang/`` subfolder of the llvm distribution. ``clang-tidy`` has to be able to find the
+ ``compile_commands.json`` file. Either run from the build folder or add a symlink to the source folder.
+ :cmake:`GMX_ENABLE_CCACHE` does not work with clang-tidy.
+
Variables affecting special targets
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
for each commit.
Details can be found on a separate page on :doc:`testutils`.
-regression tests
-
-clang-tidy
- `clang-tidy <http://releases.llvm.org/7.0.0/tools/clang/tools/extra/docs/clang-tidy/index.html>`_
- is used for static code analysis. clang-tidy is easy to install. It is contained in
- the llvm binary `package <http://releases.llvm.org/download.html#6.0.0>`_. Only
- version 7.0.* with libstdc++<7 or libc++ is supported. Others might miss tests or give false positives.
- It is run automatically on Jenkins for each commit. Many checks have fixes which can automatically be
- applied. To run it, the build has to be configured with
- ``cmake -DGMX_CLANG_TIDY=ON -DGMX_OPENMP=no -DCMAKE_BUILD_TYPE=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS=on``.
- Any ``CMAKE_BUILD_TYPE`` which enables asserts (e.g. ASAN) works. Such a configured build will
- run both the compiler as well as clang-tidy when building. The name of the clang-tidy executable is set with
-``-DCLANG_TIDY=...``, and the full path to it can be set with ``-DCLANG_TIDY_EXE=...``.
- To apply the automatic fixes to the issue identified clang-tidy should be run sepereately (running clang-tidy
- with ``-fix`` as part of the build can corrupt header files). To fix a specific file run
- ``clang-tidy -fix -header-filter '.*' {file}``, to fix all files in parallel
- ``run-clang-tidy.py -fix -header-filter '.*' '(?<!/selection/parser\.cpp|selection/scanner\.cpp)$'``,
- and to fix all modified files ``run-clang-tidy.py -fix -header-filter '.*' $(git diff HEAD --name-only)``.
- The run-clang-tidy.py script is in the
- ``share/clang/`` subfolder of the llvm distribution. ``clang-tidy`` has to be able to find the
- ``compile_commands.json`` file. Eithe run from the build folder or add a symlink to the source folder.
-
clang static analyzer
coverage
+regression tests
+
.. _dev-formatting-tools:
Code formatting and style
+# List of rationales for check suppressions (where known).
+# This have to precede the list because inline comments are not
+# supported by clang-tidy.
+#
+# -cppcoreguidelines-non-private-member-variables-in-classes,
+# -misc-non-private-member-variables-in-classes,
+# We intend a gradual transition to conform to this guideline, but it
+# is not practical to implement yet.
+#
+# -readability-isolate-declaration,
+# Declarations like "int a, b;" are readable. Some forms are not, and
+# those might reasonably be suggested against during code review.
+#
+# -cppcoreguidelines-avoid-c-arrays,
+# C arrays are still necessary in many places with legacy code
+#
+# -cppcoreguidelines-avoid-magic-numbers,
+# -readability-magic-numbers,
+# We have many legitimate use cases for magic numbers
+#
+# -cppcoreguidelines-macro-usage,
+# We do use too many macros, and we should fix many of them, but there
+# is no reasonable way to suppress the check e.g. in src/config.h and
+# configuring the build is a major legitimate use of macros.
+#
+# -cppcoreguidelines-narrowing-conversions,
+# -bugprone-narrowing-conversions
+# We have many cases where int is converted to float and we don't care
+# enough about such potential loss of precision to use explicit casts
+# in large numbers of places.
+
Checks: clang-diagnostic-*,-clang-analyzer-*,-clang-analyzer-security.insecureAPI.strcpy,
bugprone-*,misc-*,readability-*,performance-*,mpi-*,
-readability-inconsistent-declaration-parameter-name,
-cppcoreguidelines-no-malloc,-cppcoreguidelines-special-member-functions,
-cppcoreguidelines-avoid-goto,
google-*,-google-build-using-namespace,-google-explicit-constructor,
- -google-readability-function-size,-google-readability-todo,-google-runtime-int
+ -google-readability-function-size,-google-readability-todo,-google-runtime-int,
+ -cppcoreguidelines-non-private-member-variables-in-classes,
+ -misc-non-private-member-variables-in-classes,
+ -readability-isolate-declaration,
+ -cppcoreguidelines-avoid-c-arrays,
+ -cppcoreguidelines-avoid-magic-numbers,
+ -readability-magic-numbers,
+ -cppcoreguidelines-macro-usage,
+ -cppcoreguidelines-narrowing-conversions,
+ -bugprone-narrowing-conversions
HeaderFilterRegex: .*
CheckOptions:
- key: cppcoreguidelines-special-member-functions.AllowSoleDefaultDtor
value: 1
- key: bugprone-dangling-handle.HandleClasses
value: std::basic_string_view; nonstd::sv_lite::basic_string_view
+# Permit passing shard pointers by value for sink parameters
+ - key: performance-unnecessary-copy-initialization.AllowedTypes
+ value: shared_ptr
+ - key: performance-unnecessary-value-param.AllowedTypes
+ value: shared_ptr
-cppcoreguidelines-avoid-goto,
google-*,-google-build-using-namespace,-google-explicit-constructor,
-google-readability-todo,
- -google-runtime-int
+ -google-runtime-int,
+ -cppcoreguidelines-non-private-member-variables-in-classes,
+ -misc-non-private-member-variables-in-classes,
+ -readability-isolate-declaration,
+ -cppcoreguidelines-avoid-c-arrays,
+ -cppcoreguidelines-avoid-magic-numbers,
+ -readability-magic-numbers,
+ -cppcoreguidelines-macro-usage,
+ -cppcoreguidelines-narrowing-conversions,
+ -bugprone-narrowing-conversions
HeaderFilterRegex: .*
CheckOptions:
- key: cppcoreguidelines-special-member-functions.AllowSoleDefaultDtor
value: 1
- key: bugprone-dangling-handle.HandleClasses
value: std::basic_string_view; nonstd::sv_lite::basic_string_view
+# Permit passing shard pointers by value for sink parameters
+ - key: performance-unnecessary-copy-initialization.AllowedTypes
+ value: shared_ptr
+ - key: performance-unnecessary-value-param.AllowedTypes
+ value: shared_ptr
-Checks: -*
+# We don't want any checks at all for external code, but that leads to
+# clang-tidy complaining that it is being run with no checks. So we
+# let it use a single check that is irrelevant for GROMACS.
+Checks: -clang-analyzer*,zircon-temporary-objects
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2010,2011,2012,2013,2014,2015,2018, by the GROMACS development team, led by
+ * Copyright (c) 2010,2011,2012,2013,2014,2015,2018,2019, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
void
-AbstractAnalysisData::addModule(AnalysisDataModulePointer module)
+AbstractAnalysisData::addModule(const AnalysisDataModulePointer &module)
{
- impl_->modules_.addModule(this, std::move(module));
+ impl_->modules_.addModule(this, module);
}
void
AbstractAnalysisData::addColumnModule(int col, int span,
- AnalysisDataModulePointer module)
+ const AnalysisDataModulePointer &module)
{
GMX_RELEASE_ASSERT(col >= 0 && span >= 1,
"Invalid columns specified for a column module");
std::shared_ptr<AnalysisDataProxy> proxy(
new AnalysisDataProxy(col, span, this));
- proxy->addModule(std::move(module));
+ proxy->addModule(module);
addModule(proxy);
}
/*
* 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.
* 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.
*
*
* \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.
*
/*
* 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.
}
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
/*
* 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.
*
* \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.
*
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);
* \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,
/*
* 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.
/* Make the hash table a power of 2 and at least 1.5 * #elements */
int tableSize = 64;
while (tableSize <= INT_MAX/2 &&
- numElementsEstimate*c_relTableSizeSetMin > tableSize)
+ static_cast<float>(numElementsEstimate)*c_relTableSizeSetMin > tableSize)
{
tableSize *= 2;
}
{
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];
{
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];
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)
{
* 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.
}
*pfft = nullptr;
- if ( (fft = (gmx_many_fft_t)malloc(sizeof(struct gmx_many_fft))) == nullptr)
+ if ( (fft = static_cast<gmx_many_fft_t>(malloc(sizeof(struct gmx_many_fft)))) == nullptr)
{
return ENOMEM;
}
fft->howmany = howmany;
fft->dist = 2*nx;
- *pfft = (gmx_fft_t)fft;
+ *pfft = reinterpret_cast<gmx_fft_t>(fft);
return 0;
}
}
*pfft = nullptr;
- if ( (fft = (gmx_many_fft_t)malloc(sizeof(struct gmx_many_fft))) == nullptr)
+ if ( (fft = static_cast<gmx_many_fft_t>(malloc(sizeof(struct gmx_many_fft)))) == nullptr)
{
return ENOMEM;
}
fft->howmany = howmany;
fft->dist = 2*(nx/2+1);
- *pfft = (gmx_fft_t)fft;
+ *pfft = reinterpret_cast<gmx_fft_t>(fft);
return 0;
}
void * in_data,
void * out_data)
{
- gmx_many_fft_t mfft = (gmx_many_fft_t)fft;
+ gmx_many_fft_t mfft = reinterpret_cast<gmx_many_fft_t>(fft);
int i, ret;
for (i = 0; i < mfft->howmany; i++)
{
{
return ret;
}
- in_data = (real*)in_data+mfft->dist;
- out_data = (real*)out_data+mfft->dist;
+ in_data = static_cast<real*>(in_data)+mfft->dist;
+ out_data = static_cast<real*>(out_data)+mfft->dist;
}
return 0;
}
void * in_data,
void * out_data)
{
- gmx_many_fft_t mfft = (gmx_many_fft_t)fft;
+ gmx_many_fft_t mfft = reinterpret_cast<gmx_many_fft_t>(fft);
int i, ret;
for (i = 0; i < mfft->howmany; i++)
{
{
return ret;
}
- in_data = (real*)in_data+mfft->dist;
- out_data = (real*)out_data+mfft->dist;
+ in_data = static_cast<real*>(in_data)+mfft->dist;
+ out_data = static_cast<real*>(out_data)+mfft->dist;
}
return 0;
}
void
gmx_many_fft_destroy(gmx_fft_t fft)
{
- gmx_many_fft_t mfft = (gmx_many_fft_t)fft;
+ gmx_many_fft_t mfft = reinterpret_cast<gmx_many_fft_t>(fft);
if (mfft != nullptr)
{
if (mfft->fft != nullptr)
* 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.
}
*pfft = nullptr;
- if ( (fft = (struct gmx_fft *)malloc(sizeof(struct gmx_fft))) == nullptr)
+ if ( (fft = static_cast<struct gmx_fft *>(malloc(sizeof(struct gmx_fft)))) == nullptr)
{
return ENOMEM;
}
fft->n = nx;
/* Need 4*n storage for 1D complex FFT */
- if ( (fft->work = (real *)malloc(sizeof(real)*(4*nx))) == nullptr)
+ if ( (fft->work = static_cast<real *>(malloc(sizeof(real)*(4*nx)))) == nullptr)
{
free(fft);
return ENOMEM;
}
*pfft = nullptr;
- if ( (fft = (struct gmx_fft *)malloc(sizeof(struct gmx_fft))) == nullptr)
+ if ( (fft = static_cast<struct gmx_fft *>(malloc(sizeof(struct gmx_fft)))) == nullptr)
{
return ENOMEM;
}
fft->n = nx;
/* Need 2*n storage for 1D real FFT */
- if ((fft->work = (real *)malloc(sizeof(real)*(2*nx))) == nullptr)
+ if ((fft->work = static_cast<real *>(malloc(sizeof(real)*(2*nx)))) == nullptr)
{
free(fft);
return ENOMEM;
*pfft = nullptr;
/* Create the X transform */
- if ( (fft = (struct gmx_fft *)malloc(sizeof(struct gmx_fft))) == nullptr)
+ if ( (fft = static_cast<struct gmx_fft *>(malloc(sizeof(struct gmx_fft)))) == nullptr)
{
return ENOMEM;
}
/* Need 4*nx storage for 1D complex FFT, and another
* 2*nx*nyc elements for complex-to-real storage in our high-level routine.
*/
- if ( (fft->work = (real *)malloc(sizeof(real)*(4*nx+2*nx*nyc))) == nullptr)
+ if ( (fft->work = static_cast<real *>(malloc(sizeof(real)*(4*nx+2*nx*nyc)))) == nullptr)
{
free(fft);
return ENOMEM;
if (n == 1)
{
- p1 = (real *)in_data;
- p2 = (real *)out_data;
+ p1 = static_cast<real *>(in_data);
+ p2 = static_cast<real *>(out_data);
p2[0] = p1[0];
p2[1] = p1[1];
}
*/
if (in_data != out_data)
{
- p1 = (real *)in_data;
- p2 = (real *)out_data;
+ p1 = static_cast<real *>(in_data);
+ p2 = static_cast<real *>(out_data);
/* n complex = 2*n real elements */
for (i = 0; i < 2*n; i++)
if (dir == GMX_FFT_FORWARD)
{
- fftpack_cfftf1(n, (real *)out_data, fft->work+2*n, fft->work, fft->ifac, -1);
+ fftpack_cfftf1(n, static_cast<real *>(out_data), fft->work+2*n, fft->work, fft->ifac, -1);
}
else if (dir == GMX_FFT_BACKWARD)
{
- fftpack_cfftf1(n, (real *)out_data, fft->work+2*n, fft->work, fft->ifac, 1);
+ fftpack_cfftf1(n, static_cast<real *>(out_data), fft->work+2*n, fft->work, fft->ifac, 1);
}
else
{
if (n == 1)
{
- p1 = (real *)in_data;
- p2 = (real *)out_data;
+ p1 = static_cast<real *>(in_data);
+ p2 = static_cast<real *>(out_data);
p2[0] = p1[0];
if (dir == GMX_FFT_REAL_TO_COMPLEX)
{
*/
if (in_data != out_data)
{
- p1 = (real *)in_data;
- p2 = (real *)out_data;
+ p1 = static_cast<real *>(in_data);
+ p2 = static_cast<real *>(out_data);
for (i = 0; i < 2*(n/2+1); i++)
{
/* Elements 0 .. n-1 in work are used for ffac values,
* Elements n .. 2*n-1 are internal FFTPACK work space.
*/
- fftpack_rfftf1(n, (real *)out_data, fft->work+n, fft->work, fft->ifac);
+ fftpack_rfftf1(n, static_cast<real *>(out_data), fft->work+n, fft->work, fft->ifac);
/*
* FFTPACK has a slightly more compact storage than we, time to
* convert it: ove most of the array one step up to make room for
* zero imaginary parts.
*/
- p2 = (real *)out_data;
+ p2 = static_cast<real *>(out_data);
for (i = n-1; i > 0; i--)
{
p2[i+1] = p2[i];
* is more compact than ours (2 reals) it will fit, so compact it
* and copy on-the-fly to the output array.
*/
- p1 = (real *) in_data;
- p2 = (real *)out_data;
+ p1 = static_cast<real *>(in_data);
+ p2 = static_cast<real *>(out_data);
p2[0] = p1[0];
for (i = 1; i < n; i++)
{
p2[i] = p1[i+1];
}
- fftpack_rfftb1(n, (real *)out_data, fft->work+n, fft->work, fft->ifac);
+ fftpack_rfftb1(n, static_cast<real *>(out_data), fft->work+n, fft->work, fft->ifac);
}
else
{
*/
if (in_data != out_data)
{
- p1 = (real *)in_data;
- p2 = (real *)out_data;
+ p1 = static_cast<real *>(in_data);
+ p2 = static_cast<real *>(out_data);
for (i = 0; i < nx; i++)
{
/* Output (pointed to by data) is now in padded format.
* Pack it into out_data if we were doing an out-of-place transform.
*/
- p1 = (real *)data;
- p2 = (real *)out_data;
+ p1 = reinterpret_cast<real *>(data);
+ p2 = static_cast<real *>(out_data);
for (i = 0; i < nx; i++)
{
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];
{
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);
{
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);
*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)
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]);
#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);
}
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);
}
}
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);
}
}
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);
}
*
* 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.
#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[])
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[] =
/* Find vectors and phases */
- /* first find number of args in string */
- nmodes = gmx::countWords(eignrvec);
-
- snew(imodes, nmodes);
- p = eignrvec;
- for (i = 0; i < nmodes; i++)
+ std::vector<int> imodes;
+ for (const auto &imodeString : gmx::splitString(eignrvec))
{
- /* C indices start on 0 */
- imodes[i] = std::strtol(p, &pe, 10)-1;
- p = pe;
+ imodes.emplace_back(gmx::fromStdString<int>(imodeString));
}
+ int nmodes = gmx::ssize(imodes);
- /* Now read phases */
- nphases = gmx::countWords(phasevec);
-
- if (nphases > nmodes)
+ std::vector<real> phases;
+ phases.reserve(nmodes);
+ for (const auto &phaseString : gmx::splitString(phasevec))
{
- gmx_fatal(FARGS, "More phases than eigenvector indices specified.\n");
+ phases.emplace_back(gmx::fromStdString<int>(phaseString));
}
+ int nphases = gmx::ssize(phases);
- snew(phases, nmodes);
- p = phasevec;
-
- for (i = 0; i < nphases; i++)
+ if (nphases > nmodes)
{
- phases[i] = strtod(p, &pe);
- p = pe;
+ gmx_fatal(FARGS, "More phases than eigenvector indices specified.\n");
}
if (nmodes > nphases)
{
printf("Warning: Setting phase of last %d modes to zero...\n", nmodes-nphases);
- }
-
- for (i = nphases; i < nmodes; i++)
- {
- phases[i] = 0;
+ phases.resize(nmodes, 0);
}
atoms = &top.atoms;
for (i = 0; i < nframes; i++)
{
- fraction = static_cast<real>(i)/nframes;
+ real fraction = static_cast<real>(i)/static_cast<real>(nframes);
for (j = 0; j < natoms; j++)
{
copy_rvec(xav[j], xout[j]);
}
}
}
- write_trx(out, natoms, dummy, atoms, i, static_cast<real>(i)/nframes, box, xout, nullptr, nullptr);
+ write_trx(out, natoms, dummy, atoms, i, fraction, box, xout, nullptr, nullptr);
}
fprintf(stderr, "\n");
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];
sgmol[i] += cost2;
/* determine distribution */
- ibin = static_cast<int>(nsgbin * cost2);
+ ibin = static_cast<int>(static_cast<real>(nsgbin) * cost2);
if (ibin < nsgbin)
{
sgbin[ibin]++;
*skmean += skmol[i];
/* Compute sliced stuff */
- sl_index = static_cast<int>(std::round((1+x[i][slice_dim]/box[slice_dim][slice_dim])*nslice)) % nslice;
+ sl_index = static_cast<int>(std::round((1+x[i][slice_dim]/box[slice_dim][slice_dim])*static_cast<real>(nslice))) % nslice;
sgslice[sl_index] += sgmol[i];
skslice[sl_index] += skmol[i];
sl_count[sl_index]++;
} /* loop over entries in index file */
- *sgmean /= maxidx;
- *skmean /= maxidx;
+ *sgmean /= static_cast<real>(maxidx);
+ *skmean /= static_cast<real>(maxidx);
for (i = 0; (i < nslice); i++)
{
for (i = 0; (i < nslice); i++)
{
fprintf(fpsg, "%10g %10g\n", (i+0.5)*box[slice_dim][slice_dim]/nslice,
- sg_slice_tot[i]/nframes);
+ sg_slice_tot[i]/static_cast<real>(nframes));
fprintf(fpsk, "%10g %10g\n", (i+0.5)*box[slice_dim][slice_dim]/nslice,
- sk_slice_tot[i]/nframes);
+ sk_slice_tot[i]/static_cast<real>(nframes));
}
xvgrclose(fpsg);
xvgrclose(fpsk);
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*/
if (bSliced)
{
- *slWidth = box[axis][axis]/nslices;
+ *slWidth = box[axis][axis]/static_cast<real>(nslices);
fprintf(stderr, "Box divided in %d slices. Initial width of slice: %f\n",
nslices, *slWidth);
}
{
if (bSliced)
{
- *slWidth = box[axis][axis]/nslices;
+ *slWidth = box[axis][axis]/static_cast<real>(nslices);
}
teller++;
z1 = x1[a[index[i-1]+j]][axis];
z2 = x1[a[index[i+1]+j]][axis];
z_ave = 0.5 * (z1 + z2);
- slice = static_cast<int>((nslices*z_ave)/box[axis][axis]);
+ slice = static_cast<int>((static_cast<real>(nslices)*z_ave)/box[axis][axis]);
while (slice < 0)
{
- slice += nslices;
+ slice += static_cast<real>(nslices);
}
slice = slice % nslices;
for (m = 0; m < DIM; m++)
{
- (*order)[i][m] += (frameorder[m]/size);
+ (*order)[i][m] += (frameorder[m]/static_cast<real>(size));
}
if (!permolecule)
{
if (slCount[k]) /* if no elements, nothing has to be added */
{
- (*slOrder)[k][i] += slFrameorder[k]/slCount[k];
+ (*slOrder)[k][i] += slFrameorder[k]/static_cast<real>(slCount[k]);
slFrameorder[k] = 0; slCount[k] = 0;
}
}
if (bUnsat)
{
fprintf(stderr, "Average angle between double bond and normal: %f\n",
- 180*sdbangle/(nr_frames * size*M_PI));
+ 180*sdbangle/(nr_frames * static_cast<real>(size)*M_PI));
}
sfree(x0); /* free memory used by coordinate arrays */
{
S += slOrder[slice][atom];
}
- fprintf(slOrd, "%12g %12g\n", slice*slWidth, S/atom);
+ fprintf(slOrd, "%12g %12g\n", static_cast<real>(slice)*slWidth, S/static_cast<real>(atom));
}
}
*
* 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.
/*********** Start processing trajectory ***********/
do
{
- *slWidth = box[axis][axis]/(*nslices);
+ *slWidth = box[axis][axis]/static_cast<real>((*nslices));
teller++;
gmx_rmpbc(gpbc, natoms, box, x0);
{
/* get charge per volume */
(*slCharge)[n][i] = (*slCharge)[n][i] * (*nslices) /
- (nr_frames * box[axis][axis] * box[ax1][ax1] * box[ax2][ax2]);
+ (static_cast<real>(nr_frames) * box[axis][axis] * box[ax1][ax1] * box[ax2][ax2]);
}
}
/* Now we have charge densities */
*
* 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.
{
vec[m] += gmx::square(x[index[i]][m]);
}
- vec[m] = std::sqrt(vec[m] / isize);
+ vec[m] = std::sqrt(vec[m] / static_cast<real>(isize));
/* calculate scaling constants */
vec[m] = 1.0 / (std::sqrt(3.0) * vec[m]);
}
}
if (bFile2)
{
- rmsd_avg /= tel_mat*tel_mat2;
+ rmsd_avg /= static_cast<real>(tel_mat)*static_cast<real>(tel_mat2);
}
else
{
{
mx = gmx::roundToInt(std::log(static_cast<real>(mx))*delta_scalex);
}
- my = gmx::roundToInt(rmsd_mat[i][j]*delta_scaley*del_lev);
+ my = gmx::roundToInt(rmsd_mat[i][j]*delta_scaley*static_cast<real>(del_lev));
delta_tot[mx] += 1.0;
if ((rmsd_mat[i][j] >= 0) && (rmsd_mat[i][j] <= delta_maxy))
{
}
for (i = 0; i < del_lev+1; i++)
{
- del_yaxis[i] = delta_maxy*i/del_lev;
+ del_yaxis[i] = delta_maxy*static_cast<real>(i)/static_cast<real>(del_lev);
}
sprintf(buf, "%s %s vs. delta t", gn_rms[0], whatname[ewhat]);
fp = gmx_ffopen("delta.xpm", "w");
fp = xvgropen(opt2fn("-a", NFILE, fnm), buf, "Residue", buf2, oenv);
for (j = 0; (j < nrms); j++)
{
- fprintf(fp, "%10d %10g\n", j, rlstot/teller);
+ fprintf(fp, "%10d %10g\n", j, rlstot/static_cast<real>(teller));
}
xvgrclose(fp);
}
fp = xvgropen("aver.xvg", gn_rms[0], "Residue", whatxvglabel[ewhat], oenv);
for (j = 0; (j < irms[0]); j++)
{
- fprintf(fp, "%10d %10g\n", j, rlsnorm[j]/teller);
+ fprintf(fp, "%10d %10g\n", j, rlsnorm[j]/static_cast<real>(teller));
}
xvgrclose(fp);
}
*
* 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.
{
for (j = i+1; (j < nind); j++)
{
- temp1_3 = gmx::invcbrt(dtot1_3[i][j]/nframes);
- temp1_6 = gmx::invsixthroot(dtot1_6[i][j]/nframes);
+ temp1_3 = gmx::invcbrt(dtot1_3[i][j]/static_cast<real>(nframes));
+ temp1_6 = gmx::invsixthroot(dtot1_6[i][j]/static_cast<real>(nframes));
if (temp1_3 > *max1_3)
{
*max1_3 = temp1_3;
{
for (j = i+1; j < gnr; j++)
{
- noe[i][j].r_3 = gmx::invcbrt(noe[i][j].i_3/noe[i][j].nr);
- noe[i][j].r_6 = gmx::invsixthroot(noe[i][j].i_6/noe[i][j].nr);
+ noe[i][j].r_3 = gmx::invcbrt(noe[i][j].i_3/static_cast<real>(noe[i][j].nr));
+ noe[i][j].r_6 = gmx::invsixthroot(noe[i][j].i_6/static_cast<real>(noe[i][j].nr));
noe[j][i] = noe[i][j];
}
}
{
for (j = i+1; (j < nind); j++)
{
- mean = dtot[i][j]/nframes;
- mean2 = dtot2[i][j]/nframes;
+ mean = dtot[i][j]/static_cast<real>(nframes);
+ mean2 = dtot2[i][j]/static_cast<real>(nframes);
rms = std::sqrt(std::max(0.0_real, mean2-mean*mean));
rmsc = rms/mean;
if (mean > *meanmax)
*
* 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.
}
else
{
- dt = (t1 - t0)/(teller-1);
+ dt = (t1 - t0)/(static_cast<real>(teller-1));
mode = eacVector;
*
* 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.
fprintf(fp, "%g", i*rbin);
for (fbin = 0; fbin < nr; fbin++)
{
- fprintf(fp, " %g", static_cast<real>(pr[fbin][i])/(rcount[fbin]*isize*rbin*(i == 0 ? 0.5 : 1.0)));
+ fprintf(fp, " %g", static_cast<real>(pr[fbin][i]/(rcount[fbin]*isize*rbin*(i == 0 ? 0.5 : 1.0))));
}
fprintf(fp, "\n");
}
return res;
}
-static const std::string get_dummymass_name(gmx::ArrayRef<const VirtualSiteConfiguration> vsiteconflist,
- const std::string &atom, const std::string &nextheavy)
+static std::string get_dummymass_name(gmx::ArrayRef<const VirtualSiteConfiguration> vsiteconflist,
+ const std::string &atom, const std::string &nextheavy)
{
/* Return the dummy mass name if found, or NULL if not set in ddb database */
const auto found = std::find_if(vsiteconflist.begin(), vsiteconflist.end(),
/* 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);
}
}
}
-static const std::string search_resrename(gmx::ArrayRef<const RtpRename> rr,
- const char *name,
- bool bStart, bool bEnd,
- bool bCompareFFRTPname)
+static std::string search_resrename(gmx::ArrayRef<const RtpRename> rr,
+ const char *name,
+ bool bStart, bool bEnd,
+ bool bCompareFFRTPname)
{
auto found = std::find_if(rr.begin(), rr.end(), [&name, &bCompareFFRTPname](const auto &rename)
{ return ((!bCompareFFRTPname && (name == rename.gmx)) ||
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]);
* 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)
{
}
}
- 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;
}
*/
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])
{
}
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])
{
}
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])
{
}
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])
}
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])
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++)
{
* \returns A new std::vector of unsigned integer APIC IDs, one for each
* logical processor in the system.
*/
-const std::vector<unsigned int>
+std::vector<unsigned int>
detectX86ApicIDs(bool gmx_unused haveX2Apic)
{
std::vector<unsigned int> apicID;
* \return New map with the contents. If the file is not available, the returned
* map will be empty.
*/
-const std::map<std::string, std::string>
+std::map<std::string, std::string>
parseProcCpuInfo()
{
std::ifstream procCpuInfo("/proc/cpuinfo");
* descendants of the provided object. If no objects of this type
* were found, the vector will be empty.
*/
-const std::vector<const hwloc_obj*>
+std::vector<const hwloc_obj*>
getHwLocDescendantsByType(const hwloc_topology* topo, const hwloc_obj* obj, const hwloc_obj_type_t type)
{
GMX_RELEASE_ASSERT(obj, "NULL hwloc object provided to getHwLocDescendantsByType()");
OuterProductEvaluator::operator()(ArrayRef<const float> x, ArrayRef<const float> y)
{
data_.resize(ssize(x), ssize(y));
- for (int xIndex = 0; xIndex < ssize(x); ++xIndex)
+ for (gmx::index xIndex = 0; xIndex < ssize(x); ++xIndex)
{
const auto xValue = x[xIndex];
std::transform(std::begin(y), std::end(y), begin(data_.asView()[xIndex]),
{
const IVec begin = rangeBeginWithinLattice(center, range);
const IVec end = rangeEndWithinLattice(center, extent, range);
- return {begin, end};
+ return {
+ begin, end
+ };
}
/********************************************************************
* GaussianSpreadKernel
std::fill(begin(impl_->data_), end(impl_->data_), 0.);
}
-const basic_mdspan<const float, dynamicExtents3D> GaussTransform3D::view()
+basic_mdspan<const float, dynamicExtents3D> GaussTransform3D::view()
{
return impl_->data_.asConstView();
}
//! \brief Set all values on the lattice to zero.
void setZero();
//! Return a view on the spread lattice.
- const basic_mdspan<const float, dynamicExtents3D> view();
+ basic_mdspan<const float, dynamicExtents3D> view();
private:
class Impl;
/*
* 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.
gmx::test::TestReferenceChecker checker(data.rootChecker());
std::vector<float> result;
- for (float f : {-5, -4, -3, -2, -1, 1, 2, 3, 4})
+ for (int f : {-5, -4, -3, -2, -1, 1, 2, 3, 4})
{
result.push_back(gmx::invcbrt(f));
}
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));
}
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));
}
}
#include <cmath>
+#include <type_traits>
+
#include "gromacs/math/functions.h"
#include "gromacs/math/vectypes.h"
#include "gromacs/utility/real.h"
* \return magnitude or squared magnitude of vector
* \{
*/
-template<typename T> T norm(T* v) {return ::norm(v); }
-template <typename T> T norm2(T* v) { return ::norm2(v); }
+template<typename T> std::remove_const_t<T>
+norm(T* v)
+{
+ return ::norm(v);
+}
+template <typename T> std::remove_const_t<T>
+norm2(T* v)
+{
+ return ::norm2(v);
+}
+
} // namespace gmx
+
/*! \} */
#endif
// 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;
{
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);
}
impl_->ed = ed;
}
-const ArrayRef<const t_blocka>
+ArrayRef<const t_blocka>
Constraints::atom2constraints_moltype() const
{
return impl_->at2con_mt;
//! Links the essentialdynamics and constraint code.
void saveEdsamPointer(gmx_edsam *ed);
//! Getter for use by domain decomposition.
- const ArrayRef<const t_blocka> atom2constraints_moltype() const;
+ ArrayRef<const t_blocka> atom2constraints_moltype() const;
//! Getter for use by domain decomposition.
ArrayRef < const std::vector < int>> atom2settle_moltype() const;
GMX_RELEASE_ASSERT(deltaH, "Should have delta_h histograms in energy history");
GMX_RELEASE_ASSERT(deltaH->dh.size() == static_cast<size_t>(dhc->ndh), "energy history number of delta_h histograms should match inputrec's number");
- for (unsigned int i = 0; i < deltaH->dh.size(); i++)
+ for (gmx::index i = 0; i < gmx::ssize(deltaH->dh); i++)
{
dhc->dh[i].ndh = deltaH->dh[i].size();
for (unsigned int j = 0; j < dhc->dh[i].ndh; j++)
void removeQmmmAtomCharges(gmx_mtop_t *mtop, gmx::ArrayRef<const int> qmmmAtoms)
{
int molb = 0;
- for (int i = 0; i < qmmmAtoms.ssize(); i++)
+ for (gmx::index i = 0; i < qmmmAtoms.ssize(); i++)
{
int indexInMolecule;
mtopGetMolblockIndex(mtop, qmmmAtoms[i], &molb, nullptr, &indexInMolecule);
gmx_wallcycle_t wcycle,
const gmx_localtop_t *top,
const matrix box,
- gmx::ArrayRefWithPadding<gmx::RVec> x, //NOLINT(performance-unnecessary-value-param)
+ gmx::ArrayRefWithPadding<gmx::RVec> x,
history_t *hist,
- gmx::ArrayRefWithPadding<gmx::RVec> force, //NOLINT(performance-unnecessary-value-param)
+ gmx::ArrayRefWithPadding<gmx::RVec> force,
tensor vir_force,
const t_mdatoms *mdatoms,
gmx_enerdata_t *enerd,
{
// Test if all the constraints are satisfied
- for (unsigned c = 0; c < testData.constraints_.size()/3; c++)
+ for (index c = 0; c < ssize(testData.constraints_)/3; c++)
{
real r0 = testData.constraintsR0_.at(testData.constraints_.at(3*c));
int i = testData.constraints_.at(3*c + 1);
d0 = norm(xij0);
d1 = norm(xij1);
EXPECT_REAL_EQ_TOL(r0, d1, tolerance) << gmx::formatString(
- "rij = %f, which is not equal to r0 = %f for constraint #%u, between atoms %d and %d"
+ "rij = %f, which is not equal to r0 = %f for constraint #%zd, between atoms %d and %d"
" (before constraining rij was %f).", d1, r0, c, i, j, d0);
}
}
void checkConstrainsDirection(const ConstraintsTestData &testData, t_pbc pbc)
{
- for (unsigned c = 0; c < testData.constraints_.size()/3; c++)
+ for (index c = 0; c < ssize(testData.constraints_)/3; c++)
{
int i = testData.constraints_.at(3*c + 1);
int j = testData.constraints_.at(3*c + 2);
real dot = xij0.dot(xij1);
EXPECT_GE(dot, 0.0) << gmx::formatString(
- "The constraint %u changed direction. Constraining algorithm might have returned the wrong root "
+ "The constraint %zd changed direction. Constraining algorithm might have returned the wrong root "
"of the constraints equation.", c);
}
snew(idef_.il[F_CONSTR].iatoms, constraints.size());
int maxType = 0;
- for (unsigned i = 0; i < constraints.size(); i++)
+ for (index i = 0; i < ssize(constraints); i++)
{
if (i % 3 == 0)
{
idef_.il[F_CONSTR].iatoms[i] = constraints.at(i);
}
snew(idef_.iparams, maxType + 1);
- for (unsigned i = 0; i < constraints.size()/3; i++)
+ for (index i = 0; i < ssize(constraints)/3; i++)
{
idef_.iparams[constraints.at(3*i)].constr.dA = constraintsR0.at(constraints.at(3*i));
idef_.iparams[constraints.at(3*i)].constr.dB = constraintsR0.at(constraints.at(3*i));
// Constraints and their parameters (global topology)
InteractionList interactionList;
interactionList.iatoms.resize(constraints.size());
- for (unsigned i = 0; i < constraints.size(); i++)
- {
- interactionList.iatoms.at(i) = constraints.at(i);
- }
+ std::copy(constraints.begin(), constraints.end(), interactionList.iatoms.begin());
InteractionList interactionListEmpty;
interactionListEmpty.iatoms.resize(0);
maxwarn, &warncount_lincs);
EXPECT_TRUE(success) << "Test failed with a false return value in LINCS.";
EXPECT_EQ(warncount_lincs, 0) << "There were warnings in LINCS.";
- for (unsigned int i = 0; i < testData->mtop_.moltype.size(); i++)
+ for (auto &moltype : at2con_mt)
{
- sfree(at2con_mt.at(i).index);
- sfree(at2con_mt.at(i).a);
+ sfree(moltype.index);
+ sfree(moltype.a);
}
done_lincs(lincsd);
}
*/
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.
* 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.
*
}
// Kinetic energy and related data
- for (int i = 0; i < gmx::ssize(mtop_.groups.groups[SimulationAtomGroupType::TemperatureCoupling]); i++)
+ for (auto &tcstat : ekindata_.tcstat)
{
- ekindata_.tcstat[i].T = (*testValue += 0.1);
- ekindata_.tcstat[i].lambda = (*testValue += 0.1);
+ tcstat.T = (*testValue += 0.1);
+ tcstat.lambda = (*testValue += 0.1);
}
- for (int i = 0; i < gmx::ssize(mtop_.groups.groups[SimulationAtomGroupType::Acceleration]); i++)
+ for (auto &grpstat : ekindata_.grpstat)
{
- ekindata_.grpstat[i].u[XX] = (*testValue += 0.1);
- ekindata_.grpstat[i].u[YY] = (*testValue += 0.1);
- ekindata_.grpstat[i].u[ZZ] = (*testValue += 0.1);
+ grpstat.u[XX] = (*testValue += 0.1);
+ grpstat.u[YY] = (*testValue += 0.1);
+ grpstat.u[ZZ] = (*testValue += 0.1);
}
// This conditional is to check whether the ebin was allocated.
inputrec_.opts.ref_t[i] = (*testValue += 0.1);
}
- for (int k = 0; k < gmx::ssize(mtop_.groups.groups[SimulationAtomGroupType::TemperatureCoupling])*inputrec_.opts.nhchainlength; k++)
+ for (index k = 0; k < ssize(mtop_.groups.groups[SimulationAtomGroupType::TemperatureCoupling])*inputrec_.opts.nhchainlength; k++)
{
state_.nosehoover_xi[k] = (*testValue += 0.1);
state_.nosehoover_vxi[k] = (*testValue += 0.1);
// Perturb the atom positions, to appear like an
// "update," and where there is definitely constraining
// work to do.
- for (int i = 0; i < xPrime_.size()*DIM; ++i)
+ const real deltas[] = { 0.01, -0.01, +0.02, -0.02 };
+ int i = 0;
+ for (auto &xPrime : xPrime_)
{
- if (i % 4 == 0)
- {
- xPrime_[i / DIM][i % DIM] += 0.01;
- }
- else if (i % 4 == 1)
- {
- xPrime_[i / DIM][i % DIM] -= 0.01;
- }
- else if (i % 4 == 2)
- {
- xPrime_[i / DIM][i % DIM] += 0.02;
- }
- else if (i % 4 == 3)
- {
- xPrime_[i / DIM][i % DIM] -= 0.02;
- }
- v_[i / DIM][i % DIM] = 0.0;
+ xPrime[XX] += deltas[i % 4];
+ ++i;
+ xPrime[YY] += deltas[i % 4];
+ ++i;
+ xPrime[ZZ] += deltas[i % 4];
+ ++i;
}
+ std::fill(v_.begin(), v_.end(), RVec {0.0, 0.0, 0.0});
// Set up the topology.
const int settleType = 0;
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;
/* 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];
}
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;
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++)
}
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)
{
};
void Mdrunner::addPotential(std::shared_ptr<gmx::IRestraintPotential> puller,
- std::string name)
+ const std::string &name)
{
GMX_ASSERT(restraintManager_, "Mdrunner must have a restraint manager.");
// Not sure if this should be logged through the md logger or something else,
// When multiple restraints are used, it may be wasteful to register them separately.
// Maybe instead register an entire Restraint Manager as a force provider.
restraintManager_->addToSpec(std::move(puller),
- std::move(name));
+ name);
}
Mdrunner::Mdrunner(std::unique_ptr<MDModules> mdModules)
* rather than offering this public interface.
*/
void addPotential(std::shared_ptr<IRestraintPotential> restraint,
- std::string name);
+ const std::string &name);
//! Called when thread-MPI spawns threads.
t_commrec *spawnThreads(int numThreadsToLaunch) const;
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))
{
rvec_sub(upperCorner, lowerCorner, size);
- return numAtoms/(size[XX]*size[YY]*size[ZZ]);
+ return static_cast<real>(numAtoms)/(size[XX]*size[YY]*size[ZZ]);
}
void Grid::setDimensions(const int ddZone,
nbnxn_atomdata_t *nbat);
//! Returns the domain setup
- const DomainSetup domainSetup() const
+ DomainSetup domainSetup() const
{
return domainSetup_;
}
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.
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
{
}
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
{
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];
}
constexpr int clusterPerSplit = c_nbnxnGpuClusterSize/c_nbnxnGpuClusterpairSplit;
- int_bit = ((excl[jc/clusterPerSplit]->pair[(jc & (clusterPerSplit - 1))*c_clSize + ic]
- >> (jm*c_numClPerSupercl + im)) & 1);
+ int_bit = static_cast<real>((excl[jc/clusterPerSplit]->pair[(jc & (clusterPerSplit - 1))*c_clSize + ic]
+ >> (jm*c_numClPerSupercl + im)) & 1);
js = ja*nbat->xstride;
jfs = ja*nbat->fstride;
r = rsq*rinv;
rt = r*iconst->coulombEwaldTables->scale;
n0 = static_cast<int>(rt);
- eps = rt - n0;
+ eps = rt - static_cast<real>(n0);
fexcl = (1 - eps)*Ftab[n0] + eps*Ftab[n0+1];
/* A multiply mask used to zero an interaction
* when that interaction should be excluded
* (e.g. because of bonding). */
- int interact;
-
- interact = ((l_cj[cjind].excl>>(i*UNROLLI + j)) & 1);
+ real interact = static_cast<real>((l_cj[cjind].excl>>(i*UNROLLI + j)) & 1);
#ifndef EXCL_FORCES
skipmask = interact;
#else
skipmask = (cj == ci_sh && j <= i) ? 0.0 : 1.0;
#endif
#else
-#define interact 1.0
- skipmask = 1.0;
+ constexpr real interact = 1.0;
+ skipmask = interact;
#endif
VLJ = 0;
#ifdef CALC_COUL_TAB
rs = rsq*rinv*tab_coul_scale;
ri = int(rs);
- frac = rs - ri;
+ frac = rs - static_cast<real>(ri);
#if !GMX_DOUBLE
/* fexcl = F_i + frac * (F_(i+1)-F_i) */
fexcl = tab_coul_FDV0[ri*4] + frac*tab_coul_FDV0[ri*4+1];
ajz = ajy + STRIDE;
#ifdef CHECK_EXCLS
- gmx_load_simd_2xnn_interactions(l_cj[cjind].excl,
+ gmx_load_simd_2xnn_interactions(static_cast<int>(l_cj[cjind].excl),
filter_S0, filter_S2,
&interact_S0, &interact_S2);
#endif /* CHECK_EXCLS */
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
ajz = ajy + STRIDE;
#ifdef CHECK_EXCLS
- gmx_load_simd_4xn_interactions(l_cj[cjind].excl,
+ gmx_load_simd_4xn_interactions(static_cast<int>(l_cj[cjind].excl),
filter_S0, filter_S1,
filter_S2, filter_S3,
nbat->simdMasks.interaction_array.data(),
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
/* 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
{
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];
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,
{
continue;
}
-
ncj_old_i = getNumSimpleJClustersInList(*nbl);
d2cx = 0;
}
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])
{
/* 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;
continue;
}
- bz1_frac = bz1/iGrid.numCellsInColumn(ci_xy);
+ bz1_frac = bz1/real(iGrid.numCellsInColumn(ci_xy));
if (bz1_frac < 0)
{
bz1_frac = 0;
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)
{
}
else
{
- by0 = iGridDims.lowerCorner[YY] + (ci_y )*iGridDims.cellSize[YY] + shy;
- by1 = iGridDims.lowerCorner[YY] + (ci_y + 1)*iGridDims.cellSize[YY] + shy;
+ by0 = iGridDims.lowerCorner[YY] + (real(ci_y) )*iGridDims.cellSize[YY] + shy;
+ by1 = iGridDims.lowerCorner[YY] + (real(ci_y) + 1)*iGridDims.cellSize[YY] + shy;
}
get_cell_range<YY>(by0, by1,
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)
{
}
else
{
- bx0 = iGridDims.lowerCorner[XX] + (ci_x )*iGridDims.cellSize[XX] + shx;
- bx1 = iGridDims.lowerCorner[XX] + (ci_x+1)*iGridDims.cellSize[XX] + shx;
+ bx0 = iGridDims.lowerCorner[XX] + (real(ci_x) )*iGridDims.cellSize[XX] + shx;
+ bx1 = iGridDims.lowerCorner[XX] + (real(ci_x)+1)*iGridDims.cellSize[XX] + shx;
}
get_cell_range<XX>(bx0, bx1,
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 &&
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)
{
* but we do not do this because it would
* complicate this code even more.
*/
- int midCell = columnStart + static_cast<int>(bz1_frac*(columnEnd - columnStart));
+ int midCell = columnStart + static_cast<int>(bz1_frac*static_cast<real>(columnEnd - columnStart));
if (midCell >= columnEnd)
{
midCell = columnEnd - 1;
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)
{
*/
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.
NbnxnPairlistGpuWork &work = *nbl->work;
/* We will distinguish differences up to double the average */
- const int m = (2*nbl->cj4.size())/nbl->sci.size();
+ const int m = static_cast<int>((2*ssize(nbl->cj4))/ssize(nbl->sci));
/* Resize work.sci_sort so we can sort into it */
work.sci_sort.resize(nbl->sci.size());
/* 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;
//! Returns the number of steps performed with the current pair list
int numStepsWithPairlist(int64_t step) const
{
- return step - outerListCreationStep_;
+ return static_cast<int>(step - outerListCreationStep_);
}
//! Returns whether step is a dynamic list pruning step, for CPU lists
/*
* 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.
* and is exposed only to permit testing. Normal code should not
* need to call this function.
*/
- static const
+ static
std::array<RealType, 1<<tableBits>
makeTable()
{
* \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.
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));
}
void RestraintManager::addToSpec(std::shared_ptr<gmx::IRestraintPotential> puller,
- std::string name)
+ const std::string &name)
{
- instance_->add(std::move(puller), std::move(name));
+ instance_->add(std::move(puller), name);
}
std::vector< std::shared_ptr<IRestraintPotential> > RestraintManager::getRestraints() const
/*
* 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.
* \param name key by which to reference the restraint.
*/
void addToSpec(std::shared_ptr<gmx::IRestraintPotential> restraint,
- std::string name);
+ const std::string &name);
/*!
* \brief Get a copy of the current set of restraints to be applied.
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);
}
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;
}
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)
{
* 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 {};
}
-const std::string AtomProperties::elementFromAtomNumber(int atomNumber)
+std::string AtomProperties::elementFromAtomNumber(int atomNumber)
{
if (setProperties(prop(epropElement), restype(), epropElement, impl_->bWarned))
{
* \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.
*
}
/*! \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
/*! \brief Returns the number of blocks */
int numBlocks() const
{
- return static_cast<int>(index_.size() - 1);
+ return static_cast<int>(index_.size()) - 1;
}
/*! \brief Returns the size of the block with index \p blockIndex */
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)
{
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++)
{
* \param[in] ilists Set of interaction lists
* \param[in] flags Bit mask with one or more IF_... bits set
*/
-static inline const std::vector<InteractionListHandle>
+static inline std::vector<InteractionListHandle>
extractILists(const InteractionLists &ilists,
int flags)
{
(*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];
}
{
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])
{
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);
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)
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))
{
* \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"
*
{
//! Add a new group to t_blocka
-void addGroupToBlocka(t_blocka *b, gmx::ArrayRef<const int> index)
+void addGroupToBlocka(t_blocka *b, gmx::ArrayRef<const int> indices)
{
srenew(b->index, b->nr+2);
- srenew(b->a, b->nra+index.size());
- for (int i = 0; (i < index.ssize()); i++)
+ srenew(b->a, b->nra+indices.size());
+ for (index i = 0; i < indices.ssize(); i++)
{
- b->a[b->nra++] = index[i];
+ b->a[b->nra++] = indices[i];
}
b->nr++;
b->index[b->nr] = b->nra;
//! Fill ExclusionBlock with data.
int fillExclusionBlock(gmx::ArrayRef<ExclusionBlock> b)
{
- std::vector < std::vector < int>> index = {{0, 4, 7}, {1, 5, 8, 10}, {2, 6, 9, 11, 12}};
+ std::vector < std::vector < int>> indices = {{0, 4, 7}, {1, 5, 8, 10}, {2, 6, 9, 11, 12}};
int nra = 0;
- for (int i = 0; i < b.ssize(); i++)
+ for (index i = 0; i < b.ssize(); i++)
{
b[i].atomNumber.clear();
- for (const auto &j : index[i])
+ for (const auto &j : indices[i])
{
b[i].atomNumber.push_back(j);
}
{
init_blocka(ba);
- std::vector<int> index = {12, 11, 9, 6, 2};
- addGroupToBlocka(ba, index);
- index = {10, 8, 5, 1};
- addGroupToBlocka(ba, index);
- index = {7, 4, 0};
- addGroupToBlocka(ba, index);
+ std::vector<int> indices = {12, 11, 9, 6, 2};
+ addGroupToBlocka(ba, indices);
+ indices = {10, 8, 5, 1};
+ addGroupToBlocka(ba, indices);
+ indices = {7, 4, 0};
+ addGroupToBlocka(ba, indices);
}
class ExclusionBlockTest : public ::testing::Test
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++)
static void compareMoletypeAB(FILE *fp, gmx::ArrayRef<const gmx_moltype_t> mt1, real relativeTolerance, real absoluteTolerance)
{
fprintf(fp, "comparing free energy molecule types\n");
- for (int i = 0; i < mt1.ssize(); i++)
+ for (gmx::index i = 0; i < mt1.ssize(); i++)
{
compareAtoms(fp, &mt1[i].atoms, nullptr, relativeTolerance, absoluteTolerance);
}
cmp_int(fp, buf.c_str(), -1, g0.groups[group].size(), g1.groups[group].size());
if (g0.groups[group].size() == g1.groups[group].size())
{
- for (int j = 0; j < gmx::ssize(g0.groups[group]); j++)
+ for (gmx::index j = 0; j < gmx::ssize(g0.groups[group]); j++)
{
- buf = gmx::formatString("grps[%d].name[%d]", static_cast<int>(group), j);
+ buf = gmx::formatString("grps[%d].name[%zd]", static_cast<int>(group), j);
cmp_str(fp, buf.c_str(), -1,
*g0.groupNames[g0.groups[group][j]],
*g1.groupNames[g1.groups[group][j]]);
/*
* 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.
{
EnergyFrame::EnergyFrame(const t_enxframe &enxframe,
- const std::map<std::string, int> indicesOfEnergyFields)
+ const std::map<std::string, int> &indicesOfEnergyFields)
: step_(enxframe.step), time_(enxframe.t)
{
for (auto &index : indicesOfEnergyFields)
*
* 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.
using MapConstIterator = MapType::const_iterator;
//! Constructor
EnergyFrame(const t_enxframe &enxframe,
- std::map<std::string, int> indicesOfEnergyFields);
+ const std::map<std::string, int> &indicesOfEnergyFields);
/*! \brief Return string that helps users identify this frame, containing time and step number.
*
* \throws std::bad_alloc when out of memory */
#include <cstring>
#include <algorithm>
+#include <array>
#include <string>
/* This file is completely threadsafe - keep it that way! */
{
for (int j = 0; j < 4 && i < NCONTRIBUTORS; ++j, ++i)
{
- const int width = 18;
- char buf[30];
- const int offset = centeringOffset(width, strlen(Contributors[i]));
- GMX_RELEASE_ASSERT(static_cast<int>(strlen(Contributors[i])) + offset < asize(buf),
+ const int width = 18;
+ std::array<char, 30> buf;
+ const int offset = centeringOffset(width, strlen(Contributors[i]));
+ GMX_RELEASE_ASSERT(static_cast<int>(strlen(Contributors[i])) + offset < gmx::ssize(buf),
"Formatting buffer is not long enough");
- std::fill(buf, buf+width, ' ');
- std::strcpy(buf+offset, Contributors[i]);
- writer->writeString(formatString(" %-*s", width, buf));
+ std::fill(buf.begin(), buf.begin()+offset, ' ');
+ std::strncpy(buf.data()+offset, Contributors[i], gmx::ssize(buf) - offset);
+ writer->writeString(formatString(" %-*s", width, buf.data()));
}
writer->ensureLineBreak();
}
*
* 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.
{
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;
}
*
* 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.
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);
}
return *this;
}
//! Default move constructor.
- //NOLINTNEXTLINE(performance-noexcept-move-constructor) bug #38733
KeyValueTreeObject(KeyValueTreeObject &&) = default;
//! Default move assignment.
KeyValueTreeObject &operator=(KeyValueTreeObject &&) = default;
*
* 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.
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)
/*
* 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.
relativeToleranceAsFloatingPoint(double magnitude, double tolerance)
{
const double absoluteTolerance = std::abs(magnitude) * tolerance;
- return FloatingPointTolerance(absoluteTolerance, absoluteTolerance,
- tolerance, tolerance,
+ return FloatingPointTolerance(static_cast<float>(absoluteTolerance), absoluteTolerance,
+ static_cast<float>(tolerance), tolerance,
UINT64_MAX, UINT64_MAX,
false);
}
/*
* 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.
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);
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);
}
}
FilteringExactTextMatch::FilteringExactTextMatch(std::vector<std::string> linesToSkip)
- : linesToSkip_(linesToSkip)
+ : linesToSkip_(std::move(linesToSkip))
{}
void FilteringExactTextMatch::addRegexToSkip(const std::string &lineToSkip)