Code beautification with uncrustify
[alexxy/gromacs.git] / src / programs / mdrun / pme_loadbal.c
index 3fff053d1dae1f9e1f6f339887e9c8e3c9beeae5..f7c1985b757342e82143acef119f56a296fb4854 100644 (file)
@@ -1,12 +1,12 @@
 /* -*- mode: c; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; c-file-style: "stroustrup"; -*-
  *
- * 
+ *
  *                This source code is part of
- * 
+ *
  *                 G   R   O   M   A   C   S
- * 
+ *
  *          GROningen MAchine for Chemical Simulations
- * 
+ *
  *                        VERSION 4.6.0
  * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * modify it under the terms of the GNU General Public License
  * as published by the Free Software Foundation; either version 2
  * of the License, or (at your option) any later version.
- * 
+ *
  * If you want to redistribute modifications, please consider that
  * scientific software is very special. Version control is crucial -
  * bugs must be traceable. We will be happy to consider code for
  * inclusion in the official distribution, but derived work must not
  * be called official GROMACS. Details are found in the README & COPYING
  * files - if they are missing, get the official version at www.gromacs.org.
- * 
+ *
  * To help us fund GROMACS development, we humbly ask that you cite
  * the papers on the package - you can find them in the top README file.
- * 
+ *
  * For more info, check our website at http://www.gromacs.org
- * 
+ *
  * And Hey:
  * Gallium Rubidium Oxygen Manganese Argon Carbon Silicon
  */
 
 /* Parameters and setting for one PP-PME setup */
 typedef struct {
-    real rcut_coulomb;    /* Coulomb cut-off                              */
-    real rlist;           /* pair-list cut-off                            */
-    real rlistlong;       /* LR pair-list cut-off                         */
-    int  nstcalclr;       /* frequency of evaluating long-range forces for group scheme */
-    real spacing;         /* (largest) PME grid spacing                   */
-    ivec grid;            /* the PME grid dimensions                      */
-    real grid_efficiency; /* ineffiency factor for non-uniform grids <= 1 */
-    real ewaldcoeff;      /* the Ewald coefficient                        */
-    gmx_pme_t pmedata;    /* the data structure used in the PME code      */
-
-    int  count;           /* number of times this setup has been timed    */
-    double cycles;        /* the fastest time for this setup in cycles    */
+    real      rcut_coulomb;    /* Coulomb cut-off                              */
+    real      rlist;           /* pair-list cut-off                            */
+    real      rlistlong;       /* LR pair-list cut-off                         */
+    int       nstcalclr;       /* frequency of evaluating long-range forces for group scheme */
+    real      spacing;         /* (largest) PME grid spacing                   */
+    ivec      grid;            /* the PME grid dimensions                      */
+    real      grid_efficiency; /* ineffiency factor for non-uniform grids <= 1 */
+    real      ewaldcoeff;      /* the Ewald coefficient                        */
+    gmx_pme_t pmedata;         /* the data structure used in the PME code      */
+
+    int       count;           /* number of times this setup has been timed    */
+    double    cycles;          /* the fastest time for this setup in cycles    */
 } pme_setup_t;
 
 /* In the initial scan, step by grids that are at least a factor 0.8 coarser */
