switch ld_seed from int to gmx_int64_t
authorChristoph Junghans <junghans@votca.org>
Mon, 3 Feb 2014 20:52:32 +0000 (13:52 -0700)
committerGerrit Code Review <gerrit@gerrit.gromacs.org>
Sat, 1 Mar 2014 15:38:59 +0000 (16:38 +0100)
* allows more than 4,294,967,295 different seeds for ld
* tpx version bumped, used new style for magic version constants
* changed printf format strings to conform to new type

Change-Id: Id661ca331a100dc942ac978cc1b50cfdade09731

src/gromacs/fileio/tpxio.c
src/gromacs/gmxlib/txtdump.c
src/gromacs/gmxpreprocess/grompp.c
src/gromacs/gmxpreprocess/readir.c
src/gromacs/legacyheaders/types/inputrec.h
src/gromacs/tools/compare.c
src/gromacs/tools/convert_tpr.c

index 1f8c842acb12564f3f44059ec474199da46ff47d..95ce61b7a24bfb46183ed86efe01493d84c0a425 100644 (file)
@@ -76,8 +76,16 @@ static const char *tpx_tag = TPX_TAG_RELEASE;
  *
  * version  feature added
  *    96    support for ion/water position swaps (computational electrophysiology)
+ *    97    switch ld_seed from int to gmx_int64_t
+ *
+ * The following macros help the code be more self-documenting and
+ * ensure merges do not silently resolve when two patches make the
+ * same bump to the number. Unfortunately, compilers don't like
+ * initializing a const int with a const int, so we have to be a bit
+ * dirty and use a macro.
  */
-static const int tpx_version = 96;
+#define tpx_version_use_64_bit_random_seed 97
+static const int tpx_version = tpx_version_use_64_bit_random_seed;
 
 
 /* This number should only be increased when you edit the TOPOLOGY section
@@ -1408,7 +1416,15 @@ static void do_inputrec(t_fileio *fio, t_inputrec *ir, gmx_bool bRead,
         gmx_fio_do_real(fio, bd_temp);
     }
     gmx_fio_do_real(fio, ir->bd_fric);
-    gmx_fio_do_int(fio, ir->ld_seed);
+    if (file_version >= tpx_version_use_64_bit_random_seed)
+    {
+        gmx_fio_do_int64(fio, ir->ld_seed);
+    }
+    else
+    {
+        gmx_fio_do_int(fio, idum);
+        ir->ld_seed = idum;
+    }
     if (file_version >= 33)
     {
         for (i = 0; i < DIM; i++)
index d0b1ce6dc79bf912926cdac6b86dc1da77133aba..c3214304416f9b6db27c86898e39cd82cfa8425c 100644 (file)
@@ -1024,7 +1024,7 @@ void pr_inputrec(FILE *fp, int indent, const char *title, t_inputrec *ir,
         PR("lincs-warnangle", ir->LincsWarnAngle);
         PI("lincs-iter", ir->nLincsIter);
         PR("bd-fric", ir->bd_fric);
-        PI("ld-seed", ir->ld_seed);
+        PSTEP("ld-seed", ir->ld_seed);
         PR("cos-accel", ir->cos_accel);
         pr_matrix(fp, indent, "deform", ir->deform, bMDPformat);
 
index 5c20e5d4c84b082af2829b8af6756b697db3de3f..49529521e263205c29cf3d32495d8b2ba306c62b 100644 (file)
@@ -1550,8 +1550,8 @@ int gmx_grompp(int argc, char *argv[])
 
     if (ir->ld_seed == -1)
     {
-        ir->ld_seed = (int)gmx_rng_make_seed();
-        fprintf(stderr, "Setting the LD random seed to %d\n", ir->ld_seed);
+        ir->ld_seed = (gmx_int64_t)gmx_rng_make_seed();
+        fprintf(stderr, "Setting the LD random seed to %"GMX_PRId64 "\n", ir->ld_seed);
     }
 
     if (ir->expandedvals->lmc_seed == -1)
index 472c517b0450f79b540ba86ccfd4f0092e8261d6..db3595984e1621bba7a007ef5a1f3993c360e712 100644 (file)
@@ -1788,7 +1788,7 @@ void get_ir(const char *mdparin, const char *mdparout,
     CCTYPE ("LANGEVIN DYNAMICS OPTIONS");
     CTYPE ("Friction coefficient (amu/ps) and random seed");
     RTYPE ("bd-fric",     ir->bd_fric,    0.0);
-    ITYPE ("ld-seed",     ir->ld_seed,    -1);
+    STEPTYPE ("ld-seed",  ir->ld_seed,    -1);
 
     /* Em stuff */
     CCTYPE ("ENERGY MINIMIZATION OPTIONS");
