Fix scope and naming of some variables
authorMark Abraham <mark.j.abraham@gmail.com>
Fri, 29 Nov 2013 13:11:51 +0000 (14:11 +0100)
committerGerrit Code Review <gerrit@gerrit.gromacs.org>
Sun, 1 Dec 2013 19:09:24 +0000 (20:09 +0100)
Not sure why ASAN did not complain that the old code sometimes used
dvdl when uninitialized under RF.

Updated copyright header

Change-Id: Ib534dc4aa8128f58a80689d5f33282fb16967b1e

src/gromacs/mdlib/force.c

index 897a4b5036c24feeeb3bcd6d780654b79013ac00..109c8087147ce70411d2e3f645ef703206dca86c 100644 (file)
@@ -1,37 +1,38 @@
-/* -*- mode: c; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; c-file-style: "stroustrup"; -*-
+/*
+ * This file is part of the GROMACS molecular simulation package.
  *
- *
- *                This source code is part of
- *
- *                 G   R   O   M   A   C   S
- *
- *          GROningen MAchine for Chemical Simulations
- *
- *                        VERSION 3.2.0
- * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
- * Copyright (c) 2001-2004, The GROMACS development team,
- * check out http://www.gromacs.org for more information.
-
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
+ * Copyright (c) 2001-2004, The GROMACS development team.
+ * Copyright (c) 2013, 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.
+ *
+ * GROMACS is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1
  * 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.
+ * GROMACS is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
  *
- * 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.
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GROMACS; if not, see
+ * http://www.gnu.org/licenses, or write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
  *
- * For more info, check our website at http://www.gromacs.org
+ * If you want to redistribute modifications to GROMACS, 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 http://www.gromacs.org.
  *
- * And Hey:
- * GROwing Monsters And Cloning Shrimps
+ * To help us fund GROMACS development, we humbly ask that you cite
+ * the research papers on the package. Check out http://www.gromacs.org.
  */
 #ifdef HAVE_CONFIG_H
 #include <config.h>