@@ -77,57 +77,59 @@ typedef struct {
  */
 #define PME_LB_ACCEL_TOL 1.02
 
-enum { epmelblimNO, epmelblimBOX, epmelblimDD, epmelblimNR };
+enum {
+    epmelblimNO, epmelblimBOX, epmelblimDD, epmelblimNR
+};
 
 const char *pmelblim_str[epmelblimNR] =
 { "no", "box size", "domain decompostion" };
 
 struct pme_load_balancing {
-    int  nstage;        /* the current maximum number of stages */
-
-    real cut_spacing;   /* the minimum cutoff / PME grid spacing ratio */
-    real rcut_vdw;      /* Vdw cutoff (does not change) */
-    real rcut_coulomb_start; /* Initial electrostatics cutoff */
-    int  nstcalclr_start; /* Initial electrostatics cutoff */
-    real rbuf_coulomb;  /* the pairlist buffer size */
-    real rbuf_vdw;      /* the pairlist buffer size */
-    matrix box_start;   /* the initial simulation box */
-    int n;              /* the count of setup as well as the allocation size */
-    pme_setup_t *setup; /* the PME+cutoff setups */
-    int cur;            /* the current setup */
-    int fastest;        /* fastest setup up till now */
-    int start;          /* start of setup range to consider in stage>0 */
-    int end;            /* end   of setup range to consider in stage>0 */
-    int elimited;       /* was the balancing limited, uses enum above */
-    int cutoff_scheme;  /* Verlet or group cut-offs */
-
-    int stage;          /* the current stage */
+    int          nstage;             /* the current maximum number of stages */
+
+    real         cut_spacing;        /* the minimum cutoff / PME grid spacing ratio */
+    real         rcut_vdw;           /* Vdw cutoff (does not change) */
+    real         rcut_coulomb_start; /* Initial electrostatics cutoff */
+    int          nstcalclr_start;    /* Initial electrostatics cutoff */
+    real         rbuf_coulomb;       /* the pairlist buffer size */
+    real         rbuf_vdw;           /* the pairlist buffer size */
+    matrix       box_start;          /* the initial simulation box */
+    int          n;                  /* the count of setup as well as the allocation size */
+    pme_setup_t *setup;              /* the PME+cutoff setups */
+    int          cur;                /* the current setup */
+    int          fastest;            /* fastest setup up till now */
+    int          start;              /* start of setup range to consider in stage>0 */
+    int          end;                /* end   of setup range to consider in stage>0 */
+    int          elimited;           /* was the balancing limited, uses enum above */
+    int          cutoff_scheme;      /* Verlet or group cut-offs */
+
+    int          stage;              /* the current stage */
 };
 
 void pme_loadbal_init(pme_load_balancing_t *pme_lb_p,
-                      const t_inputrec *ir,matrix box,
+                      const t_inputrec *ir, matrix box,
                       const interaction_const_t *ic,
                       gmx_pme_t pmedata)
 {
     pme_load_balancing_t pme_lb;
-    real spm,sp;
-    int  d;
+    real                 spm, sp;
+    int                  d;
 
-    snew(pme_lb,1);
+    snew(pme_lb, 1);
 
     /* Any number of stages >= 2 is supported */
     pme_lb->nstage   = 2;
 
     pme_lb->cutoff_scheme = ir->cutoff_scheme;
 
-    if(pme_lb->cutoff_scheme == ecutsVERLET)
+    if (pme_lb->cutoff_scheme == ecutsVERLET)
     {
         pme_lb->rbuf_coulomb = ic->rlist - ic->rcoulomb;
         pme_lb->rbuf_vdw     = pme_lb->rbuf_coulomb;
     }
     else
     {
-        if(ic->rcoulomb > ic->rlist)
+        if (ic->rcoulomb > ic->rlist)
         {
             pme_lb->rbuf_coulomb = ic->rlistlong - ic->rcoulomb;
         }
@@ -135,7 +137,7 @@ void pme_loadbal_init(pme_load_balancing_t *pme_lb_p,
         {
             pme_lb->rbuf_coulomb = ic->rlist - ic->rcoulomb;
         }
-        if(ic->rvdw > ic->rlist)
+        if (ic->rvdw > ic->rlist)
         {
             pme_lb->rbuf_vdw = ic->rlistlong - ic->rvdw;
         }
@@ -145,20 +147,20 @@ void pme_loadbal_init(pme_load_balancing_t *pme_lb_p,
         }
     }
 
-    copy_mat(box,pme_lb->box_start);
-    if (ir->ePBC==epbcXY && ir->nwall==2)
+    copy_mat(box, pme_lb->box_start);
+    if (ir->ePBC == epbcXY && ir->nwall == 2)
     {
-        svmul(ir->wall_ewald_zfac,pme_lb->box_start[ZZ],pme_lb->box_start[ZZ]);
+        svmul(ir->wall_ewald_zfac, pme_lb->box_start[ZZ], pme_lb->box_start[ZZ]);
     }
 
     pme_lb->n = 1;
-    snew(pme_lb->setup,pme_lb->n);
+    snew(pme_lb->setup, pme_lb->n);
 
     pme_lb->rcut_vdw              = ic->rvdw;
     pme_lb->rcut_coulomb_start    = ir->rcoulomb;
     pme_lb->nstcalclr_start       = ir->nstcalclr;
-    
-    pme_lb->cur = 0;
+
+    pme_lb->cur                   = 0;
     pme_lb->setup[0].rcut_coulomb = ic->rcoulomb;
     pme_lb->setup[0].rlist        = ic->rlist;
     pme_lb->setup[0].rlistlong    = ic->rlistlong;
@@ -169,9 +171,9 @@ void pme_loadbal_init(pme_load_balancing_t *pme_lb_p,
     pme_lb->setup[0].ewaldcoeff   = ic->ewaldcoeff;
 
     pme_lb->setup[0].pmedata  = pmedata;
-    
+
     spm = 0;
-    for(d=0; d<DIM; d++)
+    for (d = 0; d < DIM; d++)
     {
         sp = norm(pme_lb->box_start[d])/pme_lb->setup[0].grid[d];
         if (sp > spm)
@@ -201,17 +203,17 @@ void pme_loadbal_init(pme_load_balancing_t *pme_lb_p,
 }
 
 static gmx_bool pme_loadbal_increase_cutoff(pme_load_balancing_t pme_lb,
-                                            int pme_order)
+                                            int                  pme_order)
 {
     pme_setup_t *set;
-    real fac,sp;
-    real tmpr_coulomb,tmpr_vdw;
-    int d;
+    real         fac, sp;
+    real         tmpr_coulomb, tmpr_vdw;
+    int          d;
 
     /* Try to add a new setup with next larger cut-off to the list */
     pme_lb->n++;
-    srenew(pme_lb->setup,pme_lb->n);
-    set = &pme_lb->setup[pme_lb->n-1];
+    srenew(pme_lb->setup, pme_lb->n);
+    set          = &pme_lb->setup[pme_lb->n-1];
     set->pmedata = NULL;
 
     fac = 1;
@@ -219,7 +221,7 @@ static gmx_bool pme_loadbal_increase_cutoff(pme_load_balancing_t pme_lb,
     {
         fac *= 1.01;
         clear_ivec(set->grid);
-        sp = calc_grid(NULL,pme_lb->box_start,
+        sp = calc_grid(NULL, pme_lb->box_start,
                        fac*pme_lb->setup[pme_lb->cur].spacing,
                        &set->grid[XX],
                        &set->grid[YY],
@@ -228,7 +230,7 @@ static gmx_bool pme_loadbal_increase_cutoff(pme_load_balancing_t pme_lb,
         /* In parallel we can't have grids smaller than 2*pme_order,
          * and we would anyhow not gain much speed at these grid sizes.
          */
-        for(d=0; d<DIM; d++)
+        for (d = 0; d < DIM; d++)
         {
             if (set->grid[d] <= 2*pme_order)
             {
@@ -242,7 +244,7 @@ static gmx_bool pme_loadbal_increase_cutoff(pme_load_balancing_t pme_lb,
 
     set->rcut_coulomb = pme_lb->cut_spacing*sp;
 
-    if(pme_lb->cutoff_scheme == ecutsVERLET)
+    if (pme_lb->cutoff_scheme == ecutsVERLET)
     {
         set->rlist        = set->rcut_coulomb + pme_lb->rbuf_coulomb;
         /* We dont use LR lists with Verlet, but this avoids if-statements in further checks */
@@ -252,16 +254,16 @@ static gmx_bool pme_loadbal_increase_cutoff(pme_load_balancing_t pme_lb,
     {
         tmpr_coulomb          = set->rcut_coulomb + pme_lb->rbuf_coulomb;
         tmpr_vdw              = pme_lb->rcut_vdw + pme_lb->rbuf_vdw;
-        set->rlist            = min(tmpr_coulomb,tmpr_vdw);
-        set->rlistlong        = max(tmpr_coulomb,tmpr_vdw);
-        
+        set->rlist            = min(tmpr_coulomb, tmpr_vdw);
+        set->rlistlong        = max(tmpr_coulomb, tmpr_vdw);
+
         /* Set the long-range update frequency */
-        if(set->rlist == set->rlistlong)
+        if (set->rlist == set->rlistlong)
         {
             /* No long-range interactions if the short-/long-range cutoffs are identical */
             set->nstcalclr = 0;
         }
-        else if(pme_lb->nstcalclr_start==0 || pme_lb->nstcalclr_start==1)
+        else if (pme_lb->nstcalclr_start == 0 || pme_lb->nstcalclr_start == 1)
         {
             /* We were not doing long-range before, but now we are since rlist!=rlistlong */
             set->nstcalclr = 1;
@@ -269,7 +271,7 @@ static gmx_bool pme_loadbal_increase_cutoff(pme_load_balancing_t pme_lb,
         else
         {
             /* We were already doing long-range interactions from the start */
-            if(pme_lb->rcut_vdw > pme_lb->rcut_coulomb_start)
+            if (pme_lb->rcut_vdw > pme_lb->rcut_coulomb_start)
             {
                 /* We were originally doing long-range VdW-only interactions.
                  * If rvdw is still longer than rcoulomb we keep the original nstcalclr,
@@ -287,11 +289,11 @@ static gmx_bool pme_loadbal_increase_cutoff(pme_load_balancing_t pme_lb,
             }
         }
     }
-    
+
     set->spacing      = sp;
     /* The grid efficiency is the size wrt a grid with uniform x/y/z spacing */
     set->grid_efficiency = 1;
-    for(d=0; d<DIM; d++)
+    for (d = 0; d < DIM; d++)
     {
         set->grid_efficiency *= (set->grid[d]*sp)/norm(pme_lb->box_start[d]);
     }
@@ -304,39 +306,39 @@ static gmx_bool pme_loadbal_increase_cutoff(pme_load_balancing_t pme_lb,
 
     if (debug)
     {
-        fprintf(debug,"PME loadbal: grid %d %d %d, coulomb cutoff %f\n",
-                set->grid[XX],set->grid[YY],set->grid[ZZ],set->rcut_coulomb);
+        fprintf(debug, "PME loadbal: grid %d %d %d, coulomb cutoff %f\n",
+                set->grid[XX], set->grid[YY], set->grid[ZZ], set->rcut_coulomb);
     }
     return TRUE;
 }
 
-static void print_grid(FILE *fp_err,FILE *fp_log,
+static void print_grid(FILE *fp_err, FILE *fp_log,
                        const char *pre,
                        const char *desc,
                        const pme_setup_t *set,
                        double cycles)
 {
-    char buf[STRLEN],buft[STRLEN];
+    char buf[STRLEN], buft[STRLEN];
 
     if (cycles >= 0)
     {
-        sprintf(buft,": %.1f M-cycles",cycles*1e-6);
+        sprintf(buft, ": %.1f M-cycles", cycles*1e-6);
     }
     else
     {
         buft[0] = '\0';
     }
-    sprintf(buf,"%-11s%10s pme grid %d %d %d, coulomb cutoff %.3f%s",
+    sprintf(buf, "%-11s%10s pme grid %d %d %d, coulomb cutoff %.3f%s",
             pre,
-            desc,set->grid[XX],set->grid[YY],set->grid[ZZ],set->rcut_coulomb,
+            desc, set->grid[XX], set->grid[YY], set->grid[ZZ], set->rcut_coulomb,
             buft);
     if (fp_err != NULL)
     {
-        fprintf(fp_err,"\r%s\n",buf);
+        fprintf(fp_err, "\r%s\n", buf);
     }
     if (fp_log != NULL)
     {
-        fprintf(fp_log,"%s\n",buf);
+        fprintf(fp_log, "%s\n", buf);
     }
 }
 
@@ -353,23 +355,23 @@ static int pme_loadbal_end(pme_load_balancing_t pme_lb)
     }
 }
 
-static void print_loadbal_limited(FILE *fp_err,FILE *fp_log,
+static void print_loadbal_limited(FILE *fp_err, FILE *fp_log,
                                   gmx_large_int_t step,
                                   pme_load_balancing_t pme_lb)
 {
-    char buf[STRLEN],sbuf[22];
+    char buf[STRLEN], sbuf[22];
 
-    sprintf(buf,"step %4s: the %s limited the PME load balancing to a coulomb cut-off of %.3f",
-            gmx_step_str(step,sbuf),
+    sprintf(buf, "step %4s: the %s limited the PME load balancing to a coulomb cut-off of %.3f",
+            gmx_step_str(step, sbuf),
             pmelblim_str[pme_lb->elimited],
             pme_lb->setup[pme_loadbal_end(pme_lb)-1].rcut_coulomb);
     if (fp_err != NULL)
     {
-        fprintf(fp_err,"\r%s\n",buf);
+        fprintf(fp_err, "\r%s\n", buf);
     }
     if (fp_log != NULL)
     {
-        fprintf(fp_log,"%s\n",buf);
+        fprintf(fp_log, "%s\n", buf);
     }
 }
 
@@ -405,23 +407,23 @@ static void switch_to_stage1(pme_load_balancing_t pme_lb)
 }
 
 gmx_bool pme_load_balance(pme_load_balancing_t pme_lb,
-                          t_commrec *cr,
-                          FILE *fp_err,
-                          FILE *fp_log,
-                          t_inputrec *ir,
-                          t_state *state,
-                          double cycles,
+                          t_commrec           *cr,
+                          FILE                *fp_err,
+                          FILE                *fp_log,
+                          t_inputrec          *ir,
+                          t_state             *state,
+                          double               cycles,
                           interaction_const_t *ic,
-                          nonbonded_verlet_t *nbv,
-                          gmx_pme_t *pmedata,
-                          gmx_large_int_t step)
+                          nonbonded_verlet_t  *nbv,
+                          gmx_pme_t           *pmedata,
+                          gmx_large_int_t      step)
 {
-    gmx_bool OK;
+    gmx_bool     OK;
     pme_setup_t *set;
-    double cycles_fast;
-    char buf[STRLEN],sbuf[22];
-    real rtab;
-    gmx_bool bUsesSimpleTables = TRUE;
+    double       cycles_fast;
+    char         buf[STRLEN], sbuf[22];
+    real         rtab;
+    gmx_bool     bUsesSimpleTables = TRUE;
 
     if (pme_lb->stage == pme_lb->nstage)
     {
@@ -430,7 +432,7 @@ gmx_bool pme_load_balance(pme_load_balancing_t pme_lb,
 
     if (PAR(cr))
     {
-        gmx_sumd(1,&cycles,cr);
+        gmx_sumd(1, &cycles, cr);
         cycles /= cr->nnodes;
     }
 
@@ -447,8 +449,8 @@ gmx_bool pme_load_balance(pme_load_balancing_t pme_lb,
         return TRUE;
     }
 
-    sprintf(buf, "step %4s: ", gmx_step_str(step,sbuf));
-    print_grid(fp_err,fp_log,buf,"timed with",set,cycles);
+    sprintf(buf, "step %4s: ", gmx_step_str(step, sbuf));
+    print_grid(fp_err, fp_log, buf, "timed with", set, cycles);
 
     if (set->count <= 2)
     {
@@ -466,15 +468,15 @@ gmx_bool pme_load_balance(pme_load_balancing_t pme_lb,
 
             if (debug)
             {
-                fprintf(debug,"The performance for grid %d %d %d went from %.3f to %.1f M-cycles, this is more than %f\n"
+                fprintf(debug, "The performance for grid %d %d %d went from %.3f to %.1f M-cycles, this is more than %f\n"
                         "Increased the number stages to %d"
                         " and ignoring the previous performance\n",
-                        set->grid[XX],set->grid[YY],set->grid[ZZ],
-                        cycles*1e-6,set->cycles*1e-6,PME_LB_ACCEL_TOL,
+                        set->grid[XX], set->grid[YY], set->grid[ZZ],
+                        cycles*1e-6, set->cycles*1e-6, PME_LB_ACCEL_TOL,
                         pme_lb->nstage);
             }
         }
-        set->cycles = min(set->cycles,cycles);
+        set->cycles = min(set->cycles, cycles);
     }
 
     if (set->cycles < pme_lb->setup[pme_lb->fastest].cycles)
@@ -527,13 +529,13 @@ gmx_bool pme_load_balance(pme_load_balancing_t pme_lb,
             else
             {
                 /* Find the next setup */
-                OK = pme_loadbal_increase_cutoff(pme_lb,ir->pme_order);
+                OK = pme_loadbal_increase_cutoff(pme_lb, ir->pme_order);
             }
 
             if (OK && ir->ePBC != epbcNONE)
             {
                 OK = (sqr(pme_lb->setup[pme_lb->cur+1].rlistlong)
-                      <= max_cutoff2(ir->ePBC,state->box));
+                      <= max_cutoff2(ir->ePBC, state->box));
                 if (!OK)
                 {
                     pme_lb->elimited = epmelblimBOX;
@@ -546,7 +548,7 @@ gmx_bool pme_load_balance(pme_load_balancing_t pme_lb,
 
                 if (DOMAINDECOMP(cr))
                 {
-                    OK = change_dd_cutoff(cr,state,ir,
+                    OK = change_dd_cutoff(cr, state, ir,
                                           pme_lb->setup[pme_lb->cur].rlistlong);
                     if (!OK)
                     {
@@ -562,7 +564,7 @@ gmx_bool pme_load_balance(pme_load_balancing_t pme_lb,
                  * the setup should not go further than cur.
                  */
                 pme_lb->n = pme_lb->cur + 1;
-                print_loadbal_limited(fp_err,fp_log,step,pme_lb);
+                print_loadbal_limited(fp_err, fp_log, step, pme_lb);
                 /* Switch to the next stage */
                 switch_to_stage1(pme_lb);
             }
@@ -579,7 +581,7 @@ gmx_bool pme_load_balance(pme_load_balancing_t pme_lb,
 
     if (pme_lb->stage > 0 && pme_lb->end == 1)
     {
-        pme_lb->cur = 0;
+        pme_lb->cur   = 0;
         pme_lb->stage = pme_lb->nstage;
     }
     else if (pme_lb->stage > 0 && pme_lb->end > 1)
@@ -612,7 +614,7 @@ gmx_bool pme_load_balance(pme_load_balancing_t pme_lb,
 
     if (DOMAINDECOMP(cr) && pme_lb->stage > 0)
     {
-        OK = change_dd_cutoff(cr,state,ir,pme_lb->setup[pme_lb->cur].rlistlong);
+        OK = change_dd_cutoff(cr, state, ir, pme_lb->setup[pme_lb->cur].rlistlong);
         if (!OK)
         {
             /* Failsafe solution */
@@ -625,7 +627,7 @@ gmx_bool pme_load_balance(pme_load_balancing_t pme_lb,
             pme_lb->end      = pme_lb->cur;
             pme_lb->cur      = pme_lb->start;
             pme_lb->elimited = epmelblimDD;
-            print_loadbal_limited(fp_err,fp_log,step,pme_lb);
+            print_loadbal_limited(fp_err, fp_log, step, pme_lb);
         }
     }
 
@@ -643,17 +645,17 @@ gmx_bool pme_load_balance(pme_load_balancing_t pme_lb,
     if (pme_lb->cutoff_scheme == ecutsVERLET &&
         nbv->grp[0].kernel_type == nbnxnk8x8x8_CUDA)
     {
-        nbnxn_cuda_pme_loadbal_update_param(nbv->cu_nbv,ic);
+        nbnxn_cuda_pme_loadbal_update_param(nbv->cu_nbv, ic);
     }
     else
     {
-        init_interaction_const_tables(NULL,ic,bUsesSimpleTables,
+        init_interaction_const_tables(NULL, ic, bUsesSimpleTables,
                                       rtab);
     }
 
     if (pme_lb->cutoff_scheme == ecutsVERLET && nbv->ngrp > 1)
     {
-        init_interaction_const_tables(NULL,ic,bUsesSimpleTables,
+        init_interaction_const_tables(NULL, ic, bUsesSimpleTables,
                                       rtab);
     }
 
@@ -665,7 +667,7 @@ gmx_bool pme_load_balance(pme_load_balancing_t pme_lb,
              * copying part of the old pointers.
              */
             gmx_pme_reinit(&set->pmedata,
-                           cr,pme_lb->setup[0].pmedata,ir,
+                           cr, pme_lb->setup[0].pmedata, ir,
                            set->grid);
         }
         *pmedata = set->pmedata;
@@ -678,12 +680,12 @@ gmx_bool pme_load_balance(pme_load_balancing_t pme_lb,
 
     if (debug)
     {
-        print_grid(NULL,debug,"","switched to",set,-1);
+        print_grid(NULL, debug, "", "switched to", set, -1);
     }
 
     if (pme_lb->stage == pme_lb->nstage)
     {
-        print_grid(fp_err,fp_log,"","optimal",set,-1);
+        print_grid(fp_err, fp_log, "", "optimal", set, -1);
     }
 
     return TRUE;
@@ -699,59 +701,59 @@ static int pme_grid_points(const pme_setup_t *setup)
     return setup->grid[XX]*setup->grid[YY]*setup->grid[ZZ];
 }
 
-static void print_pme_loadbal_setting(FILE *fplog,
-                                     char *name,
-                                     const pme_setup_t *setup)
+static void print_pme_loadbal_setting(FILE              *fplog,
+                                      char              *name,
+                                      const pme_setup_t *setup)
 {
     fprintf(fplog,
             "   %-7s %6.3f nm %6.3f nm     %3d %3d %3d   %5.3f nm  %5.3f nm\n",
             name,
-            setup->rcut_coulomb,setup->rlist,
-            setup->grid[XX],setup->grid[YY],setup->grid[ZZ],
-            setup->spacing,1/setup->ewaldcoeff);
+            setup->rcut_coulomb, setup->rlist,
+            setup->grid[XX], setup->grid[YY], setup->grid[ZZ],
+            setup->spacing, 1/setup->ewaldcoeff);
 }
 
 static void print_pme_loadbal_settings(pme_load_balancing_t pme_lb,
-                                       FILE *fplog)
+                                       FILE                *fplog)
 {
-    double pp_ratio,grid_ratio;
+    double pp_ratio, grid_ratio;
 
-    pp_ratio   = pow(pme_lb->setup[pme_lb->cur].rlist/pme_lb->setup[0].rlistlong,3.0);
+    pp_ratio   = pow(pme_lb->setup[pme_lb->cur].rlist/pme_lb->setup[0].rlistlong, 3.0);
     grid_ratio = pme_grid_points(&pme_lb->setup[pme_lb->cur])/
         (double)pme_grid_points(&pme_lb->setup[0]);
 
-    fprintf(fplog,"\n");
-    fprintf(fplog,"       P P   -   P M E   L O A D   B A L A N C I N G\n");
-    fprintf(fplog,"\n");
+    fprintf(fplog, "\n");
+    fprintf(fplog, "       P P   -   P M E   L O A D   B A L A N C I N G\n");
+    fprintf(fplog, "\n");
     /* Here we only warn when the optimal setting is the last one */
     if (pme_lb->elimited != epmelblimNO &&
         pme_lb->cur == pme_loadbal_end(pme_lb)-1)
     {
-        fprintf(fplog," NOTE: The PP/PME load balancing was limited by the %s,\n",
+        fprintf(fplog, " NOTE: The PP/PME load balancing was limited by the %s,\n",
                 pmelblim_str[pme_lb->elimited]);
-        fprintf(fplog,"       you might not have reached a good load balance.\n");
+        fprintf(fplog, "       you might not have reached a good load balance.\n");
         if (pme_lb->elimited == epmelblimDD)
         {
-            fprintf(fplog,"       Try different mdrun -dd settings or lower the -dds value.\n");
+            fprintf(fplog, "       Try different mdrun -dd settings or lower the -dds value.\n");
         }
-        fprintf(fplog,"\n");
-    }
-    fprintf(fplog," PP/PME load balancing changed the cut-off and PME settings:\n");
-    fprintf(fplog,"           particle-particle                    PME\n");
-    fprintf(fplog,"            rcoulomb  rlist            grid      spacing   1/beta\n");
-    print_pme_loadbal_setting(fplog,"initial",&pme_lb->setup[0]);
-    print_pme_loadbal_setting(fplog,"final"  ,&pme_lb->setup[pme_lb->cur]);
-    fprintf(fplog," cost-ratio           %4.2f             %4.2f\n",
-            pp_ratio,grid_ratio);
-    fprintf(fplog," (note that these numbers concern only part of the total PP and PME load)\n");
-    fprintf(fplog,"\n");
+        fprintf(fplog, "\n");
+    }
+    fprintf(fplog, " PP/PME load balancing changed the cut-off and PME settings:\n");
+    fprintf(fplog, "           particle-particle                    PME\n");
+    fprintf(fplog, "            rcoulomb  rlist            grid      spacing   1/beta\n");
+    print_pme_loadbal_setting(fplog, "initial", &pme_lb->setup[0]);
+    print_pme_loadbal_setting(fplog, "final", &pme_lb->setup[pme_lb->cur]);
+    fprintf(fplog, " cost-ratio           %4.2f             %4.2f\n",
+            pp_ratio, grid_ratio);
+    fprintf(fplog, " (note that these numbers concern only part of the total PP and PME load)\n");
+    fprintf(fplog, "\n");
 }
 
 void pme_loadbal_done(pme_load_balancing_t pme_lb, FILE *fplog)
 {
     if (fplog != NULL && (pme_lb->cur > 0 || pme_lb->elimited != epmelblimNO))
     {
-        print_pme_loadbal_settings(pme_lb,fplog);
+        print_pme_loadbal_settings(pme_lb, fplog);
     }
 
     /* TODO: Here we should free all pointers in pme_lb,