Convert domdec code to C++
[alexxy/gromacs.git] / src / gromacs / mdlib / domdec_setup.cpp
similarity index 98%
rename from src/gromacs/mdlib/domdec_setup.c
rename to src/gromacs/mdlib/domdec_setup.cpp
index 0903c32d14cc479058ac32e7a36aa7c07ffa9f0d..1d03b26bea2b00791fd2a038811a39e91763075f 100644 (file)
@@ -36,6 +36,7 @@
 #include "gmxpre.h"
 
 #include <assert.h>
+#include <cmath>
 #include <stdio.h>
 
 #include "gromacs/legacyheaders/domdec.h"
@@ -125,8 +126,8 @@ static gmx_bool fits_pp_pme_perf(int nnodes, int npme, float ratio)
     sfree(div);
     sfree(mdiv);
 
-    npp_root3  = (int)(pow(nnodes-npme, 1.0/3.0) + 0.5);
-    npme_root2 = (int)(sqrt(npme) + 0.5);
+    npp_root3  = static_cast<int>(std::pow(nnodes-npme, 1.0/3.0) + 0.5);
+    npme_root2 = static_cast<int>(std::sqrt(static_cast<double>(npme)) + 0.5);
 
     /* The check below gives a reasonable division:
      * factor 5 allowed at 5 or more PP nodes,
@@ -156,8 +157,7 @@ static int guess_npme(FILE *fplog, gmx_mtop_t *mtop, t_inputrec *ir, matrix box,
                       int nnodes)
 {
     float      ratio;
-    int        npme, nkx, nky;
-    t_inputrec ir_try;
+    int        npme;
 
     ratio = pme_load_estimate(mtop, ir, box);
 
@@ -247,7 +247,7 @@ static int div_up(int n, int f)
 
 real comm_box_frac(ivec dd_nc, real cutoff, gmx_ddbox_t *ddbox)
 {
-    int  i, j, k, npp;
+    int  i, j, k;
     rvec bt, nw;
     real comm_vol;
 
@@ -257,13 +257,11 @@ real comm_box_frac(ivec dd_nc, real cutoff, gmx_ddbox_t *ddbox)
         nw[i] = dd_nc[i]*cutoff/bt[i];
     }
 
-    npp      = 1;
     comm_vol = 0;
     for (i = 0; i < DIM; i++)
     {
         if (dd_nc[i] > 1)
         {
-            npp      *= dd_nc[i];
             comm_vol += nw[i];
             for (j = i+1; j < DIM; j++)
             {
@@ -311,7 +309,7 @@ static float comm_cost_est(real limit, real cutoff,
                            int npme_tot, ivec nc)
 {
     ivec  npme = {1, 1, 1};
-    int   i, j, k, nk, overlap;
+    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
@@ -506,7 +504,7 @@ static void assign_factors(gmx_domdec_t *dd,
                            float pbcdxr, int npme,
                            int ndiv, int *div, int *mdiv, ivec ir_try, ivec opt)
 {
-    int   x, y, z, i;
+    int   x, y, i;
     float ce;
 
     if (ndiv == 0)