Fix clang-tidy-11 for domdec and utility
authorPaul Bauer <paul.bauer.q@gmail.com>
Fri, 5 Feb 2021 13:01:43 +0000 (13:01 +0000)
committerArtem Zhmurov <zhmurov@gmail.com>
Fri, 5 Feb 2021 13:01:43 +0000 (13:01 +0000)
Part of updates needed to conform to clang-tidy-11. Split into several
commits as it is impossible to have all changes together.

Refs #3897

19 files changed:
src/config.h.cmakein
src/gromacs/domdec/box.cpp
src/gromacs/domdec/cellsizes.cpp
src/gromacs/domdec/distribute.cpp
src/gromacs/domdec/dlbtiming.cpp
src/gromacs/domdec/domdec.cpp
src/gromacs/domdec/domdec_constraints.cpp
src/gromacs/domdec/domdec_network.cpp
src/gromacs/domdec/domdec_setup.cpp
src/gromacs/domdec/domdec_specatomcomm.cpp
src/gromacs/domdec/domdec_topology.cpp
src/gromacs/utility/alignedallocator.cpp
src/gromacs/utility/basenetwork.cpp
src/gromacs/utility/baseversion-gen.cpp.cmakein
src/gromacs/utility/baseversion.cpp
src/gromacs/utility/baseversion_gen.h
src/gromacs/utility/fatalerror.cpp
src/gromacs/utility/fatalerror.h
src/gromacs/utility/futil.cpp

index 3a5f69360a3e6d772ad034e32703b110c9d08b35..47797c46c6080635b8f294c6f1b41f7c2f8a174b 100644 (file)
 #cmakedefine01 HAVE_FSEEKO
 
 /* Define to 1 if _fseeki64 (and presumably _fseeki64) exists and is declared. */
+//NOLINTNEXTLINE(bugprone-reserved-identifier)
 #cmakedefine01 HAVE__FSEEKI64
 
 /* Have io.h (windows)*/
 #cmakedefine01 HAVE_MEMALIGN
 
 /* Define to 1 if you have the MSVC _aligned_malloc() function. */
+//NOLINTNEXTLINE(bugprone-reserved-identifier)
 #cmakedefine01 HAVE__ALIGNED_MALLOC
 
 /* Define to 1 if you have the clock_gettime() function. */
 #cmakedefine01 HAVE_FSYNC
 
 /* Define to 1 if you have the Windows _commit() function. */
+//NOLINTNEXTLINE(bugprone-reserved-identifier)
 #cmakedefine01 HAVE__COMMIT
 
 /* Define to 1 if you have the fileno() function. */
 #cmakedefine01 HAVE_FILENO
 
 /* Define to 1 if you have the _fileno() function. */
+//NOLINTNEXTLINE(bugprone-reserved-identifier)
 #cmakedefine01 HAVE__FILENO
 
 /* Define to 1 if you have the sigaction() function. */
  * malloc.h or xmmintrin.h, and 0 otherwise. Note that you need to
  * conditionally include the three headers too before using _mm_malloc().
  */
+//NOLINTNEXTLINE(bugprone-reserved-identifier)
 #cmakedefine01 HAVE__MM_MALLOC
 
 /* Define if SIGUSR1 is present */
index 86bffeec6b2f8732d519ea64d2f8a06b533d55db..f6c9225ce08c02fe483358077cf23e1ffe308a85 100644 (file)
@@ -2,7 +2,7 @@
  * This file is part of the GROMACS molecular simulation package.
  *
  * Copyright (c) 2009,2010,2014,2015,2017 by the GROMACS development team.
- * Copyright (c) 2018,2019,2020, by the GROMACS development team, led by
+ * Copyright (c) 2018,2019,2020,2021, 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.
@@ -64,6 +64,7 @@
 #include "gromacs/utility/fatalerror.h"
 
 #include "domdec_internal.h"
+#include "math.h"
 
 /*! \brief Calculates the average and standard deviation in 3D of atoms */
 static void calc_pos_av_stddev(gmx::ArrayRef<const gmx::RVec> x, rvec av, rvec stddev, const MPI_Comm* mpiCommunicator)
