From: Rossen Apostolov Date: Tue, 9 Sep 2014 12:38:33 +0000 (+0200) Subject: Converted random module to C++. X-Git-Url: http://biod.pnpi.spb.ru/gitweb/?a=commitdiff_plain;h=3fd6c81197df860d973e760b93b110ddfd7ac08b;p=alexxy%2Fgromacs.git Converted random module to C++. Removed ununsed variables. Changed gmx_rng_cycle_* functions to use uint64 instead of int64. Fixed uninitialized return variable. Change-Id: I41ba38f21a0560da1080c8f51bcb36c311783c89 --- diff --git a/src/gromacs/random/CMakeLists.txt b/src/gromacs/random/CMakeLists.txt index e819cc2ab1..dc82c7a459 100644 --- a/src/gromacs/random/CMakeLists.txt +++ b/src/gromacs/random/CMakeLists.txt @@ -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) diff --git a/src/gromacs/random/random.c b/src/gromacs/random/random.cpp similarity index 94% rename from src/gromacs/random/random.c rename to src/gromacs/random/random.cpp index 1e8390abe2..8c442895f6 100644 --- a/src/gromacs/random/random.c +++ b/src/gromacs/random/random.cpp @@ -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}}; diff --git a/src/gromacs/random/random.h b/src/gromacs/random/random.h index a4eb24ebb4..5cbacebd51 100644 --- a/src/gromacs/random/random.h +++ b/src/gromacs/random/random.h @@ -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