Converted random module to C++.
authorRossen Apostolov <rossen@kth.se>
Tue, 9 Sep 2014 12:38:33 +0000 (14:38 +0200)
committerGerrit Code Review <gerrit@gerrit.gromacs.org>
Tue, 2 Jun 2015 11:50:35 +0000 (13:50 +0200)
Removed ununsed variables. Changed gmx_rng_cycle_* functions
to use uint64 instead of int64. Fixed uninitialized return variable.

Change-Id: I41ba38f21a0560da1080c8f51bcb36c311783c89

src/gromacs/random/CMakeLists.txt
src/gromacs/random/random.cpp [moved from src/gromacs/random/random.c with 94% similarity]
src/gromacs/random/random.h

index e819cc2ab11cbfd3244dabbdfd61b0d21d1f8300..dc82c7a4590695942ea7801985129827912c02b8 100644 (file)
@@ -1,7 +1,7 @@
 #
 # This file is part of the GROMACS molecular simulation package.
 #
-# Copyright (c) 2014, by the GROMACS development team, led by
+# Copyright (c) 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.
@@ -32,7 +32,7 @@
 # To help us fund GROMACS development, we humbly ask that you cite
 # the research papers on the package. Check out http://www.gromacs.org.
 
-file(GLOB RANDOM_SOURCES *.c)
+file(GLOB RANDOM_SOURCES *.cpp)
 set(LIBGROMACS_SOURCES ${LIBGROMACS_SOURCES} ${RANDOM_SOURCES} PARENT_SCOPE)
 if (BUILD_TESTING)
     add_subdirectory(tests)
similarity index 94%
rename from src/gromacs/random/random.c
rename to src/gromacs/random/random.cpp
index 1e8390abe24ffcb323a0c2c261709d1afec06e03..8c442895f69cb65ad709b68b504ef2f16b9af8b2 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2008, The GROMACS development team.
- * Copyright (c) 2012,2014, by the GROMACS development team, led by
+ * Copyright (c) 2012,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.
@@ -200,10 +200,10 @@ gmx_rng_set_state(gmx_rng_t rng,  unsigned int *mt, int mti)
 unsigned int
 gmx_rng_make_seed(void)
 {
-    FILE        *fp;
-    unsigned int data;
-    int          ret;
-    long         my_pid;
+    FILE              *fp;
+    unsigned int       data;
+    int                ret;
+    long               my_pid;
 
 #ifdef HAVE_UNISTD_H
     /* We never want Gromacs execution to halt 10-20 seconds while
@@ -226,6 +226,7 @@ gmx_rng_make_seed(void)
     if (fp != NULL)
     {
         ret = fread(&data, sizeof(unsigned int), 1, fp);
+        GMX_IGNORE_RETURN_VALUE(ret);
         fclose(fp);
     }
     else
@@ -245,14 +246,13 @@ gmx_rng_make_seed(void)
 static void
 gmx_rng_update(gmx_rng_t rng)
 {
-    unsigned int       lastx, x1, x2, y, *mt;
-    int                mti, k;
+    unsigned int       x1, x2, y, *mt;
+    int                k;
     const unsigned int mag01[2] = {0x0UL, RNG_MATRIX_A};
     /* mag01[x] = x * MATRIX_A  for x=0,1 */
 
     /* update random numbers */
     mt  = rng->mt;  /* pointer to array - avoid repeated dereferencing */
-    mti = rng->mti;
 
     x1        = mt[0];
     for (k = 0; k < RNG_N-RNG_M-3; k += 4)
@@ -393,8 +393,8 @@ gmx_rng_gaussian_table(gmx_rng_t rng)
 }
 
 void
-gmx_rng_cycle_2uniform(gmx_int64_t ctr1, gmx_int64_t ctr2,
-                       gmx_int64_t key1, gmx_int64_t key2,
+gmx_rng_cycle_2uniform(gmx_uint64_t ctr1, gmx_uint64_t ctr2,
+                       gmx_uint64_t key1, gmx_uint64_t key2,
                        double* rnd)
 {
     const gmx_int64_t  mask_53bits     = 0x1FFFFFFFFFFFFF;
@@ -409,8 +409,8 @@ gmx_rng_cycle_2uniform(gmx_int64_t ctr1, gmx_int64_t ctr2,
 }
 
 void
-gmx_rng_cycle_3gaussian_table(gmx_int64_t ctr1, gmx_int64_t ctr2,
-                              gmx_int64_t key1, gmx_int64_t key2,
+gmx_rng_cycle_3gaussian_table(gmx_uint64_t ctr1, gmx_uint64_t ctr2,
+                              gmx_uint64_t key1, gmx_uint64_t key2,
                               real* rnd)
 {
     threefry2x64_ctr_t ctr  = {{ctr1, ctr2}};
@@ -423,8 +423,8 @@ gmx_rng_cycle_3gaussian_table(gmx_int64_t ctr1, gmx_int64_t ctr2,
 }
 
 void
-gmx_rng_cycle_6gaussian_table(gmx_int64_t ctr1, gmx_int64_t ctr2,
-                              gmx_int64_t key1, gmx_int64_t key2,
+gmx_rng_cycle_6gaussian_table(gmx_uint64_t ctr1, gmx_uint64_t ctr2,
+                              gmx_uint64_t key1, gmx_uint64_t key2,
                               real* rnd)
 {
     threefry2x64_ctr_t ctr  = {{ctr1, ctr2}};
index a4eb24ebb4c47bb21748bd67e89ddaae6a8c53f4..5cbacebd51d3edae6a2f4d2c8675a3c5c51cb942 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2008, The GROMACS development team.
- * Copyright (c) 2010,2014, by the GROMACS development team, led by
+ * Copyright (c) 2010,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.
@@ -295,8 +295,8 @@ gmx_rng_gaussian_table(gmx_rng_t rng);
  * (threefry2x64).
  */
 void
-gmx_rng_cycle_2uniform(gmx_int64_t ctr1, gmx_int64_t ctr2,
-                       gmx_int64_t key1, gmx_int64_t key2,
+gmx_rng_cycle_2uniform(gmx_uint64_t ctr1, gmx_uint64_t ctr2,
+                       gmx_uint64_t key1, gmx_uint64_t key2,
                        double* rnd);
 
 /* Return three Gaussian random numbers with expectation value
@@ -308,14 +308,14 @@ gmx_rng_cycle_2uniform(gmx_int64_t ctr1, gmx_int64_t ctr2,
  * threadsafe: yes
  */
 void
-gmx_rng_cycle_3gaussian_table(gmx_int64_t ctr1, gmx_int64_t ctr2,
-                              gmx_int64_t key1, gmx_int64_t key2,
+gmx_rng_cycle_3gaussian_table(gmx_uint64_t ctr1, gmx_uint64_t ctr2,
+                              gmx_uint64_t key1, gmx_uint64_t key2,
                               real* rnd);
 
 /* As gmx_rng_3gaussian_table, but returns 6 Gaussian numbers. */
 void
-gmx_rng_cycle_6gaussian_table(gmx_int64_t ctr1, gmx_int64_t ctr2,
-                              gmx_int64_t key1, gmx_int64_t key2,
+gmx_rng_cycle_6gaussian_table(gmx_uint64_t ctr1, gmx_uint64_t ctr2,
+                              gmx_uint64_t key1, gmx_uint64_t key2,
                               real* rnd);
 
 #ifdef __cplusplus