Apply clang-format to source tree
[alexxy/gromacs.git] / src / gromacs / domdec / domdec_setup.cpp
index 165fa395cccff1c9795721aff65925e5a0318479..ea5a190c98d289a8eac0c95bdb3ddf1e7e9e7215 100644 (file)
@@ -84,9 +84,7 @@ using gmx::DomdecOptions;
  * \param[out]   fac   Vector of factors (to be allocated in this function)
  * \param[out]   mfac  Vector with the number of times each factor repeats in the factorization (to be allocated in this function)
  */
-static void factorize(int               n,
-                      std::vector<int> *fac,
-                      std::vector<int> *mfac)
+static void factorize(int n, std::vector<int>* fac, std::vector<int>* mfac)
 {
     if (n <= 0)
     {
@@ -146,7 +144,7 @@ static int lcd(int n1, int n2)
 /*! \brief Returns TRUE when there are enough PME ranks for the ratio */
 static gmx_bool fits_pme_ratio(int nrank_tot, int nrank_pme, float ratio)
 {
-    return (static_cast<double>(nrank_pme)/static_cast<double>(nrank_tot) > 0.95*ratio);
+    return (static_cast<double>(nrank_pme) / static_cast<double>(nrank_tot) > 0.95 * ratio);
 }
 
 /*! \brief Returns TRUE when npme out of ntot ranks doing PME is expected to give reasonable performance */
@@ -174,7 +172,7 @@ static gmx_bool fits_pp_pme_perf(int ntot, int npme, float ratio)
      * The factor of 2 allows for a maximum ratio of 2^2=4
      * between nx_pme and ny_pme.
      */
-    if (lcd(ntot - npme, npme)*2 < npme_root2)
+    if (lcd(ntot - npme, npme) * 2 < npme_root2)
     {
         return FALSE;
     }
@@ -184,26 +182,25 @@ static gmx_bool fits_pp_pme_perf(int ntot, int npme, float ratio)
 }
 
 /*! \brief Make a guess for the number of PME ranks to use. */
-static int guess_npme(const gmx::MDLogger &mdlog,
-                      const gmx_mtop_t    &mtop,
-                      const t_inputrec    &ir,
+static int guess_npme(const gmx::MDLoggermdlog,
+                      const gmx_mtop_t&    mtop,
+                      const t_inputrec&    ir,
                       const matrix         box,
                       int                  nrank_tot)
 {
-    float      ratio;
-    int        npme;
+    float ratio;
+    int   npme;
 
     ratio = pme_load_estimate(mtop, ir, box);
 
-    GMX_LOG(mdlog.info).appendTextFormatted(
-            "Guess for relative PME load: %.2f", ratio);
+    GMX_LOG(mdlog.info).appendTextFormatted("Guess for relative PME load: %.2f", ratio);
 
     /* We assume the optimal rank ratio is close to the load ratio.
      * The communication load is neglected,
      * but (hopefully) this will balance out between PP and PME.
      */
 
-    if (!fits_pme_ratio(nrank_tot, nrank_tot/2, ratio))
+    if (!fits_pme_ratio(nrank_tot, nrank_tot / 2, ratio))
     {
         /* We would need more than nrank_tot/2 PME only nodes,
          * which is not possible. Since the PME load is very high,
@@ -217,8 +214,8 @@ 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;
-    while (npme <= nrank_tot/3)
+    npme = (nrank_tot + 15) / 16;
+    while (npme <= nrank_tot / 3)
     {
         if (nrank_tot % npme == 0)
         {
@@ -232,11 +229,11 @@ static int guess_npme(const gmx::MDLogger &mdlog,
         }
         npme++;
     }
-    if (npme > nrank_tot/3)
+    if (npme > nrank_tot / 3)
     {
         /* Try any possible number for npme */
         npme = 1;
-        while (npme <= nrank_tot/2)
+        while (npme <= nrank_tot / 2)
         {
             /* Note that fits_perf may change the PME grid */
             if (fits_pp_pme_perf(nrank_tot, npme, ratio))
@@ -246,18 +243,23 @@ static int guess_npme(const gmx::MDLogger &mdlog,
             npme++;
         }
     }
-    if (npme > nrank_tot/2)
+    if (npme > nrank_tot / 2)
     {
-        gmx_fatal(FARGS, "Could not find an appropriate number of separate PME ranks. i.e. >= %5f*#ranks (%d) and <= #ranks/2 (%d) and reasonable performance wise (grid_x=%d, grid_y=%d).\n"
-                  "Use the -npme option of mdrun or change the number of ranks or the PME grid dimensions, see the manual for details.",
-                  ratio, gmx::roundToInt(0.95*ratio*nrank_tot), nrank_tot/2, ir.nkx, ir.nky);
+        gmx_fatal(FARGS,
+                  "Could not find an appropriate number of separate PME ranks. i.e. >= %5f*#ranks "
+                  "(%d) and <= #ranks/2 (%d) and reasonable performance wise (grid_x=%d, "
+                  "grid_y=%d).\n"
+                  "Use the -npme option of mdrun or change the number of ranks or the PME grid "
+                  "dimensions, see the manual for details.",
+                  ratio, gmx::roundToInt(0.95 * ratio * nrank_tot), nrank_tot / 2, ir.nkx, ir.nky);
     }
     else
     {
-        GMX_LOG(mdlog.info).appendTextFormatted(
-                "Will use %d particle-particle and %d PME only ranks\n"
-                "This is a guess, check the performance at the end of the log file",
-                nrank_tot - npme, npme);
+        GMX_LOG(mdlog.info)
+                .appendTextFormatted(
+                        "Will use %d particle-particle and %d PME only ranks\n"
+                        "This is a guess, check the performance at the end of the log file",
+                        nrank_tot - npme, npme);
     }
 
     return npme;
@@ -266,10 +268,10 @@ static int guess_npme(const gmx::MDLogger &mdlog,
 /*! \brief Return \p n divided by \p f rounded up to the next integer. */
 static int div_up(int n, int f)
 {
-    return (n + f - 1)/f;
+    return (n + f - 1) / f;
 }
 
-real comm_box_frac(const gmx::IVec &dd_nc, real cutoff, const gmx_ddbox_t &ddbox)
+real comm_box_frac(const gmx::IVec& dd_nc, real cutoff, const gmx_ddbox_t& ddbox)
 {
     int  i, j, k;
     rvec nw;
@@ -277,8 +279,8 @@ real comm_box_frac(const gmx::IVec &dd_nc, real cutoff, const gmx_ddbox_t &ddbox
 
     for (i = 0; i < DIM; i++)
     {
-        real bt = ddbox.box_size[i]*ddbox.skew_fac[i];
-        nw[i] = dd_nc[i]*cutoff/bt;
+        real bt = ddbox.box_size[i] * ddbox.skew_fac[i];
+        nw[i]   = dd_nc[i] * cutoff / bt;
     }
 
     comm_vol = 0;
@@ -287,16 +289,16 @@ real comm_box_frac(const gmx::IVec &dd_nc, real cutoff, const gmx_ddbox_t &ddbox
         if (dd_nc[i] > 1)
         {
             comm_vol += nw[i];
-            for (j = i+1; j < DIM; j++)
+            for (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++)
+                    comm_vol += nw[i] * nw[j] * M_PI / 4;
+                    for (k = j + 1; k < DIM; k++)
                     {
                         if (dd_nc[k] > 1)
                         {
-                            comm_vol += nw[i]*nw[j]*nw[k]*M_PI/6;
+                            comm_vol += nw[i] * nw[j] * nw[k] * M_PI / 6;
                         }
                     }
                 }
@@ -308,10 +310,10 @@ real comm_box_frac(const gmx::IVec &dd_nc, real cutoff, const gmx_ddbox_t &ddbox
 }
 
 /*! \brief Return whether the DD inhomogeneous in the z direction */
-static gmx_bool inhomogeneous_z(const t_inputrec &ir)
+static gmx_bool inhomogeneous_z(const t_inputrecir)
 {
-    return ((EEL_PME(ir.coulombtype) || ir.coulombtype == eelEWALD) &&
-            ir.ePBC == epbcXYZ && ir.ewald_geometry == eewg3DC);
+    return ((EEL_PME(ir.coulombtype) || ir.coulombtype == eelEWALD) && ir.ePBC == epbcXYZ
+            && ir.ewald_geometry == eewg3DC);
 }
 
 /*! \brief Estimate cost of PME FFT communication
@@ -326,7 +328,7 @@ 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;
+    comm_vol = npme - 1;
     comm_vol *= npme;
     comm_vol *= div_up(a, npme);
     comm_vol *= div_up(b, npme);
@@ -336,13 +338,17 @@ static float comm_pme_cost_vol(int npme, int a, int b, int c)
 }
 
 /*! \brief Estimate cost of communication for a possible domain decomposition. */
-static float comm_cost_est(real limit, real cutoff,
-                           const matrix box, const gmx_ddbox_t &ddbox,
-                           int natoms, const t_inputrec &ir,
-                           float pbcdxr,
-                           int npme_tot, const gmx::IVec &nc)
+static float comm_cost_est(real               limit,
+                           real               cutoff,
+                           const matrix       box,
+                           const gmx_ddbox_t& ddbox,
+                           int                natoms,
+                           const t_inputrec&  ir,
+                           float              pbcdxr,
+                           int                npme_tot,
+                           const gmx::IVec&   nc)
 {
-    gmx::IVec npme = {1, 1, 1};
+    gmx::IVec npme = { 1, 1, 1 };
     int       i, j, nk, overlap;
     rvec      bt;
     float     comm_vol, comm_vol_xf, comm_pme, cost_pbcdx;
@@ -356,8 +362,8 @@ static float comm_cost_est(real limit, real cutoff,
     float temp;
 
     /* Check the DD algorithm restrictions */
-    if ((ir.ePBC == epbcXY && ir.nwall < 2 && nc[ZZ] > 1) ||
-        (ir.ePBC == epbcSCREW && (nc[XX] == 1 || nc[YY] > 1 || nc[ZZ] > 1)))
+    if ((ir.ePBC == epbcXY && ir.nwall < 2 && nc[ZZ] > 1)
+        || (ir.ePBC == epbcSCREW && (nc[XX] == 1 || nc[YY] > 1 || nc[ZZ] > 1)))
     {
         return -1;
     }
@@ -372,10 +378,9 @@ static float comm_cost_est(real limit, real cutoff,
     /* Check if the triclinic requirements are met */
     for (i = 0; i < DIM; i++)
     {
-        for (j = i+1; j < ddbox.npbcdim; j++)
+        for (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))
+            if (box[j][i] != 0 || ir.deform[j][i] != 0 || (ir.epc != epcNO && ir.compress[j][i] != 0))
             {
                 if (nc[j] > 1 && nc[i] == 1)
                 {
@@ -387,15 +392,15 @@ static float comm_cost_est(real limit, real cutoff,
 
     for (i = 0; i < DIM; i++)
     {
-        bt[i] = ddbox.box_size[i]*ddbox.skew_fac[i];
+        bt[i] = ddbox.box_size[i] * ddbox.skew_fac[i];
 
         /* Without PBC and with 2 cells, there are no lower limits on the cell size */
-        if (!(i >= ddbox.npbcdim && nc[i] <= 2) && bt[i] < nc[i]*limit)
+        if (!(i >= ddbox.npbcdim && nc[i] <= 2) && bt[i] < nc[i] * limit)
         {
             return -1;
         }
         /* With PBC, check if the cut-off fits in nc[i]-1 cells */
-        if (i < ddbox.npbcdim && nc[i] > 1 && (nc[i] - 1)*bt[i] < nc[i]*cutoff)
+        if (i < ddbox.npbcdim && nc[i] > 1 && (nc[i] - 1) * bt[i] < nc[i] * cutoff)
         {
             return -1;
         }
@@ -420,7 +425,7 @@ static float comm_cost_est(real limit, real cutoff,
         {
             /* Will we use 1D or 2D PME decomposition? */
             npme[XX] = (npme_tot % nc[XX] == 0) ? nc[XX] : npme_tot;
-            npme[YY] = npme_tot/npme[XX];
+            npme[YY] = npme_tot / npme[XX];
         }
     }
 
@@ -439,8 +444,8 @@ static float comm_cost_est(real limit, real cutoff,
          */
         bool useThreads     = true;
         bool errorsAreFatal = false;
-        if (!gmx_pme_check_restrictions(ir.pme_order, ir.nkx, ir.nky, ir.nkz,
-                                        npme_x, useThreads, errorsAreFatal))
+        if (!gmx_pme_check_restrictions(ir.pme_order, ir.nkx, ir.nky, ir.nkz, npme_x, useThreads,
+                                        errorsAreFatal))
         {
             return -1;
         }
@@ -452,12 +457,12 @@ static float comm_cost_est(real limit, real cutoff,
      */
     for (i = 0; i < DIM; i++)
     {
-        for (j = i+1; j < DIM; j++)
+        for (j = i + 1; j < DIM; j++)
         {
             /* Check if the box size is nearly identical,
              * in that case we prefer nx > ny  and ny > nz.
              */
-            if (std::fabs(bt[j] - bt[i]) < 0.01*bt[i] && nc[j] > nc[i])
+            if (std::fabs(bt[j] - bt[i]) < 0.01 * bt[i] && nc[j] > nc[i])
             {
                 /* The XX/YY check is a bit compact. If nc[YY]==npme[YY]
                  * this means the swapped nc has nc[XX]==npme[XX],
@@ -467,9 +472,8 @@ static float comm_cost_est(real limit, real cutoff,
                  * For x/y: if nc[YY]!=npme[YY], we can not swap x/y
                  * For y/z: we can not have PME decomposition in z
                  */
-                if (npme_tot <= 1 ||
-                    !((i == XX && j == YY && nc[YY] != npme[YY]) ||
-                      (i == YY && j == ZZ && npme[YY] > 1)))
+                if (npme_tot <= 1
+                    || !((i == XX && j == YY && nc[YY] != npme[YY]) || (i == YY && j == ZZ && npme[YY] > 1)))
                 {
                     return -1;
                 }
@@ -492,28 +496,28 @@ static float comm_cost_est(real limit, real cutoff,
         {
             if (nc[i] > npme[i])
             {
-                comm_vol_xf = (npme[i] == 2 ? 1.0/3.0 : 0.5);
+                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]);
+                comm_vol_xf = 1.0 - lcd(nc[i], npme[i]) / static_cast<double>(npme[i]);
             }
-            comm_pme += 3*natoms*comm_vol_xf;
+            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];
-            temp     *= overlap;
-            temp     *= ir.nkx;
-            temp     *= ir.nky;
-            temp     *= ir.nkz;
-            temp     /= nk;
+            nk      = (i == 0 ? ir.nkx : ir.nky);
+            overlap = (nk % npme[i] == 0 ? ir.pme_order - 1 : ir.pme_order);
+            temp    = npme[i];
+            temp *= overlap;
+            temp *= ir.nkx;
+            temp *= ir.nky;
+            temp *= ir.nkz;
+            temp /= nk;
             comm_pme += temp;
-/* Old line comm_pme += npme[i]*overlap*ir.nkx*ir.nky*ir.nkz/nk; */
+            /* Old line comm_pme += npme[i]*overlap*ir.nkx*ir.nky*ir.nkz/nk; */
         }
     }
 
@@ -524,48 +528,51 @@ static float comm_cost_est(real limit, real cutoff,
     cost_pbcdx = 0;
     if ((nc[XX] == 1 || nc[YY] == 1) || (nc[ZZ] == 1 && ir.ePBC != epbcXY))
     {
-        if ((ddbox.tric_dir[XX] && nc[XX] == 1) ||
-            (ddbox.tric_dir[YY] && nc[YY] == 1))
+        if ((ddbox.tric_dir[XX] && nc[XX] == 1) || (ddbox.tric_dir[YY] && nc[YY] == 1))
         {
-            cost_pbcdx = pbcdxr*pbcdx_tric_fac;
+            cost_pbcdx = pbcdxr * pbcdx_tric_fac;
         }
         else
         {
-            cost_pbcdx = pbcdxr*pbcdx_rect_fac;
+            cost_pbcdx = pbcdxr * pbcdx_rect_fac;
         }
     }
 
     if (debug)
     {
-        fprintf(debug,
-                "nc %2d %2d %2d %2d %2d vol pp %6.4f pbcdx %6.4f pme %9.3e tot %9.3e\n",
-                nc[XX], nc[YY], nc[ZZ], npme[XX], npme[YY],
-                comm_vol, cost_pbcdx, comm_pme/(3*natoms),
-                comm_vol + cost_pbcdx + comm_pme/(3*natoms));
+        fprintf(debug, "nc %2d %2d %2d %2d %2d vol pp %6.4f pbcdx %6.4f pme %9.3e tot %9.3e\n",
+                nc[XX], nc[YY], nc[ZZ], npme[XX], npme[YY], comm_vol, cost_pbcdx,
+                comm_pme / (3 * natoms), comm_vol + cost_pbcdx + comm_pme / (3 * natoms));
     }
 
-    return 3*natoms*(comm_vol + cost_pbcdx) + comm_pme;
+    return 3 * natoms * (comm_vol + cost_pbcdx) + comm_pme;
 }
 
 /*! \brief Assign penalty factors to possible domain decompositions,
  * based on the estimated communication costs. */
-static void assign_factors(const real limit, const bool request1D,
-                           const real cutoff,
-                           const matrix box, const gmx_ddbox_t &ddbox,
-                           int natoms, const t_inputrec &ir,
-                           float pbcdxr, int npme,
-                           int ndiv, const int *div, const int *mdiv,
-                           gmx::IVec *irTryPtr,
-                           gmx::IVec *opt)
+static void assign_factors(const real         limit,
+                           const bool         request1D,
+                           const real         cutoff,
+                           const matrix       box,
+                           const gmx_ddbox_t& ddbox,
+                           int                natoms,
+                           const t_inputrec&  ir,
+                           float              pbcdxr,
+                           int                npme,
+                           int                ndiv,
+                           const int*         div,
+                           const int*         mdiv,
+                           gmx::IVec*         irTryPtr,
+                           gmx::IVec*         opt)
 {
     int        x, y, i;
     float      ce;
-    gmx::IVec &ir_try = *irTryPtr;
+    gmx::IVecir_try = *irTryPtr;
 
     if (ndiv == 0)
     {
-        const int  maxDimensionSize             = std::max(ir_try[XX], std::max(ir_try[YY], ir_try[ZZ]));
-        const int  productOfDimensionSizes      = ir_try[XX]*ir_try[YY]*ir_try[ZZ];
+        const int  maxDimensionSize        = std::max(ir_try[XX], std::max(ir_try[YY], ir_try[ZZ]));
+        const int  productOfDimensionSizes = ir_try[XX] * ir_try[YY] * ir_try[ZZ];
         const bool decompositionHasOneDimension = (maxDimensionSize == productOfDimensionSizes);
         if (request1D && !decompositionHasOneDimension)
         {
@@ -573,12 +580,10 @@ static void assign_factors(const real limit, const bool request1D,
             return;
         }
 
-        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)))
+        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)))
         {
             *opt = ir_try;
         }
@@ -592,23 +597,22 @@ static void assign_factors(const real limit, const bool request1D,
         {
             ir_try[XX] *= div[0];
         }
-        for (y = mdiv[0]-x; y >= 0; y--)
+        for (y = mdiv[0] - x; y >= 0; y--)
         {
             for (i = 0; i < y; i++)
             {
                 ir_try[YY] *= div[0];
             }
-            for (i = 0; i < mdiv[0]-x-y; i++)
+            for (i = 0; i < mdiv[0] - x - y; i++)
             {
                 ir_try[ZZ] *= div[0];
             }
 
             /* recurse */
-            assign_factors(limit, request1D,
-                           cutoff, box, ddbox, natoms, ir, pbcdxr, npme,
-                           ndiv-1, div+1, mdiv+1, irTryPtr, opt);
+            assign_factors(limit, request1D, 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 (i = 0; i < mdiv[0] - x - y; i++)
             {
                 ir_try[ZZ] /= div[0];
             }
@@ -629,39 +633,40 @@ static void assign_factors(const real limit, const bool request1D,
  *
  * \returns The optimal grid cell choice. The latter will contain all
  *          zeros if no valid cell choice exists. */
-static gmx::IVec
-optimizeDDCells(const gmx::MDLogger &mdlog,
-                const int            numRanksRequested,
-                const int            numPmeOnlyRanks,
-                const real           cellSizeLimit,
-                const bool           request1DAnd1Pulse,
-                const gmx_mtop_t    &mtop,
-                const matrix         box,
-                const gmx_ddbox_t   &ddbox,
-                const t_inputrec    &ir,
-                const DDSystemInfo  &systemInfo)
+static gmx::IVec optimizeDDCells(const gmx::MDLogger& mdlog,
+                                 const int            numRanksRequested,
+                                 const int            numPmeOnlyRanks,
+                                 const real           cellSizeLimit,
+                                 const bool           request1DAnd1Pulse,
+                                 const gmx_mtop_t&    mtop,
+                                 const matrix         box,
+                                 const gmx_ddbox_t&   ddbox,
+                                 const t_inputrec&    ir,
+                                 const DDSystemInfo&  systemInfo)
 {
-    double    pbcdxr;
+    double pbcdxr;
 
     const int numPPRanks = numRanksRequested - numPmeOnlyRanks;
 
-    GMX_LOG(mdlog.info).appendTextFormatted(
-            "Optimizing the DD grid for %d cells with a minimum initial size of %.3f nm",
-            numPPRanks, cellSizeLimit);
+    GMX_LOG(mdlog.info)
+            .appendTextFormatted(
+                    "Optimizing the DD grid for %d cells with a minimum initial size of %.3f nm",
+                    numPPRanks, cellSizeLimit);
     if (inhomogeneous_z(ir))
     {
-        GMX_LOG(mdlog.info).appendTextFormatted(
-                "Ewald_geometry=%s: assuming inhomogeneous particle distribution in z, will not decompose in z.",
-                eewg_names[ir.ewald_geometry]);
+        GMX_LOG(mdlog.info)
+                .appendTextFormatted(
+                        "Ewald_geometry=%s: assuming inhomogeneous particle distribution in z, "
+                        "will not decompose in z.",
+                        eewg_names[ir.ewald_geometry]);
     }
 
 
     // For cost estimates, we need the number of ranks doing PME work,
     // which is the number of PP ranks when not using separate
     // PME-only ranks.
-    const int numRanksDoingPmeWork = (EEL_PME(ir.coulombtype) ?
-                                      ((numPmeOnlyRanks > 0) ? numPmeOnlyRanks : numPPRanks) :
-                                      0);
+    const int numRanksDoingPmeWork =
+            (EEL_PME(ir.coulombtype) ? ((numPmeOnlyRanks > 0) ? numPmeOnlyRanks : numPPRanks) : 0);
 
     if (systemInfo.haveInterDomainBondeds)
     {
@@ -683,7 +688,7 @@ optimizeDDCells(const gmx::MDLogger &mdlog,
         std::string maximumCells = "The maximum allowed number of cells is:";
         for (int d = 0; d < DIM; d++)
         {
-            int nmax = static_cast<int>(ddbox.box_size[d]*ddbox.skew_fac[d]/cellSizeLimit);
+            int nmax = static_cast<int>(ddbox.box_size[d] * ddbox.skew_fac[d] / cellSizeLimit);
             if (d >= ddbox.npbcdim && nmax < 2)
             {
                 nmax = 2;
@@ -709,20 +714,18 @@ optimizeDDCells(const gmx::MDLogger &mdlog,
 
     gmx::IVec itry       = { 1, 1, 1 };
     gmx::IVec numDomains = { 0, 0, 0 };
-    assign_factors(cellSizeLimit, request1DAnd1Pulse,
-                   systemInfo.cutoff, box, ddbox, mtop.natoms, ir, pbcdxr,
-                   numRanksDoingPmeWork, div.size(), div.data(), mdiv.data(), &itry, &numDomains);
+    assign_factors(cellSizeLimit, request1DAnd1Pulse, systemInfo.cutoff, box, ddbox, mtop.natoms, ir,
+                   pbcdxr, numRanksDoingPmeWork, div.size(), div.data(), mdiv.data(), &itry, &numDomains);
 
     return numDomains;
 }
 
-real
-getDDGridSetupCellSizeLimit(const gmx::MDLogger &mdlog,
-                            const bool           request1DAnd1Pulse,
-                            const bool           bDynLoadBal,
-                            const real           dlb_scale,
-                            const t_inputrec    &ir,
-                            const real           systemInfoCellSizeLimit)
+real getDDGridSetupCellSizeLimit(const gmx::MDLogger& mdlog,
+                                 const bool           request1DAnd1Pulse,
+                                 const bool           bDynLoadBal,
+                                 const real           dlb_scale,
+                                 const t_inputrec&    ir,
+                                 const real           systemInfoCellSizeLimit)
 {
     real cellSizeLimit = systemInfoCellSizeLimit;
     if (request1DAnd1Pulse)
@@ -737,25 +740,24 @@ getDDGridSetupCellSizeLimit(const gmx::MDLogger &mdlog,
         {
             gmx_fatal(FARGS, "The value for option -dds should be smaller than 1");
         }
-        GMX_LOG(mdlog.info).appendTextFormatted(
-                "Scaling the initial minimum size with 1/%g (option -dds) = %g",
-                dlb_scale, 1/dlb_scale);
+        GMX_LOG(mdlog.info)
+                .appendTextFormatted(
+                        "Scaling the initial minimum size with 1/%g (option -dds) = %g", dlb_scale,
+                        1 / dlb_scale);
         cellSizeLimit /= dlb_scale;
     }
     else if (ir.epc != epcNO)
     {
-        GMX_LOG(mdlog.info).appendTextFormatted(
-                "To account for pressure scaling, scaling the initial minimum size with %g",
-                DD_GRID_MARGIN_PRES_SCALE);
+        GMX_LOG(mdlog.info)
+                .appendTextFormatted(
+                        "To account for pressure scaling, scaling the initial minimum size with %g",
+                        DD_GRID_MARGIN_PRES_SCALE);
         cellSizeLimit *= DD_GRID_MARGIN_PRES_SCALE;
     }
 
     return cellSizeLimit;
 }
-void
-checkForValidRankCountRequests(const int  numRanksRequested,
-                               const bool usingPme,
-                               const int  numPmeRanksRequested)
+void checkForValidRankCountRequests(const int numRanksRequested, const bool usingPme, const int numPmeRanksRequested)
 {
     int numPPRanksRequested = numRanksRequested;
     if (usingPme && numPmeRanksRequested > 0)
@@ -764,7 +766,8 @@ checkForValidRankCountRequests(const int  numRanksRequested,
         if (numPmeRanksRequested > numPPRanksRequested)
         {
             gmx_fatal(FARGS,
-                      "Cannot have %d separate PME ranks with only %d PP ranks, choose fewer or no separate PME ranks",
+                      "Cannot have %d separate PME ranks with only %d PP ranks, choose fewer or no "
+                      "separate PME ranks",
                       numPmeRanksRequested, numPPRanksRequested);
         }
     }
@@ -776,10 +779,10 @@ checkForValidRankCountRequests(const int  numRanksRequested,
     {
         const int largestDivisor = largest_divisor(numPPRanksRequested);
         /* Check if the largest divisor is more than numPPRanks ^ (2/3) */
-        if (largestDivisor*largestDivisor*largestDivisor >
-            numPPRanksRequested*numPPRanksRequested)
+        if (largestDivisor * largestDivisor * largestDivisor > numPPRanksRequested * numPPRanksRequested)
         {
-            gmx_fatal(FARGS, "The number of ranks selected for particle-particle work (%d) "
+            gmx_fatal(FARGS,
+                      "The number of ranks selected for particle-particle work (%d) "
                       "contains a large prime factor %d. In most cases this will lead to "
                       "bad performance. Choose a number with smaller prime factors or "
                       "set the decomposition (option -dd) manually.",
@@ -791,16 +794,15 @@ checkForValidRankCountRequests(const int  numRanksRequested,
 /*! \brief Return the number of PME-only ranks used by the simulation
  *
  * If the user did not choose a number, then decide for them. */
-static int
-getNumPmeOnlyRanksToUse(const gmx::MDLogger &mdlog,
-                        const DomdecOptions &options,
-                        const gmx_mtop_t    &mtop,
-                        const t_inputrec    &ir,
-                        const matrix         box,
-                        const int            numRanksRequested)
+static int getNumPmeOnlyRanksToUse(const gmx::MDLogger& mdlog,
+                                   const DomdecOptions& options,
+                                   const gmx_mtop_t&    mtop,
+                                   const t_inputrec&    ir,
+                                   const matrix         box,
+                                   const int            numRanksRequested)
 {
     int         numPmeOnlyRanks;
-    const char *extraMessage = "";
+    const charextraMessage = "";
 
     if (options.numCells[XX] > 0)
     {
@@ -838,8 +840,9 @@ getNumPmeOnlyRanksToUse(const gmx::MDLogger &mdlog,
                 if (numRanksRequested < minRankCountToDefaultToSeparatePmeRanks)
                 {
                     numPmeOnlyRanks = 0;
-                    extraMessage    = ", as there are too few total\n"
-                        " ranks for efficient splitting";
+                    extraMessage =
+                            ", as there are too few total\n"
+                            " ranks for efficient splitting";
                 }
                 else
                 {
@@ -848,23 +851,19 @@ getNumPmeOnlyRanksToUse(const gmx::MDLogger &mdlog,
                 }
             }
         }
-
     }
     GMX_RELEASE_ASSERT(numPmeOnlyRanks <= numRanksRequested,
                        "Cannot have more PME ranks than total ranks");
     if (EEL_PME(ir.coulombtype))
     {
-        GMX_LOG(mdlog.info).appendTextFormatted
-            ("Using %d separate PME ranks%s", numPmeOnlyRanks, extraMessage);
+        GMX_LOG(mdlog.info).appendTextFormatted("Using %d separate PME ranks%s", numPmeOnlyRanks, extraMessage);
     }
 
     return numPmeOnlyRanks;
 }
 
 /*! \brief Sets the order of the DD dimensions, returns the number of DD dimensions */
-static int set_dd_dim(const gmx::IVec  &numDDCells,
-                      const DDSettings &ddSettings,
-                      ivec             *dims)
+static int set_dd_dim(const gmx::IVec& numDDCells, const DDSettings& ddSettings, ivec* dims)
 {
     int ndim = 0;
     if (ddSettings.useDDOrderZYX)
@@ -899,35 +898,33 @@ static int set_dd_dim(const gmx::IVec  &numDDCells,
     return ndim;
 }
 
-DDGridSetup
-getDDGridSetup(const gmx::MDLogger           &mdlog,
-               const t_commrec               *cr,
-               const int                      numRanksRequested,
-               const DomdecOptions           &options,
-               const DDSettings              &ddSettings,
-               const DDSystemInfo            &systemInfo,
-               const real                     cellSizeLimit,
-               const gmx_mtop_t              &mtop,
-               const t_inputrec              &ir,
-               const matrix                   box,
-               gmx::ArrayRef<const gmx::RVec> xGlobal,
-               gmx_ddbox_t                   *ddbox)
+DDGridSetup getDDGridSetup(const gmx::MDLogger&           mdlog,
+                           const t_commrec*               cr,
+                           const int                      numRanksRequested,
+                           const DomdecOptions&           options,
+                           const DDSettings&              ddSettings,
+                           const DDSystemInfo&            systemInfo,
+                           const real                     cellSizeLimit,
+                           const gmx_mtop_t&              mtop,
+                           const t_inputrec&              ir,
+                           const matrix                   box,
+                           gmx::ArrayRef<const gmx::RVec> xGlobal,
+                           gmx_ddbox_t*                   ddbox)
 {
     int numPmeOnlyRanks = getNumPmeOnlyRanksToUse(mdlog, options, mtop, ir, box, numRanksRequested);
 
-    if (ddSettings.request1DAnd1Pulse &&
-        (numRanksRequested - numPmeOnlyRanks == 1))
+    if (ddSettings.request1DAnd1Pulse && (numRanksRequested - numPmeOnlyRanks == 1))
     {
         // With only one PP rank, there will not be a need for
         // GPU-based halo exchange that wants to request that any DD
         // has only 1 dimension and 1 pulse.
-        return DDGridSetup {};
+        return DDGridSetup{};
     }
 
     gmx::IVec numDomains;
     if (options.numCells[XX] > 0)
     {
-        numDomains = gmx::IVec(options.numCells);
+        numDomains                      = gmx::IVec(options.numCells);
         const ivec numDomainsLegacyIvec = { numDomains[XX], numDomains[YY], numDomains[ZZ] };
         set_ddbox_cr(*cr, &numDomainsLegacyIvec, ir, box, xGlobal, ddbox);
     }
@@ -937,12 +934,8 @@ getDDGridSetup(const gmx::MDLogger           &mdlog,
 
         if (MASTER(cr))
         {
-            numDomains =
-                optimizeDDCells(mdlog, numRanksRequested, numPmeOnlyRanks,
-                                cellSizeLimit,
-                                ddSettings.request1DAnd1Pulse,
-                                mtop, box, *ddbox, ir,
-                                systemInfo);
+            numDomains = optimizeDDCells(mdlog, numRanksRequested, numPmeOnlyRanks, cellSizeLimit,
+                                         ddSettings.request1DAnd1Pulse, mtop, box, *ddbox, ir, systemInfo);
         }
     }