@@ -124,16 +125,12 @@ static void calc_pos_av_stddev(gmx::ArrayRef<const gmx::RVec> x, rvec av, rvec s
 /*! \brief Determines if dimensions require triclinic treatment and stores this info in ddbox */
 static void set_tric_dir(const ivec* dd_nc, gmx_ddbox_t* ddbox, const matrix box)
 {
-    int   npbcdim, d, i, j;
-    rvec *v, *normal;
-    real  dep, inv_skew_fac2;
-
-    npbcdim = ddbox->npbcdim;
-    normal  = ddbox->normal;
-    for (d = 0; d < DIM; d++)
+    int   npbcdim = ddbox->npbcdim;
+    rvec* normal  = ddbox->normal;
+    for (int d = 0; d < DIM; d++)
     {
         ddbox->tric_dir[d] = 0;
-        for (j = d + 1; j < npbcdim; j++)
+        for (int j = d + 1; j < npbcdim; j++)
         {
             if (box[j][d] != 0)
             {
@@ -166,13 +163,13 @@ static void set_tric_dir(const ivec* dd_nc, gmx_ddbox_t* ddbox, const matrix box
          */
         if (ddbox->tric_dir[d])
         {
-            inv_skew_fac2 = 1;
-            v             = ddbox->v[d];
+            real  inv_skew_fac2 = 1;
+            rvec* v             = ddbox->v[d];
             if (d == XX || d == YY)
             {
                 /* Normalize such that the "diagonal" is 1 */
                 svmul(1 / box[d + 1][d + 1], box[d + 1], v[d + 1]);
-                for (i = 0; i < d; i++)
+                for (int i = 0; i < d; i++)
                 {
                     v[d + 1][i] = 0;
                 }
@@ -182,8 +179,8 @@ static void set_tric_dir(const ivec* dd_nc, gmx_ddbox_t* ddbox, const matrix box
                     /* Normalize such that the "diagonal" is 1 */
                     svmul(1 / box[d + 2][d + 2], box[d + 2], v[d + 2]);
                     /* Set v[d+2][d+1] to zero by shifting along v[d+1] */
-                    dep = v[d + 2][d + 1] / v[d + 1][d + 1];
-                    for (i = 0; i < DIM; i++)
+                    const real dep = v[d + 2][d + 1] / v[d + 1][d + 1];
+                    for (int i = 0; i < DIM; i++)
                     {
                         v[d + 2][i] -= dep * v[d + 1][i];
                     }
@@ -201,7 +198,7 @@ static void set_tric_dir(const ivec* dd_nc, gmx_ddbox_t* ddbox, const matrix box
                 if (debug)
                 {
                     fprintf(debug, "box[%d]  %.3f %.3f %.3f\n", d, box[d][XX], box[d][YY], box[d][ZZ]);
-                    for (i = d + 1; i < DIM; i++)
+                    for (int i = d + 1; i < DIM; i++)
                     {
                         fprintf(debug, "  v[%d]  %.3f %.3f %.3f\n", i, v[i][XX], v[i][YY], v[i][ZZ]);
                     }
@@ -209,7 +206,7 @@ static void set_tric_dir(const ivec* dd_nc, gmx_ddbox_t* ddbox, const matrix box
             }
             ddbox->skew_fac[d] = 1.0 / std::sqrt(inv_skew_fac2);
             /* Set the normal vector length to skew_fac */
-            dep = ddbox->skew_fac[d] / norm(normal[d]);
+            const real dep = ddbox->skew_fac[d] / norm(normal[d]);
             svmul(dep, normal[d], normal[d]);
 
             if (debug)
@@ -222,7 +219,7 @@ static void set_tric_dir(const ivec* dd_nc, gmx_ddbox_t* ddbox, const matrix box
         {
             ddbox->skew_fac[d] = 1;
 
-            for (i = 0; i < DIM; i++)
+            for (int i = 0; i < DIM; i++)
             {
                 clear_rvec(ddbox->v[d][i]);
                 ddbox->v[d][i][i] = 1;
@@ -244,13 +241,11 @@ static void low_set_ddbox(int                            numPbcDimensions,
                           gmx_ddbox_t*                   ddbox)
 {
     rvec av, stddev;
-    real b0, b1;
-    int  d;
 
     ddbox->npbcdim     = numPbcDimensions;
     ddbox->nboundeddim = numBoundedDimensions;
 
-    for (d = 0; d < numBoundedDimensions; d++)
+    for (int d = 0; d < numBoundedDimensions; d++)
     {
         ddbox->box0[d]     = 0;
         ddbox->box_size[d] = box[d][d];
@@ -264,10 +259,10 @@ static void low_set_ddbox(int                            numPbcDimensions,
          * gives a uniform load for a rectangular block of cg's.
          * For a sphere it is not a bad approximation for 4x1x1 up to 4x2x2.
          */
-        for (d = ddbox->nboundeddim; d < DIM; d++)
+        for (int d = ddbox->nboundeddim; d < DIM; d++)
         {
-            b0 = av[d] - GRID_STDDEV_FAC * stddev[d];
-            b1 = av[d] + GRID_STDDEV_FAC * stddev[d];
+            const real b0 = av[d] - GRID_STDDEV_FAC * stddev[d];
+            const real b1 = av[d] + GRID_STDDEV_FAC * stddev[d];
             if (debug)
             {
                 fprintf(debug, "Setting global DD grid boundaries to %f - %f\n", b0, b1);
index 1faea8895a1d48f6204afd2ea01511761fa2c7ef..d6edf00f8627fd0e5304c4af2c07d4061cfebbf6 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2018,2019,2020, by the GROMACS development team, led by
+ * Copyright (c) 2018,2019,2020,2021, 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.
@@ -55,6 +55,7 @@
 
 #include "atomdistribution.h"
 #include "domdec_internal.h"
+#include "math.h"
 #include "utility.h"
 
 static void set_pme_maxshift(gmx_domdec_t*      dd,
@@ -63,15 +64,11 @@ static void set_pme_maxshift(gmx_domdec_t*      dd,
                              const gmx_ddbox_t* ddbox,
                              const real*        cellFrac)
 {
-    gmx_domdec_comm_t* comm;
-    int                nc, ns, s;
-    int *              xmin, *xmax;
-    real               range, pme_boundary;
-    int                sh;
+    int sh = 0;
 
-    comm = dd->comm;
-    nc   = dd->numCells[ddpme->dim];
-    ns   = ddpme->nslab;
+    gmx_domdec_comm_t* comm = dd->comm;
+    const int          nc   = dd->numCells[ddpme->dim];
+    const int          ns   = ddpme->nslab;
 
     if (!ddpme->dim_match)
     {
@@ -88,22 +85,22 @@ static void set_pme_maxshift(gmx_domdec_t*      dd,
         /* We need to check for all pme nodes which nodes they
          * could possibly need to communicate with.
          */
-        xmin = ddpme->pp_min;
-        xmax = ddpme->pp_max;
+        const int* xmin = ddpme->pp_min;
+        const int* xmax = ddpme->pp_max;
         /* Allow for atoms to be maximally 2/3 times the cut-off
          * out of their DD cell. This is a reasonable balance between
          * between performance and support for most charge-group/cut-off
          * combinations.
          */
-        range = 2.0 / 3.0 * comm->systemInfo.cutoff / ddbox->box_size[ddpme->dim];
+        real range = 2.0 / 3.0 * comm->systemInfo.cutoff / ddbox->box_size[ddpme->dim];
         /* Avoid extra communication when we are exactly at a boundary */
         range *= 0.999;
 
-        sh = 1;
-        for (s = 0; s < ns; s++)
+        int sh = 1;
+        for (int s = 0; s < ns; s++)
         {
             /* PME slab s spreads atoms between box frac. s/ns and (s+1)/ns */
-            pme_boundary = static_cast<real>(s) / ns;
+            real pme_boundary = static_cast<real>(s) / ns;
             while (sh + 1 < ns
                    && ((s - (sh + 1) >= 0 && cellFrac[xmax[s - (sh + 1)] + 1] + range > pme_boundary)
                        || (s - (sh + 1) < 0 && cellFrac[xmax[s - (sh + 1) + ns] + 1] - 1 + range > pme_boundary)))
@@ -130,11 +127,9 @@ static void set_pme_maxshift(gmx_domdec_t*      dd,
 
 static void check_box_size(const gmx_domdec_t* dd, const gmx_ddbox_t* ddbox)
 {
-    int d, dim;
-
-    for (d = 0; d < dd->ndim; d++)
+    for (int d = 0; d < dd->ndim; d++)
     {
-        dim = dd->dim[d];
+        const int dim = dd->dim[d];
         if (dim < ddbox->nboundeddim
             && ddbox->box_size[dim] * ddbox->skew_fac[dim]
                        < dd->numCells[dim] * dd->comm->cellsize_limit * DD_CELL_MARGIN)
@@ -154,15 +149,13 @@ static void check_box_size(const gmx_domdec_t* dd, const gmx_ddbox_t* ddbox)
 
 real grid_jump_limit(const gmx_domdec_comm_t* comm, real cutoff, int dim_ind)
 {
-    real grid_jump_limit;
-
     /* The distance between the boundaries of cells at distance
      * x+-1,y+-1 or y+-1,z+-1 is limited by the cut-off restrictions
      * and by the fact that cells should not be shifted by more than
      * half their size, such that cg's only shift by one cell
      * at redecomposition.
      */
-    grid_jump_limit = comm->cellsize_limit;
+    real grid_jump_limit = comm->cellsize_limit;
     if (!comm->bVacDLBNoLimit)
     {
         if (comm->bPMELoadBalDLBLimits)
@@ -182,9 +175,7 @@ real grid_jump_limit(const gmx_domdec_comm_t* comm, real cutoff, int dim_ind)
  */
 static real cellsize_min_dlb(gmx_domdec_comm_t* comm, int dim_ind, int dim)
 {
-    real cellsize_min;
-
-    cellsize_min = comm->cellsize_min[dim];
+    real cellsize_min = comm->cellsize_min[dim];
 
     if (!comm->bVacDLBNoLimit)
     {
@@ -345,17 +336,15 @@ static void dd_cell_sizes_dlb_root_enforce_limits(gmx_domdec_t*      dd,
                                                   real               cellsize_limit_f,
                                                   int                range[])
 {
-    gmx_domdec_comm_t* comm;
-    real               halfway, cellsize_limit_f_i, region_size;
-    gmx_bool           bLastHi  = FALSE;
-    int                nrange[] = { range[0], range[1] };
+    gmx_bool bLastHi  = FALSE;
+    int      nrange[] = { range[0], range[1] };
 
-    region_size = rowMaster->cellFrac[range[1]] - rowMaster->cellFrac[range[0]];
+    const real region_size = rowMaster->cellFrac[range[1]] - rowMaster->cellFrac[range[0]];
 
     GMX_ASSERT(region_size >= (range[1] - range[0]) * cellsize_limit_f,
                "The region should fit all cells at minimum size");
 
-    comm = dd->comm;
+    gmx_domdec_comm_t* comm = dd->comm;
 
     const int ncd = dd->numCells[dim];
 
@@ -378,8 +367,8 @@ static void dd_cell_sizes_dlb_root_enforce_limits(gmx_domdec_t*      dd,
     {
         rowMaster->isCellMin[i] = false;
     }
-    int nmin = 0;
-    int nmin_old;
+    int nmin     = 0;
+    int nmin_old = 0;
     do
     {
         nmin_old = nmin;
@@ -402,14 +391,8 @@ static void dd_cell_sizes_dlb_root_enforce_limits(gmx_domdec_t*      dd,
             if (!rowMaster->isCellMin[i])
             {
                 cell_size[i] *= fac;
-                if (!dimHasPbc && (i == 0 || i == dd->numCells[dim] - 1))
-                {
-                    cellsize_limit_f_i = 0;
-                }
-                else
-                {
-                    cellsize_limit_f_i = cellsize_limit_f;
-                }
+                const real cellsize_limit_f_i =
+                        (!dimHasPbc && (i == 0 || i == dd->numCells[dim] - 1)) ? 0 : cellsize_limit_f;
                 if (cell_size[i] < cellsize_limit_f_i)
                 {
                     rowMaster->isCellMin[i] = true;
@@ -458,7 +441,7 @@ static void dd_cell_sizes_dlb_root_enforce_limits(gmx_domdec_t*      dd,
          */
         for (int i = range[0] + 1; i < range[1]; i++)
         {
-            halfway = 0.5 * (rowMaster->oldCellFrac[i] + rowMaster->oldCellFrac[i - 1]);
+            real halfway = 0.5 * (rowMaster->oldCellFrac[i] + rowMaster->oldCellFrac[i - 1]);
             if (rowMaster->cellFrac[i] < halfway)
             {
                 rowMaster->cellFrac[i] = halfway;
@@ -609,16 +592,14 @@ static void set_dd_cell_sizes_dlb_root(gmx_domdec_t*      dd,
     {
         real load_aver  = comm->load[d].sum_m / ncd;
         real change_max = 0;
-        real load_i;
-        real change;
         for (int i = 0; i < ncd; i++)
         {
             /* Determine the relative imbalance of cell i */
-            load_i         = comm->load[d].load[i * comm->load[d].nload + 2];
-            real imbalance = (load_i - load_aver) / (load_aver > 0 ? load_aver : 1);
+            const real load_i    = comm->load[d].load[i * comm->load[d].nload + 2];
+            const real imbalance = (load_i - load_aver) / (load_aver > 0 ? load_aver : 1);
             /* Determine the change of the cell size using underrelaxation */
-            change     = -c_relax * imbalance;
-            change_max = std::max(change_max, std::max(change, -change));
+            const real change = -c_relax * imbalance;
+            change_max        = std::max(change_max, std::max(change, -change));
         }
         /* Limit the amount of scaling.
          * We need to use the same rescaling for all cells in one row,
@@ -632,10 +613,10 @@ static void set_dd_cell_sizes_dlb_root(gmx_domdec_t*      dd,
         for (int i = 0; i < ncd; i++)
         {
             /* Determine the relative imbalance of cell i */
-            load_i         = comm->load[d].load[i * comm->load[d].nload + 2];
-            real imbalance = (load_i - load_aver) / (load_aver > 0 ? load_aver : 1);
+            const real load_i    = comm->load[d].load[i * comm->load[d].nload + 2];
+            const real imbalance = (load_i - load_aver) / (load_aver > 0 ? load_aver : 1);
             /* Determine the change of the cell size using underrelaxation */
-            change       = -sc * imbalance;
+            const real change = -sc * imbalance;
             cell_size[i] = (rowMaster->cellFrac[i + 1] - rowMaster->cellFrac[i]) * (1 + change);
         }
     }
@@ -851,13 +832,11 @@ static void set_dd_cell_sizes_dlb_change(gmx_domdec_t*      dd,
 
 static void set_dd_cell_sizes_dlb_nochange(gmx_domdec_t* dd, const gmx_ddbox_t* ddbox)
 {
-    int d;
-
     /* This function assumes the box is static and should therefore
      * not be called when the box has changed since the last
      * call to dd_partition_system.
      */
-    for (d = 0; d < dd->ndim; d++)
+    for (int d = 0; d < dd->ndim; d++)
     {
         relative_to_absolute_cell_bounds(dd, ddbox, d);
     }
@@ -872,10 +851,7 @@ static void set_dd_cell_sizes_dlb(gmx_domdec_t*      dd,
                                   int64_t            step,
                                   gmx_wallcycle_t    wcycle)
 {
-    gmx_domdec_comm_t* comm;
-    int                dim;
-
-    comm = dd->comm;
+    gmx_domdec_comm_t* comm = dd->comm;
 
     if (bDoDLB)
     {
@@ -889,7 +865,7 @@ static void set_dd_cell_sizes_dlb(gmx_domdec_t*      dd,
     }
 
     /* Set the dimensions for which no DD is used */
-    for (dim = 0; dim < DIM; dim++)
+    for (int dim = 0; dim < DIM; dim++)
     {
         if (dd->numCells[dim] == 1)
         {
index 9485b08d13325b28ee737b8f119339309a915369..f9f5e5b55ff8061b4b987b27a36ff6c05df33be4 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2018,2019,2020, by the GROMACS development team, led by
+ * Copyright (c) 2018,2019,2020,2021, 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.
@@ -60,6 +60,7 @@
 #include "atomdistribution.h"
 #include "cellsizes.h"
 #include "domdec_internal.h"
+#include "math.h"
 #include "utility.h"
 
 static void distributeVecSendrecv(gmx_domdec_t*                  dd,
@@ -444,13 +445,10 @@ static std::vector<std::vector<int>> getAtomGroupDistribution(const gmx::MDLogge
     {
         // Use double for the sums to avoid natoms^2 overflowing
         // (65537^2 > 2^32)
-        int    nat_sum, nat_min, nat_max;
-        double nat2_sum;
-
-        nat_sum  = 0;
-        nat2_sum = 0;
-        nat_min  = ma.domainGroups[0].numAtoms;
-        nat_max  = ma.domainGroups[0].numAtoms;
+        int    nat_sum  = 0;
+        double nat2_sum = 0;
+        int    nat_min  = ma.domainGroups[0].numAtoms;
+        int    nat_max  = ma.domainGroups[0].numAtoms;
         for (int rank = 0; rank < dd->nnodes; rank++)
         {
             int numAtoms = ma.domainGroups[rank].numAtoms;
@@ -483,8 +481,8 @@ static void distributeAtomGroups(const gmx::MDLogger& mdlog,
                                  const gmx_ddbox_t*   ddbox,
                                  rvec                 pos[])
 {
-    AtomDistribution* ma = dd->ma.get();
-    int *             ibuf, buf2[2] = { 0, 0 };
+    AtomDistribution* ma   = dd->ma.get();
+    int *             ibuf = nullptr, buf2[2] = { 0, 0 };
     gmx_bool          bMaster = DDMASTER(dd);
 
     std::vector<std::vector<int>> groupIndices;
@@ -507,10 +505,6 @@ static void distributeAtomGroups(const gmx::MDLogger& mdlog,
         }
         ibuf = ma->intBuffer.data();
     }
-    else
-    {
-        ibuf = nullptr;
-    }
     dd_scatter(dd, 2 * sizeof(int), ibuf, buf2);
 
     dd->ncg_home = buf2[0];
index 1c1fd9376eed0da5bb1ee8185efbbe12ab90fbe4..74f7910611c971fcd28b7efb04f92ee14e345ccb 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2017,2018,2019, by the GROMACS development team, led by
+ * Copyright (c) 2017,2018,2019,2021, 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.
@@ -44,6 +44,7 @@
 #include "gromacs/utility/gmxassert.h"
 
 #include "domdec_internal.h"
+#include "math.h"
 
 /*! \brief Struct for timing the region for dynamic load balancing */
 struct BalanceRegion
@@ -175,17 +176,13 @@ void DDBalanceRegionHandler::closeRegionGpuImpl(float waitGpuCyclesInCpuRegion,
 //! Accumulates flop counts for force calculations.
 static double force_flop_count(const t_nrnb* nrnb)
 {
-    int         i;
-    double      sum;
-    const char* name;
-
-    sum = 0;
-    for (i = 0; i < eNR_NBKERNEL_FREE_ENERGY; i++)
+    double sum = 0;
+    for (int i = 0; i < eNR_NBKERNEL_FREE_ENERGY; i++)
     {
         /* To get closer to the real timings, we half the count
          * for the normal loops and again half it for water loops.
          */
-        name = nrnb_str(i);
+        const char* name = nrnb_str(i);
         if (strstr(name, "W3") != nullptr || strstr(name, "W4") != nullptr)
         {
             sum += nrnb->n[i] * 0.25 * cost_nrnb(i);
@@ -195,15 +192,15 @@ static double force_flop_count(const t_nrnb* nrnb)
             sum += nrnb->n[i] * 0.50 * cost_nrnb(i);
         }
     }
-    for (i = eNR_NBKERNEL_FREE_ENERGY; i <= eNR_NB14; i++)
+    for (int i = eNR_NBKERNEL_FREE_ENERGY; i <= eNR_NB14; i++)
     {
-        name = nrnb_str(i);
+        const char* name = nrnb_str(i);
         if (strstr(name, "W3") != nullptr || strstr(name, "W4") != nullptr)
         {
             sum += nrnb->n[i] * cost_nrnb(i);
         }
     }
-    for (i = eNR_BONDS; i <= eNR_WALLS; i++)
+    for (int i = eNR_BONDS; i <= eNR_WALLS; i++)
     {
         sum += nrnb->n[i] * cost_nrnb(i);
     }
@@ -230,9 +227,7 @@ void dd_force_flop_stop(gmx_domdec_t* dd, t_nrnb* nrnb)
 
 void clear_dd_cycle_counts(gmx_domdec_t* dd)
 {
-    int i;
-
-    for (i = 0; i < ddCyclNr; i++)
+    for (int i = 0; i < ddCyclNr; i++)
     {
         dd->comm->cycl[i]     = 0;
         dd->comm->cycl_n[i]   = 0;
index e54203bcbfca1df31236ea0f61258bcfe0511d97..9fd60a568840a6937334f7dbbb910d2e74c262ad 100644 (file)
 #include "domdec_internal.h"
 #include "domdec_setup.h"
 #include "domdec_vsite.h"
+#include "math.h"
 #include "redistribute.h"
 #include "utility.h"
 
@@ -178,7 +179,7 @@ static int ddcoord2ddnodeid(gmx_domdec_t* dd, ivec c)
 
 int ddglatnr(const gmx_domdec_t* dd, int i)
 {
-    int atnr;
+    int atnr = 0;
 
     if (dd == nullptr)
     {
@@ -207,15 +208,13 @@ gmx::ArrayRef<const gmx::RangePartitioning> getUpdateGroupingPerMoleculetype(con
 
 void dd_store_state(gmx_domdec_t* dd, t_state* state)
 {
-    int i;
-
     if (state->ddp_count != dd->ddp_count)
     {
         gmx_incons("The MD state does not match the domain decomposition state");
     }
 
     state->cg_gl.resize(dd->ncg_home);
-    for (i = 0; i < dd->ncg_home; i++)
+    for (int i = 0; i < dd->ncg_home; i++)
     {
         state->cg_gl[i] = dd->globalAtomGroupIndices[i];
     }
@@ -262,25 +261,21 @@ void dd_move_x(gmx_domdec_t* dd, const matrix box, gmx::ArrayRef<gmx::RVec> x, g
 {
     wallcycle_start(wcycle, ewcMOVEX);
 
-    int                    nzone, nat_tot;
-    gmx_domdec_comm_t*     comm;
-    gmx_domdec_comm_dim_t* cd;
-    rvec                   shift = { 0, 0, 0 };
-    gmx_bool               bPBC, bScrew;
+    rvec shift = { 0, 0, 0 };
 
-    comm = dd->comm;
+    gmx_domdec_comm_t* comm = dd->comm;
 
-    nzone   = 1;
-    nat_tot = comm->atomRanges.numHomeAtoms();
+    int nzone   = 1;
+    int nat_tot = comm->atomRanges.numHomeAtoms();
     for (int d = 0; d < dd->ndim; d++)
     {
-        bPBC   = (dd->ci[dd->dim[d]] == 0);
-        bScrew = (bPBC && dd->unitCellInfo.haveScrewPBC && dd->dim[d] == XX);
+        const bool bPBC   = (dd->ci[dd->dim[d]] == 0);
+        const bool bScrew = (bPBC && dd->unitCellInfo.haveScrewPBC && dd->dim[d] == XX);
         if (bPBC)
         {
             copy_rvec(box[dd->dim[d]], shift);
         }
-        cd = &comm->cd[d];
+        gmx_domdec_comm_dim_t* cd = &comm->cd[d];
         for (const gmx_domdec_ind_t& ind : cd->ind)
         {
             DDBufferAccess<gmx::RVec> sendBufferAccess(comm->rvecBuffer, ind.nsend[nzone + 1]);
@@ -479,17 +474,13 @@ static gmx::ArrayRef<real> realArrayRefFromRvecArrayRef(gmx::ArrayRef<gmx::RVec>
 
 void dd_atom_spread_real(gmx_domdec_t* dd, real v[])
 {
-    int                    nzone, nat_tot;
-    gmx_domdec_comm_t*     comm;
-    gmx_domdec_comm_dim_t* cd;
-
-    comm = dd->comm;
+    gmx_domdec_comm_t* comm = dd->comm;
 
-    nzone   = 1;
-    nat_tot = comm->atomRanges.numHomeAtoms();
+    int nzone   = 1;
+    int nat_tot = comm->atomRanges.numHomeAtoms();
     for (int d = 0; d < dd->ndim; d++)
     {
-        cd = &comm->cd[d];
+        gmx_domdec_comm_dim_t* cd = &comm->cd[d];
         for (const gmx_domdec_ind_t& ind : cd->ind)
         {
             /* Note: We provision for RVec instead of real, so a factor of 3
@@ -537,17 +528,13 @@ void dd_atom_spread_real(gmx_domdec_t* dd, real v[])
 
 void dd_atom_sum_real(gmx_domdec_t* dd, real v[])
 {
-    int                    nzone, nat_tot;
-    gmx_domdec_comm_t*     comm;
-    gmx_domdec_comm_dim_t* cd;
-
-    comm = dd->comm;
+    gmx_domdec_comm_t* comm = dd->comm;
 
-    nzone   = comm->zones.n / 2;
-    nat_tot = comm->atomRanges.end(DDAtomRanges::Type::Zones);
+    int nzone   = comm->zones.n / 2;
+    int nat_tot = comm->atomRanges.end(DDAtomRanges::Type::Zones);
     for (int d = dd->ndim - 1; d >= 0; d--)
     {
-        cd = &comm->cd[d];
+        gmx_domdec_comm_dim_t* cd = &comm->cd[d];
         for (int p = cd->numPulses() - 1; p >= 0; p--)
         {
             const gmx_domdec_ind_t& ind = cd->ind[p];
@@ -630,9 +617,7 @@ real dd_cutoff_multibody(const gmx_domdec_t* dd)
 
 real dd_cutoff_twobody(const gmx_domdec_t* dd)
 {
-    real r_mb;
-
-    r_mb = dd_cutoff_multibody(dd);
+    const real r_mb = dd_cutoff_multibody(dd);
 
     return std::max(dd->comm->systemInfo.cutoff, r_mb);
 }
@@ -688,15 +673,13 @@ static std::vector<int> dd_interleaved_pme_ranks(const DDRankSetup& ddRankSetup)
 
 static int gmx_ddcoord2pmeindex(const t_commrec* cr, int x, int y, int z)
 {
-    gmx_domdec_t* dd;
-    ivec          coords;
-    int           slab;
+    ivec coords;
 
-    dd         = cr->dd;
-    coords[XX] = x;
-    coords[YY] = y;
-    coords[ZZ] = z;
-    slab       = ddindex2pmeindex(dd->comm->ddRankSetup, dd_index(dd->numCells, coords));
+    gmx_domdec_t* dd = cr->dd;
+    coords[XX]       = x;
+    coords[YY]       = y;
+    coords[ZZ]       = z;
+    const int slab   = ddindex2pmeindex(dd->comm->ddRankSetup, dd_index(dd->numCells, coords));
 
     return slab;
 }
@@ -849,7 +832,7 @@ std::vector<int> get_pme_ddranks(const t_commrec* cr, const int pmenodeid)
 
 static gmx_bool receive_vir_ener(const gmx_domdec_t* dd, gmx::ArrayRef<const int> pmeRanks, const t_commrec* cr)
 {
-    gmx_bool bReceive = TRUE;
+    bool bReceive = true;
 
     const DDRankSetup& ddRankSetup = dd->comm->ddRankSetup;
     if (ddRankSetup.usePmeOnlyRanks)
@@ -864,7 +847,7 @@ static gmx_bool receive_vir_ener(const gmx_domdec_t* dd, gmx::ArrayRef<const int
             coords[cartSetup.cartpmedim]++;
             if (coords[cartSetup.cartpmedim] < dd->numCells[cartSetup.cartpmedim])
             {
-                int rank;
+                int rank = 0;
                 MPI_Cart_rank(cr->mpi_comm_mysim, coords, &rank);
                 if (dd_simnode2pmenode(ddRankSetup, cartSetup, pmeRanks, cr, rank) == pmenode)
                 {
@@ -895,14 +878,11 @@ static gmx_bool receive_vir_ener(const gmx_domdec_t* dd, gmx::ArrayRef<const int
 
 static void set_slb_pme_dim_f(gmx_domdec_t* dd, int dim, real** dim_f)
 {
-    gmx_domdec_comm_t* comm;
-    int                i;
-
-    comm = dd->comm;
+    gmx_domdec_comm_t* comm = dd->comm;
 
     snew(*dim_f, dd->numCells[dim] + 1);
     (*dim_f)[0] = 0;
-    for (i = 1; i < dd->numCells[dim]; i++)
+    for (int i = 1; i < dd->numCells[dim]; i++)
     {
         if (comm->slb_frac[dim])
         {
@@ -955,16 +935,8 @@ static void init_ddpme(gmx_domdec_t* dd, gmx_ddpme_t* ddpme, int dimind)
          */
         if (dimind == 0 || xyz[XX] == dd->ci[XX])
         {
-            const int pmeindex = ddindex2pmeindex(ddRankSetup, i);
-            int       slab;
-            if (dimind == 0)
-            {
-                slab = pmeindex / nso;
-            }
-            else
-            {
-                slab = pmeindex % ddpme->nslab;
-            }
+            const int pmeindex  = ddindex2pmeindex(ddRankSetup, i);
+            const int slab      = (dimind == 0) ? pmeindex / nso : pmeindex % ddpme->nslab;
             ddpme->pp_min[slab] = std::min(ddpme->pp_min[slab], xyz[dimind]);
             ddpme->pp_max[slab] = std::max(ddpme->pp_max[slab], xyz[dimind]);
         }
@@ -1038,17 +1010,16 @@ void dd_cycles_add(const gmx_domdec_t* dd, float cycles, int ddCycl)
 #if GMX_MPI
 static void make_load_communicator(gmx_domdec_t* dd, int dim_ind, ivec loc)
 {
-    MPI_Comm c_row;
-    int      dim, i, rank;
+    MPI_Comm c_row = nullptr;
     ivec     loc_c;
-    gmx_bool bPartOfGroup = FALSE;
+    bool     bPartOfGroup = false;
 
-    dim = dd->dim[dim_ind];
+    const int dim = dd->dim[dim_ind];
     copy_ivec(loc, loc_c);
-    for (i = 0; i < dd->numCells[dim]; i++)
+    for (int i = 0; i < dd->numCells[dim]; i++)
     {
-        loc_c[dim] = i;
-        rank       = dd_index(dd->numCells, loc_c);
+        loc_c[dim]     = i;
+        const int rank = dd_index(dd->numCells, loc_c);
         if (rank == dd->rank)
         {
             /* This process is part of the group */
@@ -1095,9 +1066,7 @@ static void make_load_communicator(gmx_domdec_t* dd, int dim_ind, ivec loc)
 void dd_setup_dlb_resource_sharing(const t_commrec* cr, int gpu_id)
 {
 #if GMX_MPI
-    int           physicalnode_id_hash;
-    gmx_domdec_t* dd;
-    MPI_Comm      mpi_comm_pp_physicalnode;
+    MPI_Comm mpi_comm_pp_physicalnode = nullptr;
 
     if (!thisRankHasDuty(cr, DUTY_PP) || gpu_id < 0)
     {
@@ -1107,9 +1076,9 @@ void dd_setup_dlb_resource_sharing(const t_commrec* cr, int gpu_id)
         return;
     }
 
-    physicalnode_id_hash = gmx_physicalnode_id_hash();
+    const int physicalnode_id_hash = gmx_physicalnode_id_hash();
 
-    dd = cr->dd;
+    gmx_domdec_t* dd = cr->dd;
 
     if (debug)
     {
@@ -1147,7 +1116,6 @@ void dd_setup_dlb_resource_sharing(const t_commrec* cr, int gpu_id)
 static void make_load_communicators(gmx_domdec_t gmx_unused* dd)
 {
 #if GMX_MPI
-    int  dim0, dim1, i, j;
     ivec loc;
 
     if (debug)
@@ -1167,8 +1135,8 @@ static void make_load_communicators(gmx_domdec_t gmx_unused* dd)
     make_load_communicator(dd, 0, loc);
     if (dd->ndim > 1)
     {
-        dim0 = dd->dim[0];
-        for (i = 0; i < dd->numCells[dim0]; i++)
+        const int dim0 = dd->dim[0];
+        for (int i = 0; i < dd->numCells[dim0]; i++)
         {
             loc[dim0] = i;
             make_load_communicator(dd, 1, loc);
@@ -1176,12 +1144,12 @@ static void make_load_communicators(gmx_domdec_t gmx_unused* dd)
     }
     if (dd->ndim > 2)
     {
-        dim0 = dd->dim[0];
-        for (i = 0; i < dd->numCells[dim0]; i++)
+        const int dim0 = dd->dim[0];
+        for (int i = 0; i < dd->numCells[dim0]; i++)
         {
-            loc[dim0] = i;
-            dim1      = dd->dim[1];
-            for (j = 0; j < dd->numCells[dim1]; j++)
+            loc[dim0]      = i;
+            const int dim1 = dd->dim[1];
+            for (int j = 0; j < dd->numCells[dim1]; j++)
             {
                 loc[dim1] = j;
                 make_load_communicator(dd, 2, loc);
@@ -1199,14 +1167,12 @@ static void make_load_communicators(gmx_domdec_t gmx_unused* dd)
 /*! \brief Sets up the relation between neighboring domains and zones */
 static void setup_neighbor_relations(gmx_domdec_t* dd)
 {
-    int                 d, dim, m;
-    ivec                tmp, s;
-    gmx_domdec_zones_t* zones;
+    ivec tmp, s;
     GMX_ASSERT((dd->ndim >= 0) && (dd->ndim <= DIM), "Must have valid number of dimensions for DD");
 
-    for (d = 0; d < dd->ndim; d++)
+    for (int d = 0; d < dd->ndim; d++)
     {
-        dim = dd->dim[d];
+        const int dim = dd->dim[d];
         copy_ivec(dd->ci, tmp);
         tmp[dim]           = (tmp[dim] + 1) % dd->numCells[dim];
         dd->neighbor[d][0] = ddcoord2ddnodeid(dd, tmp);
@@ -1228,13 +1194,13 @@ static void setup_neighbor_relations(gmx_domdec_t* dd)
     int nizone = (1 << std::max(dd->ndim - 1, 0));
     assert(nizone >= 1 && nizone <= DD_MAXIZONE);
 
-    zones = &dd->comm->zones;
+    gmx_domdec_zones_t* zones = &dd->comm->zones;
 
     for (int i = 0; i < nzone; i++)
     {
-        m = 0;
+        int m = 0;
         clear_ivec(zones->shift[i]);
-        for (d = 0; d < dd->ndim; d++)
+        for (int d = 0; d < dd->ndim; d++)
         {
             zones->shift[i][dd->dim[d]] = dd_zo[i][m++];
         }
@@ -1243,7 +1209,7 @@ static void setup_neighbor_relations(gmx_domdec_t* dd)
     zones->n = nzone;
     for (int i = 0; i < nzone; i++)
     {
-        for (d = 0; d < DIM; d++)
+        for (int d = 0; d < DIM; d++)
         {
             s[d] = dd->ci[d] - zones->shift[i][d];
             if (s[d] < 0)
@@ -1269,7 +1235,7 @@ static void setup_neighbor_relations(gmx_domdec_t* dd)
          */
         iZone.jZoneRange = gmx::Range<int>(std::min(ddNonbondedZonePairRanges[iZoneIndex][1], nzone),
                                            std::min(ddNonbondedZonePairRanges[iZoneIndex][2], nzone));
-        for (dim = 0; dim < DIM; dim++)
+        for (int dim = 0; dim < DIM; dim++)
         {
             if (dd->numCells[dim] == 1)
             {
@@ -1334,7 +1300,7 @@ static void make_pp_communicator(const gmx::MDLogger& mdlog,
         {
             periods[i] = TRUE;
         }
-        MPI_Comm comm_cart;
+        MPI_Comm comm_cart = nullptr;
         MPI_Cart_create(cr->mpi_comm_mygroup, DIM, dd->numCells, periods, static_cast<int>(reorder), &comm_cart);
         /* We overwrite the old communicator with the new cartesian one */
         cr->mpi_comm_mygroup = comm_cart;
@@ -1354,15 +1320,7 @@ static void make_pp_communicator(const gmx::MDLogger& mdlog,
         /* Get the rank of the DD master,
          * above we made sure that the master node is a PP node.
          */
-        int rank;
-        if (MASTER(cr))
-        {
-            rank = dd->rank;
-        }
-        else
-        {
-            rank = 0;
-        }
+        int rank = MASTER(cr) ? dd->rank : 0;
         MPI_Allreduce(&rank, &dd->masterrank, 1, MPI_INT, MPI_SUM, dd->mpi_comm_all);
     }
     else if (cartSetup.bCartesianPP)
@@ -1521,7 +1479,7 @@ static CartesianRankSetup split_communicator(const gmx::MDLogger& mdlog,
     if (cartSetup.bCartesianPP_PME)
     {
 #if GMX_MPI
-        int  rank;
+        int  rank = 0;
         ivec periods;
 
         GMX_LOG(mdlog.info)
@@ -1535,7 +1493,7 @@ static CartesianRankSetup split_communicator(const gmx::MDLogger& mdlog,
         {
             periods[i] = TRUE;
         }
-        MPI_Comm comm_cart;
+        MPI_Comm comm_cart = nullptr;
         MPI_Cart_create(cr->mpi_comm_mysim, DIM, cartSetup.ntot, periods, static_cast<int>(reorder), &comm_cart);
         MPI_Comm_rank(comm_cart, &rank);
         if (MASTER(cr) && rank != 0)
@@ -1714,19 +1672,16 @@ static void setupGroupCommunication(const gmx::MDLogger&     mdlog,
 
 static real* get_slb_frac(const gmx::MDLogger& mdlog, const char* dir, int nc, const char* size_string)
 {
-    real * slb_frac, tot;
-    int    i, n;
-    double dbl;
-
-    slb_frac = nullptr;
+    real* slb_frac = nullptr;
     if (nc > 1 && size_string != nullptr)
     {
         GMX_LOG(mdlog.info).appendTextFormatted("Using static load balancing for the %s direction", dir);
         snew(slb_frac, nc);
-        tot = 0;
-        for (i = 0; i < nc; i++)
+        real tot = 0;
+        for (int i = 0; i < nc; i++)
         {
-            dbl = 0;
+            double dbl = 0;
+            int    n   = 0;
             sscanf(size_string, "%20lf%n", &dbl, &n);
             if (dbl == 0)
             {
@@ -1741,7 +1696,7 @@ static real* get_slb_frac(const gmx::MDLogger& mdlog, const char* dir, int nc, c
         }
         /* Normalize */
         std::string relativeCellSizes = "Relative cell sizes:";
-        for (i = 0; i < nc; i++)
+        for (int i = 0; i < nc; i++)
         {
             slb_frac[i] /= tot;
             relativeCellSizes += gmx::formatString(" %5.3f", slb_frac[i]);
@@ -1756,7 +1711,7 @@ static int multi_body_bondeds_count(const gmx_mtop_t* mtop)
 {
     int                  n     = 0;
     gmx_mtop_ilistloop_t iloop = gmx_mtop_ilistloop_init(mtop);
-    int                  nmol;
+    int                  nmol  = 0;
     while (const InteractionLists* ilists = gmx_mtop_ilistloop_next(iloop, &nmol))
     {
         for (auto& ilist : extractILists(*ilists, IF_BOND))
@@ -1773,11 +1728,8 @@ static int multi_body_bondeds_count(const gmx_mtop_t* mtop)
 
 static int dd_getenv(const gmx::MDLogger& mdlog, const char* env_var, int def)
 {
-    char* val;
-    int   nst;
-
-    nst = def;
-    val = getenv(env_var);
+    int   nst = def;
+    char* val = getenv(env_var);
     if (val)
     {
         if (sscanf(val, "%20d", &nst) <= 0)
@@ -1963,8 +1915,8 @@ static gmx_domdec_comm_t* init_dd_comm()
 /* Returns whether mtop contains constraints and/or vsites */
 static bool systemHasConstraintsOrVsites(const gmx_mtop_t& mtop)
 {
-    auto ilistLoop = gmx_mtop_ilistloop_init(mtop);
-    int  nmol;
+    auto* ilistLoop = gmx_mtop_ilistloop_init(mtop);
+    int   nmol      = 0;
     while (const InteractionLists* ilists = gmx_mtop_ilistloop_next(ilistLoop, &nmol))
     {
         if (!extractILists(*ilists, IF_CONSTRAINT | IF_VSITE).empty())
@@ -2184,7 +2136,8 @@ static DDSystemInfo getSystemInfo(const gmx::MDLogger&           mdlog,
         }
         else
         {
-            real r_2b, r_mb;
+            real r_2b = 0;
+            real r_mb = 0;
 
             if (ddRole == DDRole::Master)
             {
@@ -2277,14 +2230,13 @@ static void checkDDGridSetup(const DDGridSetup&   ddGridSetup,
 {
     if (options.numCells[XX] <= 0 && (ddGridSetup.numDomains[XX] == 0))
     {
-        char     buf[STRLEN];
-        gmx_bool bC = (systemInfo.haveSplitConstraints
-                       && systemInfo.constraintCommunicationRange > systemInfo.minCutoffForMultiBody);
-        sprintf(buf,
-                "Change the number of ranks or mdrun option %s%s%s",
-                !bC ? "-rdd" : "-rcon",
-                ddSettings.initialDlbState != DlbState::offUser ? " or -dds" : "",
-                bC ? " or your LINCS settings" : "");
+        const bool  bC = (systemInfo.haveSplitConstraints
+                         && systemInfo.constraintCommunicationRange > systemInfo.minCutoffForMultiBody);
+        std::string message =
+                gmx::formatString("Change the number of ranks or mdrun option %s%s%s",
+                                  !bC ? "-rdd" : "-rcon",
+                                  ddSettings.initialDlbState != DlbState::offUser ? " or -dds" : "",
+                                  bC ? " or your LINCS settings" : "");
 
         gmx_fatal_collective(FARGS,
                              communicator,
@@ -2295,7 +2247,7 @@ static void checkDDGridSetup(const DDGridSetup&   ddGridSetup,
                              "Look in the log file for details on the domain decomposition",
                              numNodes - ddGridSetup.numPmeOnlyRanks,
                              cellsizeLimit,
-                             buf);
+                             message.c_str());
     }
 
     const real acs = average_cellsize_min(ddbox, ddGridSetup.numDomains);
@@ -2552,11 +2504,9 @@ void dd_init_bondeds(FILE*                           fplog,
                      gmx_bool                        bBCheck,
                      gmx::ArrayRef<cginfo_mb_t>      cginfo_mb)
 {
-    gmx_domdec_comm_t* comm;
-
     dd_make_reverse_top(fplog, dd, &mtop, vsite, ir, bBCheck);
 
-    comm = dd->comm;
+    gmx_domdec_comm_t* comm = dd->comm;
 
     if (comm->systemInfo.filterBondedCommunication)
     {
@@ -2578,17 +2528,12 @@ static void writeSettings(gmx::TextWriter*   log,
                           real               dlb_scale,
                           const gmx_ddbox_t* ddbox)
 {
-    gmx_domdec_comm_t* comm;
-    int                d;
-    ivec               np;
-    real               limit, shrink;
-
-    comm = dd->comm;
+    gmx_domdec_comm_t* comm = dd->comm;
 
     if (bDynLoadBal)
     {
         log->writeString("The maximum number of communication pulses is:");
-        for (d = 0; d < dd->ndim; d++)
+        for (int d = 0; d < dd->ndim; d++)
         {
             log->writeStringFormatted(" %c %d", dim2char(dd->dim[d]), comm->cd[d].np_dlb);
         }
@@ -2597,19 +2542,15 @@ static void writeSettings(gmx::TextWriter*   log,
                                 comm->cellsize_limit);
         log->writeLineFormatted("The requested allowed shrink of DD cells (option -dds) is: %.2f", dlb_scale);
         log->writeString("The allowed shrink of domain decomposition cells is:");
-        for (d = 0; d < DIM; d++)
+        for (int d = 0; d < DIM; d++)
         {
             if (dd->numCells[d] > 1)
             {
-                if (d >= ddbox->npbcdim && dd->numCells[d] == 2)
-                {
-                    shrink = 0;
-                }
-                else
-                {
-                    shrink = comm->cellsize_min_dlb[d]
-                             / (ddbox->box_size[d] * ddbox->skew_fac[d] / dd->numCells[d]);
-                }
+                const real shrink =
+                        (d >= ddbox->npbcdim && dd->numCells[d] == 2)
+                                ? 0
+                                : comm->cellsize_min_dlb[d]
+                                          / (ddbox->box_size[d] * ddbox->skew_fac[d] / dd->numCells[d]);
                 log->writeStringFormatted(" %c %.2f", dim2char(d), shrink);
             }
         }
@@ -2617,15 +2558,16 @@ static void writeSettings(gmx::TextWriter*   log,
     }
     else
     {
+        ivec np;
         set_dd_cell_sizes_slb(dd, ddbox, setcellsizeslbPULSE_ONLY, np);
         log->writeString("The initial number of communication pulses is:");
-        for (d = 0; d < dd->ndim; d++)
+        for (int d = 0; d < dd->ndim; d++)
         {
             log->writeStringFormatted(" %c %d", dim2char(dd->dim[d]), np[dd->dim[d]]);
         }
         log->ensureLineBreak();
         log->writeString("The initial domain decomposition cell size is:");
-        for (d = 0; d < DIM; d++)
+        for (int d = 0; d < DIM; d++)
         {
             if (dd->numCells[d] > 1)
             {
@@ -2657,6 +2599,7 @@ static void writeSettings(gmx::TextWriter*   log,
         log->writeLineFormatted(
                 "%40s  %-7s %6.3f nm", "non-bonded interactions", "", comm->systemInfo.cutoff);
 
+        real limit = 0;
         if (bDynLoadBal)
         {
             limit = dd->comm->cellsize_limit;
@@ -2670,7 +2613,7 @@ static void writeSettings(gmx::TextWriter*   log,
                         "deformation)");
             }
             limit = dd->comm->cellsize_min[XX];
-            for (d = 1; d < DIM; d++)
+            for (int d = 1; d < DIM; d++)
             {
                 limit = std::min(limit, dd->comm->cellsize_min[d]);
             }
@@ -2731,13 +2674,11 @@ static void set_cell_limits_dlb(const gmx::MDLogger& mdlog,
                                 const t_inputrec*    ir,
                                 const gmx_ddbox_t*   ddbox)
 {
-    gmx_domdec_comm_t* comm;
-    int                d, dim, npulse, npulse_d_max, npulse_d;
-    gmx_bool           bNoCutOff;
+    int npulse = 0, npulse_d_max = 0, npulse_d = 0;
 
-    comm = dd->comm;
+    gmx_domdec_comm_t* comm = dd->comm;
 
-    bNoCutOff = (ir->rvdw == 0 || ir->rcoulomb == 0);
+    bool bNoCutOff = (ir->rvdw == 0 || ir->rcoulomb == 0);
 
     /* Determine the maximum number of comm. pulses in one dimension */
 
@@ -2769,9 +2710,9 @@ static void set_cell_limits_dlb(const gmx::MDLogger& mdlog,
     {
         /* See if we can do with less pulses, based on dlb_scale */
         npulse_d_max = 0;
-        for (d = 0; d < dd->ndim; d++)
+        for (int d = 0; d < dd->ndim; d++)
         {
-            dim      = dd->dim[d];
+            int dim  = dd->dim[d];
             npulse_d = static_cast<int>(
                     1
                     + dd->numCells[dim] * comm->systemInfo.cutoff
@@ -2782,7 +2723,7 @@ static void set_cell_limits_dlb(const gmx::MDLogger& mdlog,
     }
 
     /* This env var can override npulse */
-    d = dd_getenv(mdlog, "GMX_DD_NPULSE", 0);
+    int d = dd_getenv(mdlog, "GMX_DD_NPULSE", 0);
     if (d > 0)
     {
         npulse = d;
@@ -2790,7 +2731,7 @@ static void set_cell_limits_dlb(const gmx::MDLogger& mdlog,
 
     comm->maxpulse       = 1;
     comm->bVacDLBNoLimit = (ir->pbcType == PbcType::No);
-    for (d = 0; d < dd->ndim; d++)
+    for (int d = 0; d < dd->ndim; d++)
     {
         comm->cd[d].np_dlb = std::min(npulse, dd->numCells[dd->dim[d]] - 1);
         comm->maxpulse     = std::max(comm->maxpulse, comm->cd[d].np_dlb);
@@ -2807,7 +2748,7 @@ static void set_cell_limits_dlb(const gmx::MDLogger& mdlog,
     }
     comm->cellsize_limit = std::max(comm->cellsize_limit, comm->cutoff_mbody);
     /* Set the minimum cell size for each DD dimension */
-    for (d = 0; d < dd->ndim; d++)
+    for (int d = 0; d < dd->ndim; d++)
     {
         if (comm->bVacDLBNoLimit || comm->cd[d].np_dlb * comm->cellsize_limit >= comm->systemInfo.cutoff)
         {
@@ -2886,16 +2827,10 @@ static void set_ddgrid_parameters(const gmx::MDLogger& mdlog,
 
     logSettings(mdlog, dd, mtop, ir, dlb_scale, ddbox);
 
-    real vol_frac;
-    if (ir->pbcType == PbcType::No)
-    {
-        vol_frac = 1 - 1 / static_cast<double>(dd->nnodes);
-    }
-    else
-    {
-        vol_frac = (1 + comm_box_frac(dd->numCells, comm->systemInfo.cutoff, *ddbox))
-                   / static_cast<double>(dd->nnodes);
-    }
+    const real vol_frac = (ir->pbcType == PbcType::No)
+                                  ? (1 - 1 / static_cast<double>(dd->nnodes))
+                                  : ((1 + comm_box_frac(dd->numCells, comm->systemInfo.cutoff, *ddbox))
+                                     / static_cast<double>(dd->nnodes));
     if (debug)
     {
         fprintf(debug, "Volume fraction for all DD zones: %f\n", vol_frac);
@@ -3153,9 +3088,7 @@ DomainDecompositionBuilder::~DomainDecompositionBuilder() = default;
 static gmx_bool test_dd_cutoff(const t_commrec* cr, const matrix box, gmx::ArrayRef<const gmx::RVec> x, real cutoffRequested)
 {
     gmx_ddbox_t ddbox;
-    int         d, dim, np;
-    real        inv_cell_size;
-    int         LocallyLimited;
+    int         LocallyLimited = 0;
 
     const auto* dd = cr->dd;
 
@@ -3163,17 +3096,17 @@ static gmx_bool test_dd_cutoff(const t_commrec* cr, const matrix box, gmx::Array
 
     LocallyLimited = 0;
 
-    for (d = 0; d < dd->ndim; d++)
+    for (int d = 0; d < dd->ndim; d++)
     {
-        dim = dd->dim[d];
+        const int dim = dd->dim[d];
 
-        inv_cell_size = DD_CELL_MARGIN * dd->numCells[dim] / ddbox.box_size[dim];
+        real inv_cell_size = DD_CELL_MARGIN * dd->numCells[dim] / ddbox.box_size[dim];
         if (dd->unitCellInfo.ddBoxIsDynamic)
         {
             inv_cell_size *= DD_PRES_SCALE_MARGIN;
         }
 
-        np = 1 + static_cast<int>(cutoffRequested * inv_cell_size * ddbox.skew_fac[dim]);
+        const int np = 1 + static_cast<int>(cutoffRequested * inv_cell_size * ddbox.skew_fac[dim]);
 
         if (!isDlbDisabled(dd->comm) && (dim < ddbox.npbcdim) && (dd->comm->cd[d].np_dlb > 0))
         {
@@ -3218,9 +3151,7 @@ static gmx_bool test_dd_cutoff(const t_commrec* cr, const matrix box, gmx::Array
 
 gmx_bool change_dd_cutoff(t_commrec* cr, const matrix box, gmx::ArrayRef<const gmx::RVec> x, real cutoffRequested)
 {
-    gmx_bool bCutoffAllowed;
-
-    bCutoffAllowed = test_dd_cutoff(cr, box, x, cutoffRequested);
+    bool bCutoffAllowed = test_dd_cutoff(cr, box, x, cutoffRequested);
 
     if (bCutoffAllowed)
     {
index 306db7ea39c4d9b0b5f8517b562c0d60986173c7..4c4c81836374db732766953e56e99ba510170015 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 2006,2007,2008,2009,2010 by the GROMACS development team.
  * Copyright (c) 2012,2013,2014,2015,2016 by the GROMACS development team.
- * Copyright (c) 2017,2018,2019,2020, by the GROMACS development team, led by
+ * Copyright (c) 2017,2018,2019,2020,2021, 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.
@@ -210,15 +210,7 @@ static void walk_out(int                       con,
             {
                 /* Walk further */
                 const int* iap = constr_iatomptr(ia1, ia2, coni);
-                int        b;
-                if (a == iap[1])
-                {
-                    b = iap[2];
-                }
-                else
-                {
-                    b = iap[1];
-                }
+                const int  b   = (a == iap[1]) ? iap[2] : iap[1];
                 if (!ga2la.findHome(offset + b))
                 {
                     walk_out(coni, con_offset, b, offset, nrec - 1, ia1, ia2, at2con, ga2la, FALSE, dc, dcc, il_local, ireq);
@@ -246,8 +238,8 @@ static void atoms_to_settles(gmx_domdec_t*                         dd,
     {
         if (GET_CGINFO_SETTLE(cginfo[a]))
         {
-            int a_gl = dd->globalAtomIndices[a];
-            int a_mol;
+            int a_gl  = dd->globalAtomIndices[a];
+            int a_mol = 0;
             mtopGetMolblockIndex(mtop, a_gl, &mb, nullptr, &a_mol);
 
             const gmx_molblock_t* molb   = &mtop->molblock[mb];
@@ -326,8 +318,8 @@ static void atoms_to_constraints(gmx_domdec_t*                         dd,
     {
         if (GET_CGINFO_CONSTR(cginfo[a]))
         {
-            int a_gl = dd->globalAtomIndices[a];
-            int molnr, a_mol;
+            int a_gl  = dd->globalAtomIndices[a];
+            int molnr = 0, a_mol = 0;
             mtopGetMolblockIndex(mtop, a_gl, &mb, &molnr, &a_mol);
 
             const gmx_molblock_t& molb = mtop->molblock[mb];
@@ -347,8 +339,8 @@ static void atoms_to_constraints(gmx_domdec_t*                         dd,
             const auto& at2con = at2con_mt[molb.type];
             for (const int con : at2con[a_mol])
             {
-                const int* iap = constr_iatomptr(ia1, ia2, con);
-                int        b_mol;
+                const int* iap   = constr_iatomptr(ia1, ia2, con);
+                int        b_mol = 0;
                 if (a_mol == iap[1])
                 {
                     b_mol = iap[2];
@@ -411,11 +403,6 @@ int dd_make_local_constraints(gmx_domdec_t*                  dd,
                               int                            nrec,
                               gmx::ArrayRef<InteractionList> il_local)
 {
-    gmx_domdec_constraints_t* dc;
-    InteractionList *         ilc_local, *ils_local;
-    gmx::HashedMap<int>*      ga2la_specat;
-    int                       at_end, i, j;
-
     // This code should not be called unless this condition is true,
     // because that's the only time init_domdec_constraints is
     // called...
@@ -431,10 +418,10 @@ int dd_make_local_constraints(gmx_domdec_t*                  dd,
     // true. dd->constraint_comm is unilaterally dereferenced before
     // the call to atoms_to_settles.
 
-    dc = dd->constraints;
+    gmx_domdec_constraints_t* dc = dd->constraints;
 
-    ilc_local = &il_local[F_CONSTR];
-    ils_local = &il_local[F_SETTLE];
+    InteractionList* ilc_local = &il_local[F_CONSTR];
+    InteractionList* ils_local = &il_local[F_SETTLE];
 
     dc->ncon = 0;
     gmx::ArrayRef<const ListOfLists<int>> at2con_mt;
@@ -465,12 +452,10 @@ int dd_make_local_constraints(gmx_domdec_t*                  dd,
     }
     else
     {
-        int t0_set;
-
         /* Do the constraints, if present, on the first thread.
          * Do the settles on all other threads.
          */
-        t0_set = ((!at2con_mt.empty() && dc->nthread > 1) ? 1 : 0);
+        const int t0_set = ((!at2con_mt.empty() && dc->nthread > 1) ? 1 : 0);
 
 #pragma omp parallel for num_threads(dc->nthread) schedule(static)
         for (int thread = 0; thread < dc->nthread; thread++)
@@ -484,23 +469,13 @@ int dd_make_local_constraints(gmx_domdec_t*                  dd,
 
                 if (thread >= t0_set)
                 {
-                    int              cg0, cg1;
-                    InteractionList* ilst;
-
                     /* Distribute the settle check+assignments over
                      * dc->nthread or dc->nthread-1 threads.
                      */
-                    cg0 = (dd->ncg_home * (thread - t0_set)) / (dc->nthread - t0_set);
-                    cg1 = (dd->ncg_home * (thread - t0_set + 1)) / (dc->nthread - t0_set);
+                    int cg0 = (dd->ncg_home * (thread - t0_set)) / (dc->nthread - t0_set);
+                    int cg1 = (dd->ncg_home * (thread - t0_set + 1)) / (dc->nthread - t0_set);
 
-                    if (thread == t0_set)
-                    {
-                        ilst = ils_local;
-                    }
-                    else
-                    {
-                        ilst = &dc->ils[thread];
-                    }
+                    InteractionList* ilst = (thread == t0_set) ? ils_local : &dc->ils[thread];
                     ilst->clear();
 
                     std::vector<int>& ireqt = dc->requestedGlobalAtomIndices[thread];
@@ -533,10 +508,9 @@ int dd_make_local_constraints(gmx_domdec_t*                  dd,
         }
     }
 
+    int at_end = 0;
     if (dd->constraint_comm)
     {
-        int nral1;
-
         at_end = setup_specat_communication(dd,
                                             ireq,
                                             dd->constraint_comm,
@@ -547,13 +521,13 @@ int dd_make_local_constraints(gmx_domdec_t*                  dd,
                                             " or lincs-order");
 
         /* Fill in the missing indices */
-        ga2la_specat = dd->constraints->ga2la.get();
+        gmx::HashedMap<int>* ga2la_specat = dd->constraints->ga2la.get();
 
-        nral1 = 1 + NRAL(F_CONSTR);
-        for (i = 0; i < ilc_local->size(); i += nral1)
+        int nral1 = 1 + NRAL(F_CONSTR);
+        for (int i = 0; i < ilc_local->size(); i += nral1)
         {
             int* iap = ilc_local->iatoms.data() + i;
-            for (j = 1; j < nral1; j++)
+            for (int j = 1; j < nral1; j++)
             {
                 if (iap[j] < 0)
                 {
@@ -565,10 +539,10 @@ int dd_make_local_constraints(gmx_domdec_t*                  dd,
         }
 
         nral1 = 1 + NRAL(F_SETTLE);
-        for (i = 0; i < ils_local->size(); i += nral1)
+        for (int i = 0; i < ils_local->size(); i += nral1)
         {
             int* iap = ils_local->iatoms.data() + i;
-            for (j = 1; j < nral1; j++)
+            for (int j = 1; j < nral1; j++)
             {
                 if (iap[j] < 0)
                 {
@@ -590,16 +564,13 @@ int dd_make_local_constraints(gmx_domdec_t*                  dd,
 
 void init_domdec_constraints(gmx_domdec_t* dd, const gmx_mtop_t* mtop)
 {
-    gmx_domdec_constraints_t* dc;
-    const gmx_molblock_t*     molb;
-
     if (debug)
     {
         fprintf(debug, "Begin init_domdec_constraints\n");
     }
 
-    dd->constraints = new gmx_domdec_constraints_t;
-    dc              = dd->constraints;
+    dd->constraints              = new gmx_domdec_constraints_t;
+    gmx_domdec_constraints_t* dc = dd->constraints;
 
     dc->molb_con_offset.resize(mtop->molblock.size());
     dc->molb_ncon_mol.resize(mtop->molblock.size());
@@ -607,9 +578,9 @@ void init_domdec_constraints(gmx_domdec_t* dd, const gmx_mtop_t* mtop)
     int ncon = 0;
     for (size_t mb = 0; mb < mtop->molblock.size(); mb++)
     {
-        molb                    = &mtop->molblock[mb];
-        dc->molb_con_offset[mb] = ncon;
-        dc->molb_ncon_mol[mb]   = mtop->moltype[molb->type].ilist[F_CONSTR].size() / 3
+        const gmx_molblock_t* molb = &mtop->molblock[mb];
+        dc->molb_con_offset[mb]    = ncon;
+        dc->molb_ncon_mol[mb]      = mtop->moltype[molb->type].ilist[F_CONSTR].size() / 3
                                 + mtop->moltype[molb->type].ilist[F_CONSTRNC].size() / 3;
         ncon += molb->nmol * dc->molb_ncon_mol[mb];
     }
index 0a97f0a04b776d9352b198edb9fb0caa87d55e17..c6363362febb09c5786eae80b5a315f399b8ee80 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2008-2019,2020, by the GROMACS development team, led by
+ * Copyright (c) 2008-2019,2020,2021, 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.
@@ -157,12 +157,11 @@ void dd_sendrecv2_rvec(const struct gmx_domdec_t gmx_unused* dd,
                        int gmx_unused n_r_bw)
 {
 #if GMX_MPI
-    int         rank_fw, rank_bw, nreq;
     MPI_Request req[4];
     MPI_Status  stat[4];
 
-    rank_fw = dd->neighbor[ddimind][0];
-    rank_bw = dd->neighbor[ddimind][1];
+    int rank_fw = dd->neighbor[ddimind][0];
+    int rank_bw = dd->neighbor[ddimind][1];
 
     if (!dd->comm->ddSettings.useSendRecv2)
     {
@@ -174,7 +173,7 @@ void dd_sendrecv2_rvec(const struct gmx_domdec_t gmx_unused* dd,
          * are slower.
          * SendRecv2 can be turned on with the env.var. GMX_DD_SENDRECV2
          */
-        nreq = 0;
+        int nreq = 0;
         if (n_r_fw)
         {
             MPI_Irecv(buf_r_fw[0], n_r_fw * sizeof(rvec), MPI_BYTE, rank_bw, 0, dd->mpi_comm_all, &req[nreq++]);
@@ -294,7 +293,7 @@ void dd_scatterv(const gmx_domdec_t gmx_unused* dd,
                  void*           rbuf)
 {
 #if GMX_MPI
-    int dum;
+    int dum = 0;
 
     if (dd->nnodes > 1)
     {
@@ -326,7 +325,7 @@ void dd_gatherv(const gmx_domdec_t gmx_unused* dd,
                 void gmx_unused* rbuf)
 {
 #if GMX_MPI
-    int dum;
+    int dum = 0;
 
     if (scount == 0)
     {
index 7b8d329b4ab45dbcd736e06640d746e2632d396a..f33b56f1013e7cded1efbdf05dae2ada110865a4 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 2008,2009,2010,2011,2012 by the GROMACS development team.
  * Copyright (c) 2013,2014,2015,2017,2018 by the GROMACS development team.
- * Copyright (c) 2019,2020, by the GROMACS development team, led by
+ * Copyright (c) 2019,2020,2021, 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.
@@ -72,6 +72,7 @@
 
 #include "box.h"
 #include "domdec_internal.h"
+#include "math.h"
 #include "utility.h"
 
 // TODO remove this when moving domdec into gmx namespace
@@ -129,10 +130,8 @@ static int largest_divisor(int n)
 /*! \brief Compute largest common divisor of \p n1 and \b n2 */
 static int lcd(int n1, int n2)
 {
-    int d, i;
-
-    d = 1;
-    for (i = 2; (i <= n1 && i <= n2); i++)
+    int d = 1;
+    for (int i = 2; (i <= n1 && i <= n2); i++)
     {
         if (n1 % i == 0 && n2 % i == 0)
         {
@@ -190,10 +189,7 @@ static int guess_npme(const gmx::MDLogger& mdlog,
                       const matrix         box,
                       int                  nrank_tot)
 {
-    float ratio;
-    int   npme;
-
-    ratio = pme_load_estimate(mtop, ir, box);
+    float ratio = pme_load_estimate(mtop, ir, box);
 
     GMX_LOG(mdlog.info).appendTextFormatted("Guess for relative PME load: %.2f", ratio);
 
@@ -216,7 +212,7 @@ static int guess_npme(const gmx::MDLogger& mdlog,
      * We start with a minimum PME node fraction of 1/16
      * and avoid ratios which lead to large prime factors in nnodes-npme.
      */
-    npme = (nrank_tot + 15) / 16;
+    int npme = (nrank_tot + 15) / 16;
     while (npme <= nrank_tot / 3)
     {
         if (nrank_tot % npme == 0)
@@ -280,28 +276,26 @@ static int div_up(int n, int f)
 
 real comm_box_frac(const gmx::IVec& dd_nc, real cutoff, const gmx_ddbox_t& ddbox)
 {
-    int  i, j, k;
     rvec nw;
-    real comm_vol;
 
-    for (i = 0; i < DIM; i++)
+    for (int i = 0; i < DIM; i++)
     {
         real bt = ddbox.box_size[i] * ddbox.skew_fac[i];
         nw[i]   = dd_nc[i] * cutoff / bt;
     }
 
-    comm_vol = 0;
-    for (i = 0; i < DIM; i++)
+    real comm_vol = 0;
+    for (int i = 0; i < DIM; i++)
     {
         if (dd_nc[i] > 1)
         {
             comm_vol += nw[i];
-            for (j = i + 1; j < DIM; j++)
+            for (int j = i + 1; j < DIM; j++)
             {
                 if (dd_nc[j] > 1)
                 {
                     comm_vol += nw[i] * nw[j] * M_PI / 4;
-                    for (k = j + 1; k < DIM; k++)
+                    for (int k = j + 1; k < DIM; k++)
                     {
                         if (dd_nc[k] > 1)
                         {
@@ -333,9 +327,7 @@ static gmx_bool inhomogeneous_z(const t_inputrec& ir)
 static float comm_pme_cost_vol(int npme, int a, int b, int c)
 {
     /* We use a float here, since an integer might overflow */
-    float comm_vol;
-
-    comm_vol = npme - 1;
+    float comm_vol = npme - 1;
     comm_vol *= npme;
     comm_vol *= div_up(a, npme);
     comm_vol *= div_up(b, npme);
@@ -356,9 +348,7 @@ static float comm_cost_est(real               limit,
                            const gmx::IVec&   nc)
 {
     gmx::IVec npme = { 1, 1, 1 };
-    int       i, j, nk, overlap;
     rvec      bt;
-    float     comm_vol, comm_vol_xf, comm_pme, cost_pbcdx;
     /* This is the cost of a pbc_dx call relative to the cost
      * of communicating the coordinate and force of an atom.
      * This will be machine dependent.
@@ -366,7 +356,6 @@ static float comm_cost_est(real               limit,
      */
     float pbcdx_rect_fac = 0.1;
     float pbcdx_tric_fac = 0.2;
-    float temp;
 
     /* Check the DD algorithm restrictions */
     if ((ir.pbcType == PbcType::XY && ir.nwall < 2 && nc[ZZ] > 1)
@@ -383,9 +372,9 @@ static float comm_cost_est(real               limit,
     assert(ddbox.npbcdim <= DIM);
 
     /* Check if the triclinic requirements are met */
-    for (i = 0; i < DIM; i++)
+    for (int i = 0; i < DIM; i++)
     {
-        for (j = i + 1; j < ddbox.npbcdim; j++)
+        for (int j = i + 1; j < ddbox.npbcdim; j++)
         {
             if (box[j][i] != 0 || ir.deform[j][i] != 0 || (ir.epc != epcNO && ir.compress[j][i] != 0))
             {
@@ -397,7 +386,7 @@ static float comm_cost_est(real               limit,
         }
     }
 
-    for (i = 0; i < DIM; i++)
+    for (int i = 0; i < DIM; i++)
     {
         bt[i] = ddbox.box_size[i] * ddbox.skew_fac[i];
 
@@ -462,9 +451,9 @@ static float comm_cost_est(real               limit,
      * for the smallest index, so the decomposition does not
      * depend sensitively on the rounding of the box elements.
      */
-    for (i = 0; i < DIM; i++)
+    for (int i = 0; i < DIM; i++)
     {
-        for (j = i + 1; j < DIM; j++)
+        for (int j = i + 1; j < DIM; j++)
         {
             /* Check if the box size is nearly identical,
              * in that case we prefer nx > ny  and ny > nz.
@@ -493,31 +482,26 @@ static float comm_cost_est(real               limit,
      * and the "back"-communication cost is identical to the forward cost.
      */
 
-    comm_vol = comm_box_frac(nc, cutoff, ddbox);
+    float comm_vol = comm_box_frac(nc, cutoff, ddbox);
 
-    comm_pme = 0;
-    for (i = 0; i < 2; i++)
+    float comm_pme = 0;
+    for (int i = 0; i < 2; i++)
     {
         /* Determine the largest volume for PME x/f redistribution */
         if (nc[i] % npme[i] != 0)
         {
-            if (nc[i] > npme[i])
-            {
-                comm_vol_xf = (npme[i] == 2 ? 1.0 / 3.0 : 0.5);
-            }
-            else
-            {
-                comm_vol_xf = 1.0 - lcd(nc[i], npme[i]) / static_cast<double>(npme[i]);
-            }
+            float comm_vol_xf = (nc[i] > npme[i])
+                                        ? (npme[i] == 2 ? 1.0 / 3.0 : 0.5)
+                                        : (1.0 - lcd(nc[i], npme[i]) / static_cast<double>(npme[i]));
             comm_pme += 3 * natoms * comm_vol_xf;
         }
 
         /* Grid overlap communication */
         if (npme[i] > 1)
         {
-            nk      = (i == 0 ? ir.nkx : ir.nky);
-            overlap = (nk % npme[i] == 0 ? ir.pme_order - 1 : ir.pme_order);
-            temp    = npme[i];
+            const int nk      = (i == 0 ? ir.nkx : ir.nky);
+            const int overlap = (nk % npme[i] == 0 ? ir.pme_order - 1 : ir.pme_order);
+            float     temp    = npme[i];
             temp *= overlap;
             temp *= ir.nkx;
             temp *= ir.nky;
@@ -532,7 +516,7 @@ static float comm_cost_est(real               limit,
     comm_pme += comm_pme_cost_vol(npme[XX], ir.nkx, ir.nky, ir.nkz);
 
     /* Add cost of pbc_dx for bondeds */
-    cost_pbcdx = 0;
+    float cost_pbcdx = 0;
     if ((nc[XX] == 1 || nc[YY] == 1) || (nc[ZZ] == 1 && ir.pbcType != PbcType::XY))
     {
         if ((ddbox.tric_dir[XX] && nc[XX] == 1) || (ddbox.tric_dir[YY] && nc[YY] == 1))
@@ -579,14 +563,12 @@ static void assign_factors(const real         limit,
                            gmx::IVec*         irTryPtr,
                            gmx::IVec*         opt)
 {
-    int        x, y, i;
-    float      ce;
     gmx::IVec& ir_try = *irTryPtr;
 
     if (ndiv == 0)
     {
 
-        ce = comm_cost_est(limit, cutoff, box, ddbox, natoms, ir, pbcdxr, npme, ir_try);
+        const float ce = comm_cost_est(limit, cutoff, box, ddbox, natoms, ir, pbcdxr, npme, ir_try);
         if (ce >= 0
             && ((*opt)[XX] == 0
                 || ce < comm_cost_est(limit, cutoff, box, ddbox, natoms, ir, pbcdxr, npme, *opt)))
@@ -597,19 +579,19 @@ static void assign_factors(const real         limit,
         return;
     }
 
-    for (x = mdiv[0]; x >= 0; x--)
+    for (int x = mdiv[0]; x >= 0; x--)
     {
-        for (i = 0; i < x; i++)
+        for (int i = 0; i < x; i++)
         {
             ir_try[XX] *= div[0];
         }
-        for (y = mdiv[0] - x; y >= 0; y--)
+        for (int y = mdiv[0] - x; y >= 0; y--)
         {
-            for (i = 0; i < y; i++)
+            for (int i = 0; i < y; i++)
             {
                 ir_try[YY] *= div[0];
             }
-            for (i = 0; i < mdiv[0] - x - y; i++)
+            for (int i = 0; i < mdiv[0] - x - y; i++)
             {
                 ir_try[ZZ] *= div[0];
             }
@@ -618,16 +600,16 @@ static void assign_factors(const real         limit,
             assign_factors(
                     limit, cutoff, box, ddbox, natoms, ir, pbcdxr, npme, ndiv - 1, div + 1, mdiv + 1, irTryPtr, opt);
 
-            for (i = 0; i < mdiv[0] - x - y; i++)
+            for (int i = 0; i < mdiv[0] - x - y; i++)
             {
                 ir_try[ZZ] /= div[0];
             }
-            for (i = 0; i < y; i++)
+            for (int i = 0; i < y; i++)
             {
                 ir_try[YY] /= div[0];
             }
         }
-        for (i = 0; i < x; i++)
+        for (int i = 0; i < x; i++)
         {
             ir_try[XX] /= div[0];
         }
@@ -649,7 +631,7 @@ static gmx::IVec optimizeDDCells(const gmx::MDLogger& mdlog,
                                  const t_inputrec&    ir,
                                  const DDSystemInfo&  systemInfo)
 {
-    double pbcdxr;
+    double pbcdxr = 0;
 
     const int numPPRanks = numRanksRequested - numPmeOnlyRanks;
 
@@ -817,8 +799,8 @@ static int getNumPmeOnlyRanksToUse(const gmx::MDLogger& mdlog,
                                    const matrix         box,
                                    const int            numRanksRequested)
 {
-    int         numPmeOnlyRanks;
-    const char* extraMessage = "";
+    int         numPmeOnlyRanks = 0;
+    const char* extraMessage    = "";
 
     if (options.numCells[XX] > 0)
     {
index 89ac9df3f8e5c5a0b782671449756762f08506e2..5a87c7d339c857fb3d61dfa8823ef0d6caebb19b 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 2006,2007,2008,2009,2010 by the GROMACS development team.
  * Copyright (c) 2012,2013,2014,2015,2017 by the GROMACS development team.
- * Copyright (c) 2018,2019,2020, by the GROMACS development team, led by
+ * Copyright (c) 2018,2019,2020,2021, 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 dd_move_f_specat(const gmx_domdec_t* dd, gmx_domdec_specat_comm_t* spac, rvec* f, rvec* fshift)
 {
-    gmx_specatsend_t* spas;
-    rvec*             vbuf;
-    int               n, n0, n1, dim, dir;
-    ivec              vis;
-    int               is;
-    gmx_bool          bPBC, bScrew;
+    ivec vis;
 
-    n = spac->at_end;
+    int n = spac->at_end;
     for (int d = dd->ndim - 1; d >= 0; d--)
     {
-        dim = dd->dim[d];
+        const int dim = dd->dim[d];
         if (dd->numCells[dim] > 2)
         {
             /* Pulse the grid forward and backward */
-            spas = spac->spas[d];
-            n0   = spas[0].nrecv;
-            n1   = spas[1].nrecv;
+            gmx_specatsend_t* spas = spac->spas[d];
+            int               n0   = spas[0].nrecv;
+            int               n1   = spas[1].nrecv;
             n -= n1 + n0;
-            vbuf = as_rvec_array(spac->vbuf.data());
+            rvec* vbuf = as_rvec_array(spac->vbuf.data());
             /* Send and receive the coordinates */
             dd_sendrecv2_rvec(dd,
                               d,
@@ -97,13 +92,13 @@ void dd_move_f_specat(const gmx_domdec_t* dd, gmx_domdec_specat_comm_t* spac, rv
                               n1,
                               vbuf + spas[0].a.size(),
                               spas[1].a.size());
-            for (dir = 0; dir < 2; dir++)
+            for (int dir = 0; dir < 2; dir++)
             {
-                bPBC   = ((dir == 0 && dd->ci[dim] == 0)
-                        || (dir == 1 && dd->ci[dim] == dd->numCells[dim] - 1));
-                bScrew = (bPBC && dd->unitCellInfo.haveScrewPBC && dim == XX);
+                bool bPBC   = ((dir == 0 && dd->ci[dim] == 0)
+                             || (dir == 1 && dd->ci[dim] == dd->numCells[dim] - 1));
+                bool bScrew = (bPBC && dd->unitCellInfo.haveScrewPBC && dim == XX);
 
-                spas = &spac->spas[d][dir];
+                gmx_specatsend_t* spas = &spac->spas[d][dir];
                 /* Sum the buffer into the required forces */
                 if (!bPBC || (!bScrew && fshift == nullptr))
                 {
@@ -117,7 +112,7 @@ void dd_move_f_specat(const gmx_domdec_t* dd, gmx_domdec_specat_comm_t* spac, rv
                 {
                     clear_ivec(vis);
                     vis[dim] = (dir == 0 ? 1 : -1);
-                    is       = IVEC2IS(vis);
+                    int is   = IVEC2IS(vis);
                     if (!bScrew)
                     {
                         /* Sum and add to shift forces */
@@ -149,7 +144,7 @@ void dd_move_f_specat(const gmx_domdec_t* dd, gmx_domdec_specat_comm_t* spac, rv
         else
         {
             /* Two cells, so we only need to communicate one way */
-            spas = &spac->spas[d][0];
+            gmx_specatsend_t* spas = &spac->spas[d][0];
             n -= spas->nrecv;
             /* Send and receive the coordinates */
             ddSendrecv(dd, d, dddirForward, f + n, spas->nrecv, as_rvec_array(spac->vbuf.data()), spas->a.size());
@@ -187,49 +182,43 @@ void dd_move_x_specat(const gmx_domdec_t*       dd,
                       rvec*                     x1,
                       gmx_bool                  bX1IsCoord)
 {
-    gmx_specatsend_t* spas;
-    int               nvec, v, n, nn, ns0, ns1, nr0, nr1, nr, d, dim, dir, i;
-    gmx_bool          bPBC, bScrew = FALSE;
-    rvec              shift = { 0, 0, 0 };
+    rvec shift = { 0, 0, 0 };
 
-    nvec = 1;
+    int nvec = 1;
     if (x1 != nullptr)
     {
         nvec++;
     }
 
-    n = spac->at_start;
-    for (d = 0; d < dd->ndim; d++)
+    int n = spac->at_start;
+    for (int d = 0; d < dd->ndim; d++)
     {
-        dim = dd->dim[d];
+        int dim = dd->dim[d];
         if (dd->numCells[dim] > 2)
         {
             /* Pulse the grid forward and backward */
             rvec* vbuf = as_rvec_array(spac->vbuf.data());
-            for (dir = 0; dir < 2; dir++)
+            for (int dir = 0; dir < 2; dir++)
             {
+                bool bPBC   = false;
+                bool bScrew = false;
                 if (dir == 0 && dd->ci[dim] == 0)
                 {
-                    bPBC   = TRUE;
+                    bPBC   = true;
                     bScrew = (dd->unitCellInfo.haveScrewPBC && dim == XX);
                     copy_rvec(box[dim], shift);
                 }
                 else if (dir == 1 && dd->ci[dim] == dd->numCells[dim] - 1)
                 {
-                    bPBC   = TRUE;
+                    bPBC   = true;
                     bScrew = (dd->unitCellInfo.haveScrewPBC && dim == XX);
-                    for (i = 0; i < DIM; i++)
+                    for (int i = 0; i < DIM; i++)
                     {
                         shift[i] = -box[dim][i];
                     }
                 }
-                else
-                {
-                    bPBC   = FALSE;
-                    bScrew = FALSE;
-                }
-                spas = &spac->spas[d][dir];
-                for (v = 0; v < nvec; v++)
+                gmx_specatsend_t* spas = &spac->spas[d][dir];
+                for (int v = 0; v < nvec; v++)
                 {
                     rvec* x = (v == 0 ? x0 : x1);
                     /* Copy the required coordinates to the send buffer */
@@ -265,11 +254,11 @@ void dd_move_x_specat(const gmx_domdec_t*       dd,
                 }
             }
             /* Send and receive the coordinates */
-            spas = spac->spas[d];
-            ns0  = spas[0].a.size();
-            nr0  = spas[0].nrecv;
-            ns1  = spas[1].a.size();
-            nr1  = spas[1].nrecv;
+            gmx_specatsend_t* spas = spac->spas[d];
+            int               ns0  = spas[0].a.size();
+            int               nr0  = spas[0].nrecv;
+            int               ns1  = spas[1].a.size();
+            int               nr1  = spas[1].nrecv;
             if (nvec == 1)
             {
                 rvec* vbuf = as_rvec_array(spac->vbuf.data());
@@ -283,14 +272,14 @@ void dd_move_x_specat(const gmx_domdec_t*       dd,
                 dd_sendrecv2_rvec(
                         dd, d, vbuf + 2 * ns0, 2 * ns1, rbuf, 2 * nr1, vbuf, 2 * ns0, rbuf + 2 * nr1, 2 * nr0);
                 /* Split the buffer into the two vectors */
-                nn = n;
-                for (dir = 1; dir >= 0; dir--)
+                int nn = n;
+                for (int dir = 1; dir >= 0; dir--)
                 {
-                    nr = spas[dir].nrecv;
-                    for (v = 0; v < 2; v++)
+                    int nr = spas[dir].nrecv;
+                    for (int v = 0; v < 2; v++)
                     {
                         rvec* x = (v == 0 ? x0 : x1);
-                        for (i = 0; i < nr; i++)
+                        for (int i = 0; i < nr; i++)
                         {
                             copy_rvec(*rbuf, x[nn + i]);
                             rbuf++;
@@ -303,10 +292,10 @@ void dd_move_x_specat(const gmx_domdec_t*       dd,
         }
         else
         {
-            spas = &spac->spas[d][0];
+            gmx_specatsend_t* spas = &spac->spas[d][0];
             /* Copy the required coordinates to the send buffer */
             rvec* vbuf = as_rvec_array(spac->vbuf.data());
-            for (v = 0; v < nvec; v++)
+            for (int v = 0; v < nvec; v++)
             {
                 rvec* x = (v == 0 ? x0 : x1);
                 if (dd->unitCellInfo.haveScrewPBC && dim == XX
@@ -345,11 +334,11 @@ void dd_move_x_specat(const gmx_domdec_t*       dd,
                 rvec* rbuf = as_rvec_array(spac->vbuf2.data());
                 ddSendrecv(dd, d, dddirBackward, vbuf, 2 * spas->a.size(), rbuf, 2 * spas->nrecv);
                 /* Split the buffer into the two vectors */
-                nr = spas[0].nrecv;
-                for (v = 0; v < 2; v++)
+                int nr = spas[0].nrecv;
+                for (int v = 0; v < 2; v++)
                 {
                     rvec* x = (v == 0 ? x0 : x1);
-                    for (i = 0; i < nr; i++)
+                    for (int i = 0; i < nr; i++)
                     {
                         copy_rvec(*rbuf, x[n + i]);
                         rbuf++;
@@ -370,11 +359,8 @@ int setup_specat_communication(gmx_domdec_t*             dd,
                                const char*               specat_type,
                                const char*               add_err)
 {
-    int               nsend[2], nlast, nsend_zero[2] = { 0, 0 }, *nsend_ptr;
-    int               dim, ndir, nr, ns, nrecv_local, n0, start, buf[2];
-    int               nat_tot_specat, nat_tot_prev;
-    gmx_bool          bPBC;
-    gmx_specatsend_t* spas;
+    int nsend[2], nsend_zero[2] = { 0, 0 };
+    int buf[2];
 
     if (debug)
     {
@@ -388,21 +374,18 @@ int setup_specat_communication(gmx_domdec_t*             dd,
     const int numRequested = ireq->size();
     nsend[0]               = ireq->size();
     nsend[1]               = nsend[0];
-    nlast                  = nsend[1];
+    int nlast              = nsend[1];
     for (int d = dd->ndim - 1; d >= 0; d--)
     {
         /* Pulse the grid forward and backward */
-        dim  = dd->dim[d];
-        bPBC = (dim < dd->unitCellInfo.npbcdim);
-        if (dd->numCells[dim] == 2)
-        {
-            /* Only 2 cells, so we only need to communicate once */
-            ndir = 1;
-        }
-        else
-        {
-            ndir = 2;
-        }
+        int       dim  = dd->dim[d];
+        bool      bPBC = (dim < dd->unitCellInfo.npbcdim);
+        const int ndir = (dd->numCells[dim] == 2)
+                                 ?
+                                 /* Only 2 cells, so we only need to communicate once */
+                                 1
+                                 : 2;
+        int* nsend_ptr = nullptr;
         for (int dir = 0; dir < ndir; dir++)
         {
             if (!bPBC && dd->numCells[dim] > 2
@@ -417,7 +400,7 @@ int setup_specat_communication(gmx_domdec_t*             dd,
             }
             /* Communicate the number of indices */
             ddSendrecv(dd, d, dir == 0 ? dddirForward : dddirBackward, nsend_ptr, 2, spac->nreq[d][dir], 2);
-            nr = spac->nreq[d][dir][1];
+            int nr = spac->nreq[d][dir][1];
             ireq->resize(nlast + nr);
             /* Communicate the indices */
             ddSendrecv(dd,
@@ -437,20 +420,13 @@ int setup_specat_communication(gmx_domdec_t*             dd,
     }
 
     /* Search for the requested atoms and communicate the indices we have */
-    nat_tot_specat = at_start;
-    nrecv_local    = 0;
+    int nat_tot_specat = at_start;
+    int nrecv_local    = 0;
     for (int d = 0; d < dd->ndim; d++)
     {
         /* Pulse the grid forward and backward */
-        if (dd->dim[d] >= dd->unitCellInfo.npbcdim || dd->numCells[dd->dim[d]] > 2)
-        {
-            ndir = 2;
-        }
-        else
-        {
-            ndir = 1;
-        }
-        nat_tot_prev = nat_tot_specat;
+        const int ndir = (dd->dim[d] >= dd->unitCellInfo.npbcdim || dd->numCells[dd->dim[d]] > 2) ? 2 : 1;
+        int       nat_tot_prev = nat_tot_specat;
         for (int dir = ndir - 1; dir >= 0; dir--)
         {
             /* To avoid cost of clearing by resize(), we only increase size */
@@ -459,21 +435,21 @@ int setup_specat_communication(gmx_domdec_t*             dd,
                 /* Note: resize initializes new elements to false, which is actually needed here */
                 spac->sendAtom.resize(nat_tot_specat);
             }
-            spas = &spac->spas[d][dir];
-            n0   = spac->nreq[d][dir][0];
-            nr   = spac->nreq[d][dir][1];
+            gmx_specatsend_t* spas = &spac->spas[d][dir];
+            const int         n0   = spac->nreq[d][dir][0];
+            const int         nr   = spac->nreq[d][dir][1];
             if (debug)
             {
                 fprintf(debug, "dim=%d, dir=%d, searching for %d atoms\n", d, dir, nr);
             }
-            start = nlast - nr;
+            const int start = nlast - nr;
             spas->a.clear();
             spac->ibuf.clear();
             nsend[0] = 0;
             for (int i = 0; i < nr; i++)
             {
                 const int indr = (*ireq)[start + i];
-                int       ind;
+                int       ind  = 0;
                 /* Check if this is a home atom and if so ind will be set */
                 if (const int* homeIndex = dd->ga2la->findHome(indr))
                 {
@@ -553,8 +529,8 @@ int setup_specat_communication(gmx_domdec_t*             dd,
         }
 
         /* Increase the x/f communication buffer sizes, when necessary */
-        ns = spac->spas[d][0].a.size();
-        nr = spac->spas[d][0].nrecv;
+        int ns = spac->spas[d][0].a.size();
+        int nr = spac->spas[d][0].nrecv;
         if (ndir == 2)
         {
             ns += spac->spas[d][1].a.size();
index ad10295ed8db32679c93a1cc997986493194c442..46d98be8a07b1d1e8ff2e3ba2c3df954a8d9673e 100644 (file)
@@ -2,7 +2,7 @@
  * This file is part of the GROMACS molecular simulation package.
  *
  * Copyright (c) 2006 - 2014, The GROMACS development team.
- * Copyright (c) 2015,2016,2017,2018,2019,2020, by the GROMACS development team, led by
+ * Copyright (c) 2015,2016,2017,2018,2019,2020,2021, 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.
@@ -89,6 +89,7 @@
 #include "domdec_internal.h"
 #include "domdec_vsite.h"
 #include "dump.h"
+#include "math.h"
 
 using gmx::ArrayRef;
 using gmx::ListOfLists;
@@ -163,9 +164,7 @@ struct gmx_reverse_top_t
 /*! \brief Returns the number of atom entries for il in gmx_reverse_top_t */
 static int nral_rt(int ftype)
 {
-    int nral;
-
-    nral = NRAL(ftype);
+    int nral = NRAL(ftype);
     if (interaction_function[ftype].flags & IF_VSITE)
     {
         /* With vsites the reverse topology contains an extra entry
@@ -306,8 +305,8 @@ static std::string printMissingInteractionsMolblock(t_commrec*               cr,
                                 numMissingToPrint);
                     }
                     log.writeStringFormatted("%20s atoms", interaction_function[ftype].longname);
-                    int a;
-                    for (a = 0; a < nral; a++)
+                    int a = 0;
+                    for (; a < nral; a++)
                     {
                         log.writeStringFormatted("%5d", ril.il[j_mol + 2 + a] + 1);
                     }
@@ -317,7 +316,7 @@ static std::string printMissingInteractionsMolblock(t_commrec*               cr,
                         a++;
                     }
                     log.writeString(" global");
-                    for (a = 0; a < nral; a++)
+                    for (int a = 0; a < nral; a++)
                     {
                         log.writeStringFormatted("%6d",
                                                  atomRange.begin() + mol * numAtomsPerMolecule
@@ -370,23 +369,20 @@ void dd_print_missing_interactions(const gmx::MDLogger&           mdlog,
                                    gmx::ArrayRef<const gmx::RVec> x,
                                    const matrix                   box)
 {
-    int           ndiff_tot, cl[F_NRE], n, ndiff, rest_global, rest_local;
-    int           ftype, nral;
-    gmx_domdec_t* dd;
-
-    dd = cr->dd;
+    int           cl[F_NRE];
+    gmx_domdec_t* dd = cr->dd;
 
     GMX_LOG(mdlog.warning)
             .appendText(
                     "Not all bonded interactions have been properly assigned to the domain "
                     "decomposition cells");
 
-    ndiff_tot = local_count - dd->nbonded_global;
+    const int ndiff_tot = local_count - dd->nbonded_global;
 
-    for (ftype = 0; ftype < F_NRE; ftype++)
+    for (int ftype = 0; ftype < F_NRE; ftype++)
     {
-        nral      = NRAL(ftype);
-        cl[ftype] = top_local->idef.il[ftype].size() / (1 + nral);
+        const int nral = NRAL(ftype);
+        cl[ftype]      = top_local->idef.il[ftype].size() / (1 + nral);
     }
 
     gmx_sumi(F_NRE, cl, cr);
@@ -394,9 +390,9 @@ void dd_print_missing_interactions(const gmx::MDLogger&           mdlog,
     if (DDMASTER(dd))
     {
         GMX_LOG(mdlog.warning).appendText("A list of missing interactions:");
-        rest_global = dd->nbonded_global;
-        rest_local  = local_count;
-        for (ftype = 0; ftype < F_NRE; ftype++)
+        int rest_global = dd->nbonded_global;
+        int rest_local  = local_count;
+        for (int ftype = 0; ftype < F_NRE; ftype++)
         {
             /* In the reverse and local top all constraints are merged
              * into F_CONSTR. So in the if statement we skip F_CONSTRNC
@@ -407,12 +403,12 @@ void dd_print_missing_interactions(const gmx::MDLogger&           mdlog,
                 || (dd->reverse_top->bConstr && ftype == F_CONSTR)
                 || (dd->reverse_top->bSettle && ftype == F_SETTLE))
             {
-                n = gmx_mtop_ftype_count(top_global, ftype);
+                int n = gmx_mtop_ftype_count(top_global, ftype);
                 if (ftype == F_CONSTR)
                 {
                     n += gmx_mtop_ftype_count(top_global, F_CONSTRNC);
                 }
-                ndiff = cl[ftype] - n;
+                int ndiff = cl[ftype] - n;
                 if (ndiff != 0)
                 {
                     GMX_LOG(mdlog.warning)
@@ -426,7 +422,7 @@ void dd_print_missing_interactions(const gmx::MDLogger&           mdlog,
             }
         }
 
-        ndiff = rest_local - rest_global;
+        int ndiff = rest_local - rest_global;
         if (ndiff != 0)
         {
             GMX_LOG(mdlog.warning).appendTextFormatted("%20s of %6d missing %6d", "exclusions", rest_global, -ndiff);
@@ -465,7 +461,7 @@ static void global_atomnr_to_moltype_ind(const gmx_reverse_top_t* rt, int i_gl,
     const MolblockIndices* mbi   = rt->mbi.data();
     int                    start = 0;
     int                    end   = rt->mbi.size(); /* exclusive */
-    int                    mid;
+    int                    mid   = 0;
 
     /* binary search for molblock_ind */
     while (TRUE)
@@ -523,12 +519,9 @@ static int low_make_reverse_ilist(const InteractionLists&  il_mt,
                                   gmx_bool                 bLinkToAllAtoms,
                                   gmx_bool                 bAssign)
 {
-    int ftype, j, nlink, link;
-    int a;
-    int nint;
+    int nint = 0;
 
-    nint = 0;
-    for (ftype = 0; ftype < F_NRE; ftype++)
+    for (int ftype = 0; ftype < F_NRE; ftype++)
     {
         if ((interaction_function[ftype].flags & (IF_BOND | IF_VSITE))
             || (bConstr && (ftype == F_CONSTR || ftype == F_CONSTRNC)) || (bSettle && ftype == F_SETTLE))
@@ -538,34 +531,18 @@ static int low_make_reverse_ilist(const InteractionLists&  il_mt,
             const auto& il     = il_mt[ftype];
             for (int i = 0; i < il.size(); i += 1 + nral)
             {
-                const int* ia = il.iatoms.data() + i;
-                if (bLinkToAllAtoms)
+                const int* ia    = il.iatoms.data() + i;
+                const int  nlink = bLinkToAllAtoms ? bVSite ? 0 : nral : 1;
+                for (int link = 0; link < nlink; link++)
                 {
-                    if (bVSite)
-                    {
-                        /* We don't need the virtual sites for the cg-links */
-                        nlink = 0;
-                    }
-                    else
-                    {
-                        nlink = nral;
-                    }
-                }
-                else
-                {
-                    /* Couple to the first atom in the interaction */
-                    nlink = 1;
-                }
-                for (link = 0; link < nlink; link++)
-                {
-                    a = ia[1 + link];
+                    const int a = ia[1 + link];
                     if (bAssign)
                     {
                         GMX_ASSERT(!r_il.empty(), "with bAssign not allowed to be empty");
                         GMX_ASSERT(!r_index.empty(), "with bAssign not allowed to be empty");
                         r_il[r_index[a] + count[a]]     = (ftype == F_CONSTRNC ? F_CONSTR : ftype);
                         r_il[r_index[a] + count[a] + 1] = ia[0];
-                        for (j = 1; j < 1 + nral; j++)
+                        for (int j = 1; j < 1 + nral; j++)
                         {
                             /* Store the molecular atom number */
                             r_il[r_index[a] + count[a] + 1 + j] = ia[j];
@@ -580,7 +557,7 @@ static int low_make_reverse_ilist(const InteractionLists&  il_mt,
                              * vsites again.
                              */
                             r_il[r_index[a] + count[a] + 2 + nral] = 0;
-                            for (j = 2; j < 1 + nral; j++)
+                            for (int j = 2; j < 1 + nral; j++)
                             {
                                 if (atom[ia[j]].ptype == eptVSite)
                                 {
@@ -618,16 +595,14 @@ static int make_reverse_ilist(const InteractionLists& ilist,
                               gmx_bool                bLinkToAllAtoms,
                               reverse_ilist_t*        ril_mt)
 {
-    int nat_mt, *count, i, nint_mt;
-
     /* Count the interactions */
-    nat_mt = atoms->nr;
-    snew(count, nat_mt);
+    const int        nat_mt = atoms->nr;
+    std::vector<int> count(nat_mt);
     low_make_reverse_ilist(
-            ilist, atoms->atom, count, bConstr, bSettle, bBCheck, {}, {}, bLinkToAllAtoms, FALSE);
+            ilist, atoms->atom, count.data(), bConstr, bSettle, bBCheck, {}, {}, bLinkToAllAtoms, FALSE);
 
     ril_mt->index.push_back(0);
-    for (i = 0; i < nat_mt; i++)
+    for (int i = 0; i < nat_mt; i++)
     {
         ril_mt->index.push_back(ril_mt->index[i] + count[i]);
         count[i] = 0;
@@ -635,10 +610,8 @@ static int make_reverse_ilist(const InteractionLists& ilist,
     ril_mt->il.resize(ril_mt->index[nat_mt]);
 
     /* Store the interactions */
-    nint_mt = low_make_reverse_ilist(
-            ilist, atoms->atom, count, bConstr, bSettle, bBCheck, ril_mt->index, ril_mt->il, bLinkToAllAtoms, TRUE);
-
-    sfree(count);
+    int nint_mt = low_make_reverse_ilist(
+            ilist, atoms->atom, count.data(), bConstr, bSettle, bBCheck, ril_mt->index, ril_mt->il, bLinkToAllAtoms, TRUE);
 
     ril_mt->numAtomsInMolecule = atoms->nr;
 
@@ -939,9 +912,7 @@ static void add_vsite(const gmx_ga2la_t&       ga2la,
                       const t_iatom*           iatoms,
                       InteractionDefinitions*  idef)
 {
-    int     k;
     t_iatom tiatoms[1 + MAXATOMLIST];
-    int     j, ftype_r, nral_r;
 
     /* Add this interaction to the local topology */
     add_ifunc_for_vsites(tiatoms, ga2la, nral, bHomeA, a, a_gl, a_mol, iatoms, &idef->il[ftype]);
@@ -949,7 +920,7 @@ static void add_vsite(const gmx_ga2la_t&       ga2la,
     if (iatoms[1 + nral])
     {
         /* Check for recursion */
-        for (k = 2; k < 1 + nral; k++)
+        for (int k = 2; k < 1 + nral; k++)
         {
             if ((iatoms[1 + nral] & (2 << k)) && (tiatoms[k] < 0))
             {
@@ -964,11 +935,11 @@ static void add_vsite(const gmx_ga2la_t&       ga2la,
                 /* Find the vsite construction */
 
                 /* Check all interactions assigned to this atom */
-                j = index[iatoms[k]];
+                int j = index[iatoms[k]];
                 while (j < index[iatoms[k] + 1])
                 {
-                    ftype_r = rtil[j++];
-                    nral_r  = NRAL(ftype_r);
+                    int ftype_r = rtil[j++];
+                    int nral_r  = NRAL(ftype_r);
                     if (interaction_function[ftype_r].flags & IF_VSITE)
                     {
                         /* Add this vsite (recursion) */
@@ -1011,9 +982,7 @@ static real dd_dist2(t_pbc* pbc_null, const rvec* x, const int i, int j)
 /*! \brief Append t_idef structures 1 to nsrc in src to *dest */
 static void combine_idef(InteractionDefinitions* dest, gmx::ArrayRef<const thread_work_t> src)
 {
-    int ftype;
-
-    for (ftype = 0; ftype < F_NRE; ftype++)
+    for (int ftype = 0; ftype < F_NRE; ftype++)
     {
         int n = 0;
         for (gmx::index s = 1; s < src.ssize(); s++)
@@ -1110,7 +1079,7 @@ static inline void check_assign_interactions_atom(int                       i,
         }
         else
         {
-            gmx_bool bUse;
+            bool bUse = false;
 
             /* Copy the type */
             tiatoms[0] = iatoms[0];
@@ -1121,7 +1090,7 @@ static inline void check_assign_interactions_atom(int                       i,
                 /* Assign single-body interactions to the home zone */
                 if (iz == 0)
                 {
-                    bUse       = TRUE;
+                    bUse       = true;
                     tiatoms[1] = i;
                     if (ftype == F_POSRES)
                     {
@@ -1131,10 +1100,10 @@ static inline void check_assign_interactions_atom(int                       i,
                     {
                         add_fbposres(mol, i_mol, numAtomsInMolecule, molb, tiatoms, ip_in, idef);
                     }
-                }
-                else
-                {
-                    bUse = FALSE;
+                    else
+                    {
+                        bUse = false;
+                    }
                 }
             }
             else if (nral == 2)
@@ -1142,17 +1111,11 @@ static inline void check_assign_interactions_atom(int                       i,
                 /* This is a two-body interaction, we can assign
                  * analogous to the non-bonded assignments.
                  */
-                int k_gl;
-
-                if (!bInterMolInteractions)
-                {
-                    /* Get the global index using the offset in the molecule */
-                    k_gl = i_gl + iatoms[2] - i_mol;
-                }
-                else
-                {
-                    k_gl = iatoms[2];
-                }
+                const int k_gl = (!bInterMolInteractions)
+                                         ?
+                                         /* Get the global index using the offset in the molecule */
+                                         (i_gl + iatoms[2] - i_mol)
+                                         : iatoms[2];
                 if (const auto* entry = dd->ga2la->find(k_gl))
                 {
                     int kz = entry->cell;
@@ -1173,7 +1136,7 @@ static inline void check_assign_interactions_atom(int                       i,
                         /* If necessary check the cgcm distance */
                         if (bRCheck2B && dd_dist2(pbc_null, cg_cm, tiatoms[1], tiatoms[2]) >= rc2)
                         {
-                            bUse = FALSE;
+                            bUse = false;
                         }
                     }
                 }
@@ -1191,23 +1154,16 @@ static inline void check_assign_interactions_atom(int                       i,
                  * with 2 DD cells an extra check may be necessary.
                  */
                 ivec k_zero, k_plus;
-                int  k;
-
-                bUse = TRUE;
+                bUse = true;
                 clear_ivec(k_zero);
                 clear_ivec(k_plus);
-                for (k = 1; k <= nral && bUse; k++)
+                for (int k = 1; k <= nral && bUse; k++)
                 {
-                    int k_gl;
-                    if (!bInterMolInteractions)
-                    {
-                        /* Get the global index using the offset in the molecule */
-                        k_gl = i_gl + iatoms[k] - i_mol;
-                    }
-                    else
-                    {
-                        k_gl = iatoms[k];
-                    }
+                    const int k_gl = (!bInterMolInteractions)
+                                             ?
+                                             /* Get the global index using the offset in the molecule */
+                                             (i_gl + iatoms[k] - i_mol)
+                                             : iatoms[k];
                     const auto* entry = dd->ga2la->find(k_gl);
                     if (entry == nullptr || entry->cell >= zones->n)
                     {
@@ -1219,10 +1175,8 @@ static inline void check_assign_interactions_atom(int                       i,
                     }
                     else
                     {
-                        int d;
-
                         tiatoms[k] = entry->la;
-                        for (d = 0; d < DIM; d++)
+                        for (int d = 0; d < DIM; d++)
                         {
                             if (zones->shift[entry->cell][d] == 0)
                             {
@@ -1238,9 +1192,7 @@ static inline void check_assign_interactions_atom(int                       i,
                 bUse = (bUse && (k_zero[XX] != 0) && (k_zero[YY] != 0) && (k_zero[ZZ] != 0));
                 if (bRCheckMB)
                 {
-                    int d;
-
-                    for (d = 0; (d < DIM && bUse); d++)
+                    for (int d = 0; (d < DIM && bUse); d++)
                     {
                         /* Check if the cg_cm distance falls within
                          * the cut-off to avoid possible multiple
@@ -1290,16 +1242,13 @@ static int make_bondeds_zone(gmx_domdec_t*                      dd,
                              int                                izone,
                              const gmx::Range<int>&             atomRange)
 {
-    int                mb, mt, mol, i_mol;
-    gmx_bool           bBCheck;
-    gmx_reverse_top_t* rt;
-    int                nbonded_local;
+    int mb = 0, mt = 0, mol = 0, i_mol = 0;
 
-    rt = dd->reverse_top;
+    gmx_reverse_top_t* rt = dd->reverse_top;
 
-    bBCheck = rt->bBCheck;
+    bool bBCheck = rt->bBCheck;
 
-    nbonded_local = 0;
+    int nbonded_local = 0;
 
     for (int i : atomRange)
     {
@@ -1396,10 +1345,10 @@ static void make_exclusions_zone(gmx_domdec_t*                     dd,
 
         if (GET_CGINFO_EXCL_INTER(cginfo[at]))
         {
-            int a_gl, mb, mt, mol, a_mol;
+            int mb = 0, mt = 0, mol = 0, a_mol = 0;
 
             /* Copy the exclusions from the global top */
-            a_gl = dd->globalAtomIndices[at];
+            int a_gl = dd->globalAtomIndices[at];
             global_atomnr_to_moltype_ind(dd->reverse_top, a_gl, &mb, &mt, &mol, &a_mol);
             const auto excls = moltype[mt].excls[a_mol];
             for (const int aj_mol : excls)
@@ -1459,11 +1408,7 @@ static int make_local_bondeds_excls(gmx_domdec_t*           dd,
                                     ListOfLists<int>*       lexcls,
                                     int*                    excl_count)
 {
-    int                nzone_bondeds;
-    int                cg0, cg1;
-    real               rc2;
-    int                nbonded_local;
-    gmx_reverse_top_t* rt;
+    int nzone_bondeds = 0;
 
     if (dd->reverse_top->bInterAtomicInteractions)
     {
@@ -1480,21 +1425,21 @@ static int make_local_bondeds_excls(gmx_domdec_t*           dd,
     /* We only use exclusions from i-zones to i- and j-zones */
     const int numIZonesForExclusions = (dd->haveExclusions ? zones->iZones.size() : 0);
 
-    rt = dd->reverse_top;
+    gmx_reverse_top_t* rt = dd->reverse_top;
 
-    rc2 = rc * rc;
+    real rc2 = rc * rc;
 
     /* Clear the counts */
     idef->clear();
-    nbonded_local = 0;
+    int nbonded_local = 0;
 
     lexcls->clear();
     *excl_count = 0;
 
     for (int izone = 0; izone < nzone_bondeds; izone++)
     {
-        cg0 = zones->cg_range[izone];
-        cg1 = zones->cg_range[izone + 1];
+        int cg0 = zones->cg_range[izone];
+        int cg1 = zones->cg_range[izone + 1];
 
         const int numThreads = rt->th_work.size();
 #pragma omp parallel for num_threads(numThreads) schedule(static)
@@ -1502,11 +1447,10 @@ static int make_local_bondeds_excls(gmx_domdec_t*           dd,
         {
             try
             {
-                int                     cg0t, cg1t;
-                InteractionDefinitions* idef_t;
+                InteractionDefinitions* idef_t = nullptr;
 
-                cg0t = cg0 + ((cg1 - cg0) * thread) / numThreads;
-                cg1t = cg0 + ((cg1 - cg0) * (thread + 1)) / numThreads;
+                int cg0t = cg0 + ((cg1 - cg0) * thread) / numThreads;
+                int cg1t = cg0 + ((cg1 - cg0) * (thread + 1)) / numThreads;
 
                 if (thread == 0)
                 {
@@ -1534,7 +1478,7 @@ static int make_local_bondeds_excls(gmx_domdec_t*           dd,
 
                 if (izone < numIZonesForExclusions)
                 {
-                    ListOfLists<int>* excl_t;
+                    ListOfLists<int>* excl_t = nullptr;
                     if (thread == 0)
                     {
                         // Thread 0 stores exclusions directly in the final storage
@@ -1597,19 +1541,18 @@ void dd_make_local_top(gmx_domdec_t*       dd,
                        const gmx_mtop_t&   mtop,
                        gmx_localtop_t*     ltop)
 {
-    gmx_bool bRCheckMB, bRCheck2B;
-    real     rc = -1;
-    ivec     rcheck;
-    int      d, nexcl;
-    t_pbc    pbc, *pbc_null = nullptr;
+    real  rc = -1;
+    ivec  rcheck;
+    int   nexcl = 0;
+    t_pbc pbc, *pbc_null = nullptr;
 
     if (debug)
     {
         fprintf(debug, "Making local topology\n");
     }
 
-    bRCheckMB = FALSE;
-    bRCheck2B = FALSE;
+    bool bRCheckMB = false;
+    bool bRCheck2B = false;
 
     if (dd->reverse_top->bInterAtomicInteractions)
     {
@@ -1621,7 +1564,7 @@ void dd_make_local_top(gmx_domdec_t*       dd,
         }
 
         /* Should we check cg_cm distances when assigning bonded interactions? */
-        for (d = 0; d < DIM; d++)
+        for (int d = 0; d < DIM; d++)
         {
             rcheck[d] = FALSE;
             /* Only need to check for dimensions where the part of the box
@@ -1719,11 +1662,8 @@ void dd_init_local_state(gmx_domdec_t* dd, const t_state* state_global, t_state*
 /*! \brief Check if a link is stored in \p link between charge groups \p cg_gl and \p cg_gl_j and if not so, store a link */
 static void check_link(t_blocka* link, int cg_gl, int cg_gl_j)
 {
-    int      k;
-    gmx_bool bFound;
-
-    bFound = FALSE;
-    for (k = link->index[cg_gl]; k < link->index[cg_gl + 1]; k++)
+    bool bFound = false;
+    for (int k = link->index[cg_gl]; k < link->index[cg_gl + 1]; k++)
     {
         GMX_RELEASE_ASSERT(link->a, "Inconsistent NULL pointer while making charge-group links");
         if (link->a[k] == cg_gl_j)
@@ -1748,8 +1688,7 @@ static void check_link(t_blocka* link, int cg_gl, int cg_gl_j)
 
 t_blocka* makeBondedLinks(const gmx_mtop_t& mtop, gmx::ArrayRef<cginfo_mb_t> cginfo_mb)
 {
-    t_blocka*    link;
-    cginfo_mb_t* cgi_mb;
+    t_blocka* link = nullptr;
 
     /* For each atom make a list of other atoms in the system
      * that a linked to it via bonded interactions
@@ -1793,9 +1732,9 @@ t_blocka* makeBondedLinks(const gmx_mtop_t& mtop, gmx::ArrayRef<cginfo_mb_t> cgi
         reverse_ilist_t ril;
         make_reverse_ilist(molt.ilist, &molt.atoms, FALSE, FALSE, FALSE, TRUE, &ril);
 
-        cgi_mb = &cginfo_mb[mb];
+        cginfo_mb_t* cgi_mb = &cginfo_mb[mb];
 
-        int mol;
+        int mol = 0;
         for (mol = 0; mol < (mtop.bIntermolecularInteractions ? molb.nmol : 1); mol++)
         {
             for (int a = 0; a < molt.atoms.nr; a++)
@@ -2003,7 +1942,7 @@ static void bonded_distance_intermol(const InteractionLists& ilists_intermol,
                     for (int aj = ai + 1; aj < nral; aj++)
                     {
                         rvec dx;
-                        real rij2;
+                        real rij2 = NAN;
 
                         int atom_j = il.iatoms[i + 1 + aj];
 
@@ -2043,8 +1982,6 @@ static void getWholeMoleculeCoordinates(const gmx_moltype_t*  molt,
                                         ArrayRef<const RVec>  x,
                                         ArrayRef<RVec>        xs)
 {
-    int n, i;
-
     if (pbcType != PbcType::No)
     {
         mk_mshift(nullptr, graph, pbcType, box, as_rvec_array(x.data()));
@@ -2063,8 +2000,7 @@ static void getWholeMoleculeCoordinates(const gmx_moltype_t*  molt,
          * unchanged, just to be 100% sure that we do not affect
          * binary reproducibility of simulations.
          */
-        n = molt->atoms.nr;
-        for (i = 0; i < n; i++)
+        for (int i = 0; i < molt->atoms.nr; i++)
         {
             copy_rvec(x[i], xs[i]);
         }
@@ -2085,16 +2021,14 @@ void dd_bonded_cg_distance(const gmx::MDLogger& mdlog,
                            real*                r_2b,
                            real*                r_mb)
 {
-    gmx_bool          bExclRequired;
-    int               at_offset;
     bonded_distance_t bd_2b = { 0, -1, -1, -1 };
     bonded_distance_t bd_mb = { 0, -1, -1, -1 };
 
-    bExclRequired = inputrecExclForces(ir);
+    bool bExclRequired = inputrecExclForces(ir);
 
-    *r_2b     = 0;
-    *r_mb     = 0;
-    at_offset = 0;
+    *r_2b         = 0;
+    *r_mb         = 0;
+    int at_offset = 0;
     for (const gmx_molblock_t& molb : mtop->molblock)
     {
         const gmx_moltype_t& molt = mtop->moltype[molb.type];
index a6d073c3c9346762990829ab57995c76218cb632..c5265f5f8f27c75f3d97d2534700c010a4be668f 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2015,2017,2018,2019, by the GROMACS development team, led by
+ * Copyright (c) 2015,2017,2018,2019,2021, 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.
@@ -149,7 +149,7 @@ gmx_unused void alignedFreeGeneric(void* p)
 //! Implement malloc of \c bytes of memory, aligned to \c alignment.
 void* mallocImpl(std::size_t bytes, std::size_t alignment)
 {
-    void* p;
+    void* p = nullptr;
 
 #if HAVE__MM_MALLOC
     p = _mm_malloc(bytes, alignment);
@@ -228,7 +228,7 @@ void AlignedAllocationPolicy::free(void* p)
 //! \todo Move this function into sysinfo.cpp where other OS-specific code/includes live
 static std::size_t getPageSize()
 {
-    long pageSize;
+    long pageSize = 0;
 #if GMX_NATIVE_WINDOWS
     SYSTEM_INFO si;
     GetNativeSystemInfo(&si);
index 6fade03e577a04d6be1bea33987e1ed80e3b2847..7aa2944bbe281229e7c664d0c4cbc2a5c806e98e 100644 (file)
@@ -4,7 +4,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 by the GROMACS development team.
- * Copyright (c) 2018,2019,2020, by the GROMACS development team, led by
+ * Copyright (c) 2018,2019,2020,2021, 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.
@@ -55,7 +55,7 @@ bool gmx_mpi_initialized()
 #if !GMX_MPI
     return false;
 #else
-    int n;
+    int n = 0;
     MPI_Initialized(&n);
 
     return n != 0;
@@ -73,7 +73,7 @@ int gmx_node_num()
         return 1;
     }
 #    endif
-    int i;
+    int i = 0;
     (void)MPI_Comm_size(MPI_COMM_WORLD, &i);
     return i;
 #endif
@@ -90,7 +90,7 @@ int gmx_node_rank()
         return 0;
     }
 #    endif
-    int i;
+    int i = 0;
     (void)MPI_Comm_rank(MPI_COMM_WORLD, &i);
     return i;
 #endif
@@ -98,7 +98,7 @@ int gmx_node_rank()
 
 static int mpi_hostname_hash()
 {
-    int hash_int;
+    int hash_int = 0;
 
 #if GMX_LIB_MPI
     int  resultlen;
index 7c324773219cbbbc46a8ed90c9c1d2a2843e2a73..a78ba3c4f17f0e0118056d69ee1dd974a2ebb41b 100644 (file)
@@ -2,7 +2,7 @@
  * This file is part of the GROMACS molecular simulation package.
  *
  * Copyright (c) 2010,2012,2014,2015,2018 by the GROMACS development team.
- * Copyright (c) 2019,2020, by the GROMACS development team, led by
+ * Copyright (c) 2019,2020,2021, 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.
@@ -35,9 +35,9 @@
  */
 #include "gromacs/utility/baseversion_gen.h"
 
-const char _gmx_ver_string[] = "@GMX_VERSION_STRING_FULL@";
-const char _gmx_full_git_hash[] = "@GMX_VERSION_FULL_HASH@";
-const char _gmx_central_base_hash[] = "@GMX_VERSION_CENTRAL_BASE_HASH@";
+const char gmx_ver_string[] = "@GMX_VERSION_STRING_FULL@";
+const char gmx_full_git_hash[] = "@GMX_VERSION_FULL_HASH@";
+const char gmx_central_base_hash[] = "@GMX_VERSION_CENTRAL_BASE_HASH@";
 const char gmxSourceDoiString[] = "@GMX_SOURCE_DOI@";
 const char gmxReleaseSourceFileChecksum[] = "@GMX_RELEASE_SOURCE_FILE_CHECKSUM@"; 
 const char gmxCurrentSourceFileChecksum[] = "@GMX_CURRENT_SOURCE_FILE_CHECKSUM@";
index ec06ccd4ab88fe576f91f7c694096afbb34aff48..e862b805dc15d5decb11e5a7ccf4ce721d8fc820 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * This file is part of the GROMACS molecular simulation package.
  *
- * Copyright (c) 2014,2015,2018,2019,2020, by the GROMACS development team, led by
+ * Copyright (c) 2014,2015,2018,2019,2020,2021, 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.
 
 const char* gmx_version()
 {
-    return _gmx_ver_string;
+    return gmx_ver_string;
 }
 
 const char* gmx_version_git_full_hash()
 {
-    return _gmx_full_git_hash;
+    return gmx_full_git_hash;
 }
 
 const char* gmx_version_git_central_base_hash()
 {
-    return _gmx_central_base_hash;
+    return gmx_central_base_hash;
 }
 
 const char* gmxDOI()
index b2f026f81a3e6336a056784343d9db63d9cda5e9..0249270ec41ac5dc0c01be2dcd94717e1e4b1dd9 100644 (file)
@@ -2,7 +2,7 @@
  * This file is part of the GROMACS molecular simulation package.
  *
  * Copyright (c) 2010,2012,2013,2014,2015 by the GROMACS development team.
- * Copyright (c) 2018,2019,2020, by the GROMACS development team, led by
+ * Copyright (c) 2018,2019,2020,2021, 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.
 //! \{
 
 //! Version string, containing the version, date, and abbreviated hash.
-extern const char _gmx_ver_string[];
+extern const char gmx_ver_string[];
 //! Full git hash of the latest commit.
-extern const char _gmx_full_git_hash[];
+extern const char gmx_full_git_hash[];
 //! Full git hash of the latest commit in a central \Gromacs repository.
-extern const char _gmx_central_base_hash[];
+extern const char gmx_central_base_hash[];
 /*! \brief
  *  DOI string for the \Gromacs source code populated by CMake.
  *
index fe6a77e315e437739dfdc3ed08a5585e10036a85..a9d416459e684fd6283bb32929db8bad153a40fd 100644 (file)
@@ -234,13 +234,13 @@ void gmx_fatal(int f_errno, const char* file, int line, gmx_fmtstr const char* f
     va_end(ap);
 }
 
-void _gmx_error(const char* key, const std::string& msg, const char* file, int line)
+void gmx_error_function(const char* key, const std::string& msg, const char* file, int line)
 {
     call_error_handler(key, file, line, msg);
     gmx_exit_on_fatal_error(ExitType_Abort, 1);
 }
 
-void _range_check(int n, int n_min, int n_max, const char* warn_str, const char* var, const char* file, int line)
+void range_check_function(int n, int n_min, int n_max, const char* warn_str, const char* var, const char* file, int line)
 {
     if ((n < n_min) || (n >= n_max))
     {
@@ -259,7 +259,7 @@ void _range_check(int n, int n_min, int n_max, const char* warn_str, const char*
                 n_min,
                 n_max);
 
-        _gmx_error("range", buf, file, line);
+        gmx_error_function("range", buf, file, line);
     }
 }
 
index 55f2c946efbb65825985092e1837ac79cbace979..9db24793ba48ff90b757c3483a1fb966be0a940a 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2012,2014,2015,2018,2019, by the GROMACS development team, led by
+ * Copyright (c) 2012,2014,2015,2018,2019,2021, 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.
@@ -62,9 +62,9 @@
    }
    \endcode
  */
-extern FILE* debug;
+extern FILE* debug; //NOLINT(cppcoreguidelines-avoid-non-const-global-variables,-warnings-as-errors)
 /** Whether extra debugging is enabled. */
-extern gmx_bool gmx_debug_at;
+extern gmx_bool gmx_debug_at; //NOLINT(cppcoreguidelines-avoid-non-const-global-variables,-warnings-as-errors)
 
 /*! \brief
  * Initializes debugging variables.
@@ -181,7 +181,7 @@ enum ExitType
 #define FARGS 0, __FILE__, __LINE__
 
 /** Implementation for gmx_error(). */
-[[noreturn]] void _gmx_error(const char* key, const std::string& msg, const char* file, int line);
+[[noreturn]] void gmx_error_function(const char* key, const std::string& msg, const char* file, int line);
 /*! \brief
  * Alternative fatal error routine with canned messages.
  *
@@ -189,7 +189,7 @@ enum ExitType
  * based on a string key, and printf-style formatting is not supported.
  * Should not typically be called directly, but through gmx_call() etc.
  */
-#define gmx_error(key, msg) _gmx_error(key, msg, __FILE__, __LINE__)
+#define gmx_error(key, msg) gmx_error_function(key, msg, __FILE__, __LINE__)
 
 /*! \name Fatal error routines for certain types of errors
  *
@@ -212,7 +212,7 @@ enum ExitType
  *
  * \p warn_str can be NULL.
  */
-void _range_check(int n, int n_min, int n_max, const char* warn_str, const char* var, const char* file, int line);
+void range_check_function(int n, int n_min, int n_max, const char* warn_str, const char* var, const char* file, int line);
 
 /*! \brief
  * Checks that a variable is within a range.
@@ -221,14 +221,15 @@ void _range_check(int n, int n_min, int n_max, const char* warn_str, const char*
  * \p n_min is inclusive, but \p n_max is not.
  */
 #define range_check_mesg(n, n_min, n_max, str) \
-    _range_check(n, n_min, n_max, str, #n, __FILE__, __LINE__)
+    range_check_function(n, n_min, n_max, str, #n, __FILE__, __LINE__)
 
 /*! \brief
  * Checks that a variable is within a range.
  *
  * This works as range_check_mesg(), but with a default error message.
  */
-#define range_check(n, n_min, n_max) _range_check(n, n_min, n_max, NULL, #n, __FILE__, __LINE__)
+#define range_check(n, n_min, n_max) \
+    range_check_function(n, n_min, n_max, NULL, #n, __FILE__, __LINE__)
 
 /*! \brief
  * Prints a warning message to stderr.
index d20e8e63ea60fee789645c1345df4010d8d03607..1c5385d8de35278c9523c70f1e43796362f84b4c 100644 (file)
@@ -150,7 +150,7 @@ void gmx_set_max_backup_count(int count)
 
 static void push_ps(FILE* fp)
 {
-    t_pstack* ps;
+    t_pstack* ps = nullptr;
 
     Lock pstackLock(pstack_mutex);
 
@@ -183,7 +183,7 @@ static int pclose(FILE* /* fp */)
 
 int gmx_ffclose(FILE* fp)
 {
-    t_pstack *ps, *tmp;
+    t_pstack *ps = nullptr, *tmp = nullptr;
     int       ret = 0;
 
     Lock pstackLock(pstack_mutex);
@@ -303,7 +303,7 @@ int gmx_truncate(const std::string& filename, gmx_off_t length)
 
 static FILE* uncompress(const std::string& fn, const char* mode)
 {
-    FILE*       fp;
+    FILE*       fp  = nullptr;
     std::string buf = "uncompress -c < " + fn;
     fprintf(stderr, "Going to execute '%s'\n", buf.c_str());
     if ((fp = popen(buf.c_str(), mode)) == nullptr)
@@ -317,7 +317,7 @@ static FILE* uncompress(const std::string& fn, const char* mode)
 
 static FILE* gunzip(const std::string& fn, const char* mode)
 {
-    FILE*       fp;
+    FILE*       fp  = nullptr;
     std::string buf = "gunzip -c < ";
     buf += fn;
     fprintf(stderr, "Going to execute '%s'\n", buf.c_str());
@@ -332,7 +332,7 @@ static FILE* gunzip(const std::string& fn, const char* mode)
 
 gmx_bool gmx_fexist(const std::string& fname)
 {
-    FILE* test;
+    FILE* test = nullptr;
 
     if (fname.empty())
     {
@@ -410,9 +410,9 @@ void make_backup(const std::string& name)
 
 FILE* gmx_ffopen(const std::string& file, const char* mode)
 {
-    FILE*    ff = nullptr;
-    gmx_bool bRead;
-    int      bs;
+    FILE*    ff    = nullptr;
+    gmx_bool bRead = 0;
+    int      bs    = 0;
 
     if (file.empty())
     {
@@ -452,7 +452,7 @@ FILE* gmx_ffopen(const std::string& file, const char* mode)
             }
             else
             {
-                char* ptr;
+                char* ptr = nullptr;
                 snew(ptr, bs + 8);
                 if (setvbuf(ff, ptr, _IOFBF, bs) != 0)
                 {
@@ -532,7 +532,7 @@ FilePtr openLibraryFile(const char* filename, bool bAddCWD, bool bFatal)
  * \todo Use std::string and std::vector<char>. */
 static int makeTemporaryFilename(char* buf)
 {
-    int len;
+    int len = 0;
 
     if ((len = strlen(buf)) < 7)
     {
@@ -546,7 +546,7 @@ static int makeTemporaryFilename(char* buf)
      * since windows doesnt support it we have to separate the cases.
      * 20090307: mktemp deprecated, use iso c++ _mktemp instead.
      */
-    int fd;
+    int fd = 0;
 #if GMX_NATIVE_WINDOWS
     _mktemp(buf);
     if (buf == NULL)
@@ -641,12 +641,12 @@ int gmx_file_copy(const char* oldname, const char* newname, gmx_bool copy_if_emp
 
     while (!feof(in.get()))
     {
-        size_t nread;
+        size_t nread = 0;
 
         nread = fread(buf.data(), sizeof(char), FILECOPY_BUFSIZE, in.get());
         if (nread > 0)
         {
-            size_t ret;
+            size_t ret = 0;
             if (!out)
             {
                 /* so this is where we open when copy_if_empty is false:
@@ -677,7 +677,7 @@ int gmx_fsync(FILE* fp)
     int rc = 0;
 
     {
-        int fn;
+        int fn = 0;
 
         /* get the file number */
 #if HAVE_FILENO