@@ -162,19 +163,16 @@ void do_force_lowlevel(FILE       *fplog,   gmx_large_int_t step,
                        int        flags,
                        float      *cycles_pme)
 {
-    int         i, j, status;
+    int         i, j;
     int         donb_flags;
     gmx_bool    bDoEpot, bSepDVDL, bSB;
     int         pme_flags;
     matrix      boxs;
     rvec        box_size;
-    real        Vsr, Vlr, Vcorr = 0;
     t_pbc       pbc;
-    real        dvdgb;
     char        buf[22];
     double      clam_i, vlam_i;
-    real        dvdl_dum[efptNR], dvdl, dvdl_nb[efptNR], lam_i[efptNR];
-    real        dvdlsum;
+    real        dvdl_dum[efptNR], dvdl_nb[efptNR], lam_i[efptNR];
 
 #ifdef GMX_MPI
     double  t0 = 0.0, t1, t2, t3; /* time measurement for coarse load balancing */
@@ -227,10 +225,10 @@ void do_force_lowlevel(FILE       *fplog,   gmx_large_int_t step,
     if (ir->nwall)
     {
         /* foreign lambda component for walls */
-        dvdl = do_walls(ir, fr, box, md, x, f, lambda[efptVDW],
-                        enerd->grpp.ener[egLJSR], nrnb);
-        PRINT_SEPDVDL("Walls", 0.0, dvdl);
-        enerd->dvdl_lin[efptVDW] += dvdl;
+        real dvdl_walls = do_walls(ir, fr, box, md, x, f, lambda[efptVDW],
+                                   enerd->grpp.ener[egLJSR], nrnb);
+        PRINT_SEPDVDL("Walls", 0.0, dvdl_walls);
+        enerd->dvdl_lin[efptVDW] += dvdl_walls;
     }
 
     /* If doing GB, reset dvda and calculate the Born radii */
@@ -342,19 +340,23 @@ void do_force_lowlevel(FILE       *fplog,   gmx_large_int_t step,
         enerd->dvdl_lin[efptCOUL] += dvdl_nb[efptCOUL];
     }
 
-    Vsr = 0;
     if (bSepDVDL)
     {
+        real V_short_range = 0;
+        real dvdl_short_range;
+
         for (i = 0; i < enerd->grpp.nener; i++)
         {
-            Vsr +=
+            V_short_range +=
                 (fr->bBHAM ?
                  enerd->grpp.ener[egBHAMSR][i] :
                  enerd->grpp.ener[egLJSR][i])
                 + enerd->grpp.ener[egCOULSR][i] + enerd->grpp.ener[egGB][i];
         }
-        dvdlsum = dvdl_nb[efptVDW] + dvdl_nb[efptCOUL];
-        PRINT_SEPDVDL("VdW and Coulomb SR particle-p.", Vsr, dvdlsum);
+        dvdl_short_range = dvdl_nb[efptVDW] + dvdl_nb[efptCOUL];
+        PRINT_SEPDVDL("VdW and Coulomb SR particle-p.",
+                      V_short_range,
+                      dvdl_short_range);
     }
     debug_gmx();
 
@@ -438,6 +440,10 @@ void do_force_lowlevel(FILE       *fplog,   gmx_large_int_t step,
     *cycles_pme = 0;
     if (EEL_FULL(fr->eeltype))
     {
+        real Vlr             = 0, Vcorr = 0;
+        real dvdl_long_range = 0;
+        int  status          = 0;
+
         bSB = (ir->nwall == 2);
         if (bSB)
         {
@@ -450,8 +456,7 @@ void do_force_lowlevel(FILE       *fplog,   gmx_large_int_t step,
 
         if (fr->bEwald)
         {
-            Vcorr = 0;
-            dvdl  = 0;
+            real dvdl_long_range_correction = 0;
 
             /* With the Verlet scheme exclusion forces are calculated
              * in the non-bonded kernel.
@@ -486,7 +491,7 @@ void do_force_lowlevel(FILE       *fplog,   gmx_large_int_t step,
                         fnv    = fr->f_novirsum;
                         vir    = &fr->vir_el_recip;
                         Vcorrt = &Vcorr;
-                        dvdlt  = &dvdl;
+                        dvdlt  = &dvdl_long_range_correction;
                     }
                     else
                     {
@@ -517,7 +522,7 @@ void do_force_lowlevel(FILE       *fplog,   gmx_large_int_t step,
                 {
                     reduce_thread_forces(fr->natoms_force, fr->f_novirsum,
                                          fr->vir_el_recip,
-                                         &Vcorr, efptCOUL, &dvdl,
+                                         &Vcorr, efptCOUL, &dvdl_long_range_correction,
                                          nthreads, fr->f_t);
                 }
 
@@ -527,16 +532,15 @@ void do_force_lowlevel(FILE       *fplog,   gmx_large_int_t step,
             if (fr->n_tpi == 0)
             {
                 Vcorr += ewald_charge_correction(cr, fr, lambda[efptCOUL], box,
-                                                 &dvdl, fr->vir_el_recip);
+                                                 &dvdl_long_range_correction,
+                                                 fr->vir_el_recip);
             }
 
-            PRINT_SEPDVDL("Ewald excl./charge/dip. corr.", Vcorr, dvdl);
-            enerd->dvdl_lin[efptCOUL] += dvdl;
+            PRINT_SEPDVDL("Ewald excl./charge/dip. corr.", Vcorr,
+                          dvdl_long_range_correction);
+            enerd->dvdl_lin[efptCOUL] += dvdl_long_range_correction;
         }
 
-        status = 0;
-        Vlr    = 0;
-        dvdl   = 0;
         switch (fr->eeltype)
         {
             case eelPME:
@@ -573,7 +577,7 @@ void do_force_lowlevel(FILE       *fplog,   gmx_large_int_t step,
                                             DOMAINDECOMP(cr) ? dd_pme_maxshift_y(cr->dd) : 0,
                                             nrnb, wcycle,
                                             fr->vir_el_recip, fr->ewaldcoeff,
-                                            &Vlr, lambda[efptCOUL], &dvdl,
+                                            &Vlr, lambda[efptCOUL], &dvdl_long_range,
                                             pme_flags);
                         *cycles_pme = wallcycle_stop(wcycle, ewcPMEMESH);
 
@@ -595,7 +599,7 @@ void do_force_lowlevel(FILE       *fplog,   gmx_large_int_t step,
                                             md->chargeA + md->homenr - fr->n_tpi,
                                             &Vlr);
                     }
-                    PRINT_SEPDVDL("PME mesh", Vlr, dvdl);
+                    PRINT_SEPDVDL("PME mesh", Vlr, dvdl_long_range);
                 }
                 break;
             case eelEWALD:
@@ -603,8 +607,8 @@ void do_force_lowlevel(FILE       *fplog,   gmx_large_int_t step,
                                md->chargeA, md->chargeB,
                                box_size, cr, md->homenr,
                                fr->vir_el_recip, fr->ewaldcoeff,
-                               lambda[efptCOUL], &dvdl, fr->ewald_table);
-                PRINT_SEPDVDL("Ewald long-range", Vlr, dvdl);
+                               lambda[efptCOUL], &dvdl_long_range, fr->ewald_table);
+                PRINT_SEPDVDL("Ewald long-range", Vlr, dvdl_long_range);
                 break;
             default:
                 gmx_fatal(FARGS, "No such electrostatics method implemented %s",
@@ -616,7 +620,7 @@ void do_force_lowlevel(FILE       *fplog,   gmx_large_int_t step,
                       status, EELTYPE(fr->eeltype));
         }
         /* Note that with separate PME nodes we get the real energies later */
-        enerd->dvdl_lin[efptCOUL] += dvdl;
+        enerd->dvdl_lin[efptCOUL] += dvdl_long_range;
         enerd->term[F_COUL_RECIP]  = Vlr + Vcorr;
         if (debug)
         {
@@ -628,22 +632,23 @@ void do_force_lowlevel(FILE       *fplog,   gmx_large_int_t step,
     }
     else
     {
-        if (EEL_RF(fr->eeltype))
+        /* Is there a reaction-field exclusion correction needed? */
+        if (EEL_RF(fr->eeltype) && eelRF_NEC != fr->eeltype)
         {
-            /* With the Verlet scheme exclusion forces are calculated
+            /* With the Verlet scheme, exclusion forces are calculated
              * in the non-bonded kernel.
              */
-            if (ir->cutoff_scheme != ecutsVERLET && fr->eeltype != eelRF_NEC)
+            if (ir->cutoff_scheme != ecutsVERLET)
             {
-                dvdl                   = 0;
+                real dvdl_rf_excl      = 0;
                 enerd->term[F_RF_EXCL] =
                     RF_excl_correction(fr, graph, md, excl, x, f,
-                                       fr->fshift, &pbc, lambda[efptCOUL], &dvdl);
-            }
+                                       fr->fshift, &pbc, lambda[efptCOUL], &dvdl_rf_excl);
 
-            enerd->dvdl_lin[efptCOUL] += dvdl;
-            PRINT_SEPDVDL("RF exclusion correction",
-                          enerd->term[F_RF_EXCL], dvdl);
+                enerd->dvdl_lin[efptCOUL] += dvdl_rf_excl;
+                PRINT_SEPDVDL("RF exclusion correction",
+                              enerd->term[F_RF_EXCL], dvdl_rf_excl);
+            }
         }
     }
     where();