index e2f2fcf682e4bd88ec95144a862d939cca6e1d20..3a9e42d643ad507403849c8061b34b06ca2e32a2 100644 (file)
@@ -429,7 +429,7 @@ typedef struct {
     int             nLincsIter;              /* Number of iterations in the final Lincs step */
     gmx_bool        bShakeSOR;               /* Use successive overrelaxation for shake      */
     real            bd_fric;                 /* Friction coefficient for BD (amu/ps)         */
-    int             ld_seed;                 /* Random seed for SD and BD                    */
+    gmx_int64_t     ld_seed;                 /* Random seed for SD and BD                    */
     int             nwall;                   /* The number of walls                          */
     int             wall_type;               /* The type of walls                            */
     real            wall_r_linpot;           /* The potentail is linear for r<=wall_r_linpot */
index 31e2cf84d7a35ee698915285c87e30fad86ec3a2..f5a231849e92a69d9c5499204fb348edcf1dcb80 100644 (file)
@@ -869,7 +869,7 @@ static void cmp_inputrec(FILE *fp, t_inputrec *ir1, t_inputrec *ir2, real ftol,
     cmp_real(fp, "inputrec->LincsWarnAngle", -1, ir1->LincsWarnAngle, ir2->LincsWarnAngle, ftol, abstol);
     cmp_int(fp, "inputrec->nLincsIter", -1, ir1->nLincsIter, ir2->nLincsIter);
     cmp_real(fp, "inputrec->bd_fric", -1, ir1->bd_fric, ir2->bd_fric, ftol, abstol);
-    cmp_int(fp, "inputrec->ld_seed", -1, ir1->ld_seed, ir2->ld_seed);
+    cmp_int64(fp, "inputrec->ld_seed", ir1->ld_seed, ir2->ld_seed);
     cmp_real(fp, "inputrec->cos_accel", -1, ir1->cos_accel, ir2->cos_accel, ftol, abstol);
     cmp_rvec(fp, "inputrec->deform(a)", -1, ir1->deform[XX], ir2->deform[XX], ftol, abstol);
     cmp_rvec(fp, "inputrec->deform(b)", -1, ir1->deform[YY], ir2->deform[YY], ftol, abstol);
index c3297ed7cccec0405fe69c36c87e0c5c6ef47bbd..9f9136799c7871758d641fcb868a75767db7a27a 100644 (file)
@@ -56,6 +56,7 @@
 #include "gromacs/fileio/trnio.h"
 #include "gromacs/fileio/enxio.h"
 #include "gromacs/fileio/futil.h"
+#include "gromacs/random/random.h"
 
 #define RANGECHK(i, n) if ((i) >= (n)) gmx_fatal(FARGS, "Your index file contains atomnumbers (e.g. %d)\nthat are larger than the number of atoms in the tpr file (%d)", (i), (n))
 
@@ -463,6 +464,13 @@ int gmx_convert_tpr(int argc, char *argv[])
                     "If you want that, supply a checkpoint file to mdrun\n\n");
         }
 
+        if (EI_SD(ir->eI) || ir->eI == eiBD)
+        {
+            fprintf(stderr, "\nChanging ld-seed from %"GMX_PRId64 " ", ir->ld_seed);
+            ir->ld_seed = (gmx_int64_t)gmx_rng_make_seed();
+            fprintf(stderr, "to %"GMX_PRId64 "\n\n", ir->ld_seed);
+        }
+
         frame_fn = ftp2fn(efTRN, NFILE, fnm);
 
         if (fn2ftp(frame_fn) == efCPT)