Moved random number generator code to separate dir.
[alexxy/gromacs.git] / src / programs / mdrun / repl_ex.c
index 786c55cae28becbb01e7bbbeeef7e4901a77a0bf..9f5ac5ff2cb996b0d5a6f656ed2e50dfe1e6e416 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) 2011,2012,2013, by the GROMACS development team, led by
+ * Copyright (c) 2011,2012,2013,2014, 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.
@@ -41,7 +41,7 @@
 #include <math.h>
 #include "repl_ex.h"
 #include "network.h"
-#include "random.h"
+#include "gromacs/random/random.h"
 #include "smalloc.h"
 #include "physics.h"
 #include "copyrite.h"
@@ -66,22 +66,23 @@ const char *erename[ereNR] = { "temperature", "lambda", "end_single_marker", "te
 
 typedef struct gmx_repl_ex
 {
-    int      repl;
-    int      nrepl;
-    real     temp;
-    int      type;
-    real   **q;
-    gmx_bool bNPT;
-    real    *pres;
-    int     *ind;
-    int     *allswaps;
-    int      nst;
-    int      nex;
-    int      seed;
-    int      nattempt[2];
-    real    *prob_sum;
-    int    **nmoves;
-    int     *nexchange;
+    int       repl;
+    int       nrepl;
+    real      temp;
+    int       type;
+    real    **q;
+    gmx_bool  bNPT;
+    real     *pres;
+    int      *ind;
+    int      *allswaps;
+    int       nst;
+    int       nex;
+    int       seed;
+    int       nattempt[2];
+    real     *prob_sum;
+    int     **nmoves;
+    int      *nexchange;
+    gmx_rng_t rng;
 
     /* these are helper arrays for replica exchange; allocated here so they
        don't have to be allocated each time */
@@ -340,7 +341,7 @@ gmx_repl_ex_t init_replica_exchange(FILE *fplog,
     {
         if (MASTERSIM(ms))
         {
-            re->seed = make_seed();
+            re->seed = (int)gmx_rng_make_seed();
         }
         else
         {
@@ -354,6 +355,7 @@ gmx_repl_ex_t init_replica_exchange(FILE *fplog,
     }
     fprintf(fplog, "\nReplica exchange interval: %d\n", re->nst);
     fprintf(fplog, "\nReplica random seed: %d\n", re->seed);
+    re->rng = gmx_rng_init(re->seed);
 
     re->nattempt[0] = 0;
     re->nattempt[1] = 0;
@@ -901,6 +903,7 @@ test_for_replica_exchange(FILE                 *fplog,
     gmx_bool  bEpot    = FALSE;
     gmx_bool  bDLambda = FALSE;
     gmx_bool  bVol     = FALSE;
+    gmx_rng_t rng;
 
     bMultiEx = (re->nex > 1);  /* multiple exchanges at each state */
     fprintf(fplog, "Replica exchange at step " "%"GMX_PRId64 " time %g\n", step, time);
@@ -987,8 +990,8 @@ test_for_replica_exchange(FILE                 *fplog,
                probability of occurring (log p > -100) and only operate on those switches */
             /* find out which state it is from, and what label that state currently has. Likely
                more work that useful. */
-            i0 = (int)(re->nrepl*rando(&(re->seed)));
-            i1 = (int)(re->nrepl*rando(&(re->seed)));
+            i0 = (int)(re->nrepl*gmx_rng_uniform_real(re->rng));
+            i1 = (int)(re->nrepl*gmx_rng_uniform_real(re->rng));
             if (i0 == i1)
             {
                 i--;
@@ -1027,7 +1030,7 @@ test_for_replica_exchange(FILE                 *fplog,
                     prob[0] = exp(-delta);
                 }
                 /* roll a number to determine if accepted */
-                bEx[0] = (rando(&(re->seed)) < prob[0]);
+                bEx[0] = (gmx_rng_uniform_real(re->rng) < prob[0]);
             }
             re->prob_sum[0] += prob[0];
 
@@ -1072,7 +1075,7 @@ test_for_replica_exchange(FILE                 *fplog,
                         prob[i] = exp(-delta);
                     }
                     /* roll a number to determine if accepted */
-                    bEx[i] = (rando(&(re->seed)) < prob[i]);
+                    bEx[i] = (gmx_rng_uniform_real(re->rng) < prob[i]);
                 }
                 re->prob_sum[i] += prob[i];