Merge release-5-0 into master
authorMark Abraham <mark.j.abraham@gmail.com>
Fri, 26 Jun 2015 12:53:15 +0000 (14:53 +0200)
committerMark Abraham <mark.j.abraham@gmail.com>
Sat, 27 Jun 2015 06:49:20 +0000 (08:49 +0200)
Conflicts:
src/gromacs/mdlib/calc_verletbuf.c
Included nbnxn_simd.h, consistent with fix incoming from release-5-0.

src/programs/mdrun/runner.cpp
One of the changes in release-5-0 was in the -testverlet feature,
which has been removed in master. Other changes applied normally.

Change-Id: Id5b507bce1d6f907e97ac694f02fbe7e486f6208

src/gromacs/fileio/strdb.c
src/gromacs/fileio/trajectory_writing.c
src/gromacs/gmxana/gmx_energy.c
src/gromacs/gmxlib/checkpoint.cpp
src/gromacs/gmxpreprocess/grompp.c
src/gromacs/mdlib/calc_verletbuf.c
src/gromacs/mdlib/calc_verletbuf.h
src/gromacs/utility/cstringutil.c
src/gromacs/utility/cstringutil.h
src/programs/mdrun/md.cpp
src/programs/mdrun/runner.cpp

index 7d6ff971f8f0b88bc3ae6c359a0ffe271b1a87da..a0fc276d8fee579723e6856ce011ffc02fefc86d 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) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, 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.
@@ -121,7 +121,7 @@ int get_strings(const char *db, char ***strings)
 {
     FILE  *in;
     char **ptr;
-    char   buf[256];
+    char   buf[STRLEN];
     int    i, nstr;
 
     in = libopen(db);
@@ -135,7 +135,7 @@ int get_strings(const char *db, char ***strings)
     snew(ptr, nstr);
     for (i = 0; (i < nstr); i++)
     {
-        if (1 != fscanf(in, "%s", buf))
+        if (NULL == fgets2(buf, STRLEN, in))
         {
             gmx_fatal(FARGS, "Cannot read string from buffer");
         }
@@ -174,7 +174,7 @@ int fget_lines(FILE *in, char ***strings)
     int    i, nstr;
     char  *pret;
 
-    pret = fgets(buf, STRLEN-1, in);
+    pret = fgets(buf, STRLEN, in);
     if (pret == NULL  || sscanf(buf, "%d", &nstr) != 1)
     {
         gmx_warning("File is empty");
@@ -185,7 +185,7 @@ int fget_lines(FILE *in, char ***strings)
     snew(ptr, nstr);
     for (i = 0; (i < nstr); i++)
     {
-        fgets2(buf, STRLEN-1, in);
+        fgets2(buf, STRLEN, in);
         ptr[i] = gmx_strdup(buf);
     }
 
index 6689cdd410b08057440ab7f226e2804179a80b93..169d412d77283c3591f9c2c72bd35a49e29a6dfc 100644 (file)
@@ -73,6 +73,7 @@ do_md_trajectory_writing(FILE           *fplog,
                          )
 {
     int   mdof_flags;
+    rvec *x_for_confout = NULL;
 
     mdof_flags = 0;
     if (do_per_step(step, ir->nstxout))
@@ -149,6 +150,25 @@ do_md_trajectory_writing(FILE           *fplog,
             bDoConfOut && MASTER(cr) &&
             !bRerunMD)
         {
+            if (fr->bMolPBC && state->x == state_global->x)
+            {
+                /* This (single-rank) run needs to allocate a
+                   temporary array of size natoms so that any
+                   periodicity removal for mdrun -confout does not
+                   perturb the update and thus the final .edr
+                   output. This makes .cpt restarts look binary
+                   identical, and makes .edr restarts binary
+                   identical. */
+                snew(x_for_confout, state_global->natoms);
+                copy_rvecn(state_global->x, x_for_confout, 0, state_global->natoms);
+            }
+            else
+            {
+                /* With DD, or no bMolPBC, it doesn't matter if
+                   we change state_global->x */
+                x_for_confout = state_global->x;
+            }
+
             /* x and v have been collected in mdoutf_write_to_trajectory_files,
              * because a checkpoint file will always be written
              * at the last step.
@@ -157,12 +177,16 @@ do_md_trajectory_writing(FILE           *fplog,
             if (fr->bMolPBC)
             {
                 /* Make molecules whole only for confout writing */
-                do_pbc_mtop(fplog, ir->ePBC, state->box, top_global, state_global->x);
+                do_pbc_mtop(fplog, ir->ePBC, state->box, top_global, x_for_confout);
             }
             write_sto_conf_mtop(ftp2fn(efSTO, nfile, fnm),
                                 *top_global->name, top_global,
-                                state_global->x, state_global->v,
+                                x_for_confout, state_global->v,
                                 ir->ePBC, state->box);
+            if (fr->bMolPBC && state->x == state_global->x)
+            {
+                sfree(x_for_confout);
+            }
             debug_gmx();
         }
         wallcycle_stop(mdoutf_get_wcycle(outf), ewcTRAJ);
index 3b3c86cd42d40d94fd2c8ea157d09d3344ce8a19..d2595be547c6a100667c660b0c29255d488ef3be 100644 (file)
@@ -86,6 +86,7 @@ typedef struct {
     int             *steps;
     int             *points;
     enerdat_t       *s;
+    gmx_bool         bHaveSums;
 } enerdata_t;
 
 static double mypow(double x, double y)
@@ -702,7 +703,7 @@ static void calc_averages(int nset, enerdata_t *edat, int nbmin, int nbmax)
     {
         ed             = &edat->s[i];
         ed->bExactStat = FALSE;
-        if (edat->npoints > 0)
+        if (edat->bHaveSums)
         {
             /* All energy file sum entries 0 signals no exact sums.
              * But if all energy values are 0, we still have exact sums.
@@ -1171,7 +1172,7 @@ static void analyse_ener(gmx_bool bCorr, const char *corrfn,
             esum = calc_sum(nset, edat, nbmin, nbmax);
         }
 
-        if (edat->npoints == 0)
+        if (!edat->bHaveSums)
         {
             nexact    = 0;
             nnotexact = nset;
@@ -2330,12 +2331,13 @@ int gmx_energy(int argc, char *argv[])
     }
 
     /* Initiate energies and set them to zero */
-    edat.nsteps  = 0;
-    edat.npoints = 0;
-    edat.nframes = 0;
-    edat.step    = NULL;
-    edat.steps   = NULL;
-    edat.points  = NULL;
+    edat.nsteps    = 0;
+    edat.npoints   = 0;
+    edat.nframes   = 0;
+    edat.step      = NULL;
+    edat.steps     = NULL;
+    edat.points    = NULL;
+    edat.bHaveSums = TRUE;
     snew(edat.s, nset);
 
     /* Initiate counters */
@@ -2413,41 +2415,43 @@ int gmx_energy(int argc, char *argv[])
                 else
                 {
                     edat.steps[nfr] = fr->nsteps;
+
+                    if (fr->nsum <= 1)
                     {
-                        if (fr->step - start_step + 1 == edat.nsteps + fr->nsteps)
+                        /* mdrun only calculated the energy at energy output
+                         * steps. We don't need to check step intervals.
+                         */
+                        edat.points[nfr] = 1;
+                        for (i = 0; i < nset; i++)
                         {
-                            if (fr->nsum <= 1)
-                            {
-                                edat.points[nfr] = 1;
-                                for (i = 0; i < nset; i++)
-                                {
-                                    sss                    = set[i];
-                                    edat.s[i].es[nfr].sum  = fr->ener[sss].e;
-                                    edat.s[i].es[nfr].sum2 = 0;
-                                }
-                                edat.npoints += 1;
-                            }
-                            else
-                            {
-                                edat.points[nfr] = fr->nsum;
-                                for (i = 0; i < nset; i++)
-                                {
-                                    sss                    = set[i];
-                                    edat.s[i].es[nfr].sum  = fr->ener[sss].esum;
-                                    edat.s[i].es[nfr].sum2 = fr->ener[sss].eav;
-                                }
-                                edat.npoints += fr->nsum;
-                            }
+                            sss                    = set[i];
+                            edat.s[i].es[nfr].sum  = fr->ener[sss].e;
+                            edat.s[i].es[nfr].sum2 = 0;
                         }
-                        else
+                        edat.npoints  += 1;
+                        edat.bHaveSums = FALSE;
+                    }
+                    else if (fr->step - start_step + 1 == edat.nsteps + fr->nsteps)
+                    {
+                        /* We have statistics  to the previous frame */
+                        edat.points[nfr] = fr->nsum;
+                        for (i = 0; i < nset; i++)
                         {
-                            /* The interval does not match fr->nsteps:
-                             * can not do exact averages.
-                             */
-                            edat.npoints = 0;
+                            sss                    = set[i];
+                            edat.s[i].es[nfr].sum  = fr->ener[sss].esum;
+                            edat.s[i].es[nfr].sum2 = fr->ener[sss].eav;
                         }
-                        edat.nsteps = fr->step - start_step + 1;
+                        edat.npoints += fr->nsum;
                     }
+                    else
+                    {
+                        /* The interval does not match fr->nsteps:
+                         * can not do exact averages.
+                         */
+                        edat.bHaveSums = FALSE;
+                    }
+
+                    edat.nsteps = fr->step - start_step + 1;
                 }
                 for (i = 0; i < nset; i++)
                 {
index 98897daaa66dabef938ac0a7ea9bd1540db568ce..607f94974a2caa82ae7c2e59b4b7e990cda42c75 100644 (file)
@@ -1529,16 +1529,15 @@ void write_checkpoint(const char *fn, gmx_bool bNumberAndKeep,
     flags_enh = 0;
     if (state->enerhist.nsum > 0 || state->enerhist.nsum_sim > 0)
     {
-        flags_enh |= (1<<eenhENERGY_N);
+        flags_enh |= (1<<eenhENERGY_N) | (1<<eenhENERGY_NSTEPS) | (1<<eenhENERGY_NSTEPS_SIM);
         if (state->enerhist.nsum > 0)
         {
             flags_enh |= ((1<<eenhENERGY_AVER) | (1<<eenhENERGY_SUM) |
-                          (1<<eenhENERGY_NSTEPS) | (1<<eenhENERGY_NSUM));
+                          (1<<eenhENERGY_NSUM));
         }
         if (state->enerhist.nsum_sim > 0)
         {
-            flags_enh |= ((1<<eenhENERGY_SUM_SIM) | (1<<eenhENERGY_NSTEPS_SIM) |
-                          (1<<eenhENERGY_NSUM_SIM));
+            flags_enh |= ((1<<eenhENERGY_SUM_SIM) | (1<<eenhENERGY_NSUM_SIM));
         }
         if (state->enerhist.dht)
         {
index 2c9ed586d79f77b70621aadcd9faf55990d2932f..77bb8515f94b3122cdc720da099644b0b9060bf1 100644 (file)
@@ -1386,7 +1386,7 @@ static void set_verlet_buffer(const gmx_mtop_t *mtop,
                             &ls, &n_nonlin_vsite, &rlist_1x1);
 
     /* Set the pair-list buffer size in ir */
-    verletbuf_get_list_setup(FALSE, &ls);
+    verletbuf_get_list_setup(FALSE, FALSE, &ls);
     calc_verlet_buffer_size(mtop, det(box), ir, buffer_temp,
                             &ls, &n_nonlin_vsite, &ir->rlist);
 
@@ -1404,6 +1404,8 @@ static void set_verlet_buffer(const gmx_mtop_t *mtop,
            ls.cluster_size_i, ls.cluster_size_j,
            ir->rlist, ir->rlist-max(ir->rvdw, ir->rcoulomb));
 
+    printf("Note that mdrun will redetermine rlist based on the actual pair-list setup\n");
+
     if (sqr(ir->rlistlong) >= max_cutoff2(ir->ePBC, box))
     {
         gmx_fatal(FARGS, "The pair-list cut-off (%g nm) is longer than half the shortest box vector or longer than the smallest box diagonal element (%g nm). Increase the box size or decrease nstlist or increase verlet-buffer-tolerance.", ir->rlistlong, sqrt(max_cutoff2(ir->ePBC, box)));
index d516c795b94d724a79cc3204b1aa39568cdaa8f7..774a0b138e7ee15a9dbca359123f6c0cb74e31fd 100644 (file)
@@ -48,6 +48,7 @@
 #include "gromacs/math/units.h"
 #include "gromacs/math/vec.h"
 #include "gromacs/mdlib/nbnxn_consts.h"
+#include "gromacs/mdlib/nbnxn_simd.h"
 #include "gromacs/utility/fatalerror.h"
 #include "gromacs/utility/smalloc.h"
 
@@ -118,25 +119,28 @@ typedef struct
     int                           n;    /* #atoms of this type in the system */
 } verletbuf_atomtype_t;
 
-void verletbuf_get_list_setup(gmx_bool                bGPU,
+void verletbuf_get_list_setup(gmx_bool gmx_unused     bSIMD,
+                              gmx_bool                bGPU,
                               verletbuf_list_setup_t *list_setup)
 {
-    list_setup->cluster_size_i     = NBNXN_CPU_CLUSTER_I_SIZE;
-
     if (bGPU)
     {
-        list_setup->cluster_size_j = NBNXN_GPU_CLUSTER_SIZE;
+        list_setup->cluster_size_i     = NBNXN_GPU_CLUSTER_SIZE;
+        list_setup->cluster_size_j     = NBNXN_GPU_CLUSTER_SIZE;
     }
     else
     {
-#ifndef GMX_NBNXN_SIMD
-        list_setup->cluster_size_j = NBNXN_CPU_CLUSTER_I_SIZE;
-#else
-        list_setup->cluster_size_j = GMX_SIMD_REAL_WIDTH;
+        list_setup->cluster_size_i     = NBNXN_CPU_CLUSTER_I_SIZE;
+        list_setup->cluster_size_j     = NBNXN_CPU_CLUSTER_I_SIZE;
+#ifdef GMX_NBNXN_SIMD
+        if (bSIMD)
+        {
+            list_setup->cluster_size_j = GMX_SIMD_REAL_WIDTH;
 #ifdef GMX_NBNXN_SIMD_2XNN
-        /* We assume the smallest cluster size to be on the safe side */
-        list_setup->cluster_size_j /= 2;
+            /* We assume the smallest cluster size to be on the safe side */
+            list_setup->cluster_size_j /= 2;
 #endif
+        }
 #endif
     }
 }
index edce6db14353426511cd4cde5168f14c376fbb15..3013293d42a9128911533f1d29e5ec1aa0ec62ac 100644 (file)
@@ -63,8 +63,11 @@ static const real verlet_buffer_ratio_NVE_T0     = 0.10;
 /* Sets the pair-list setup assumed for the current Gromacs configuration.
  * The setup with smallest cluster sizes is return, such that the Verlet
  * buffer size estimated with this setup will be conservative.
+ * bSIMD tells if to take into account SIMD, when supported.
+ * bGPU tells to estimate for GPU kernels (bSIMD is ignored with bGPU=TRUE)
  */
-void verletbuf_get_list_setup(gmx_bool                bGPU,
+void verletbuf_get_list_setup(gmx_bool                bSIMD,
+                              gmx_bool                bGPU,
                               verletbuf_list_setup_t *list_setup);
 
 
index 438a232b9c39b248b35e46d918ee6c8afec09fc7..bb0c250776f07540bef543c0404b5b973b1e1aeb 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) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, 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.
index 20605d0728d3f40cf06d20256f79961a03c5b966..fabe7788246016d7b5def483380800882c3ca9cf 100644 (file)
@@ -71,9 +71,9 @@ int continuing(char *s);
 /*! \brief
  * Reads a line from a stream.
  *
- * This routine reads a string from stream of max length n
- * and zero terminated, without newlines.
- * \p s should be long enough (>= \p n)
+ * This routine reads a string from stream of max length n, including
+ * \0 and zero terminated, without newlines.  \p s should be long
+ * enough (>= \p n)
  */
 char *fgets2(char *s, int n, FILE *stream);
 
index a839ee8adbbce5c2e0513c7ba12243d98d6eab6c..060595cb18d47b04fc14bbf244de7385e8b4343d 100644 (file)
@@ -526,9 +526,14 @@ double do_md(FILE *fplog, t_commrec *cr, int nfile, const t_filenm fnm[],
         nstfep = gmx_greatest_common_divisor(repl_ex_nst, nstfep);
     }
 
-    /* I'm assuming we need global communication the first time! MRS */
+    /* Be REALLY careful about what flags you set here. You CANNOT assume
+     * this is the first step, since we might be restarting from a checkpoint,
+     * and in that case we should not do any modifications to the state.
+     */
+    bStopCM = (ir->comm_mode != ecmNO && !ir->bContinuation);
+
     cglo_flags = (CGLO_TEMPERATURE | CGLO_GSTAT
-                  | ((ir->comm_mode != ecmNO) ? CGLO_STOPCM : 0)
+                  | (bStopCM ? CGLO_STOPCM : 0)
                   | (bVV ? CGLO_PRESSURE : 0)
                   | (bVV ? CGLO_CONSTRAINT : 0)
                   | (bRerunMD ? CGLO_RERUNMD : 0)
index ff1ac26cc708c10be23825887f86c63ee972c27a..500a74d4d44e59737559384a2e5b25e300da714f 100644 (file)
@@ -398,7 +398,7 @@ static void increase_nstlist(FILE *fp, t_commrec *cr,
         ir->nstlist = nstlist_cmdline;
     }
 
-    verletbuf_get_list_setup(bGPU, &ls);
+    verletbuf_get_list_setup(TRUE, bGPU, &ls);
 
     /* Allow rlist to make the list a given factor larger than the list
      * would be with the reference value for nstlist (10).
@@ -523,7 +523,7 @@ static void prepare_verlet_scheme(FILE                           *fplog,
          * calc_verlet_buffer_size gives the same results for 4x8 and 4x4
          * and 4x2 gives a larger buffer than 4x4, this is ok.
          */
-        verletbuf_get_list_setup(bUseGPU, &ls);
+        verletbuf_get_list_setup(TRUE, bUseGPU, &ls);
 
         calc_verlet_buffer_size(mtop, det(box), ir, -1, &ls, NULL, &rlist_new);