Random engines & distributions as proper C++11 classes
authorErik Lindahl <erik@kth.se>
Wed, 12 Aug 2015 16:02:42 +0000 (18:02 +0200)
committerGerrit Code Review <gerrit@gerrit.gromacs.org>
Wed, 9 Mar 2016 14:17:04 +0000 (15:17 +0100)
commit2d0247f6a60c810d883b0ed1ad42ef326e87dbf8
tree4fd5b8f933283c3b99c0a898194c86f83477bef6
parent61fe70a919ecbdf024d30199a435d8cc16d3c1b0
Random engines & distributions as proper C++11 classes

This change implements the ThreeFry2x64 random engine with flexible
number of encryption rounds and internal counter bits. The class is
compatible with the C++11 random number generators, and the GROMACS
tabulated normal distribution has likewise been turned into a
random distribution compatible with C++11, meaning they can be used in
almost any combination with the standard library distributions.
- The ThreeFry2x64 implementation uses John Salmon's idea of a template-
  selected internal counter so a number of bits are reserved to generate
  an arbitrary random stream. This makes it possible to use ThreeFry as
  a normal random engine, and even in counter mode it is possible to
  draw an arbitrary amount of random numbers before restarting counters.
- Both accurate (20-round) and fast (13-round) versions are available.
- There is a gmx::DefaultRandomEngine when we don't care about details.
- gmx::GammaDistribution has been added to work around bugs in
  libstdc++-4.4.7 headers, and to avoid getting different results
  for libstdc++ vs. libc++.
- Custom Uniform, normal, and exponential distributions have been added
  to make all results reproducible across platforms since stdlibc++ and
  libc++ do not use the same generating algorithms.
- Code using random numbers has been updated, but no changes have been
  made to turn random seeds into 64bits yet.
- The selection nbsearch unit test was a bit fragile and very sensitive
  to the coordinate specific values; this has been fixed so it should
  be resilient no matter what RNG is used in the future.

Change-Id: I47a04d03e2f264e1a6ef0aa0a2174cb464ed9af7
84 files changed:
COPYING
src/contrib/gmx_stats_test.c [deleted file]
src/external/Random123-1.08/LICENSE [deleted file]
src/external/Random123-1.08/README [deleted file]
src/external/Random123-1.08/include/Random123/array.h [deleted file]
src/external/Random123-1.08/include/Random123/threefry.h [deleted file]
src/gromacs/CMakeLists.txt
src/gromacs/gmxana/gmx_cluster.cpp
src/gromacs/gmxana/gmx_dipoles.cpp
src/gromacs/gmxana/gmx_genion.cpp
src/gromacs/gmxana/gmx_nmens.cpp
src/gromacs/gmxana/gmx_pme_error.cpp
src/gromacs/gmxana/gmx_wham.cpp
src/gromacs/gmxana/nsfactor.cpp
src/gromacs/gmxpreprocess/gen_maxwell_velocities.cpp
src/gromacs/gmxpreprocess/genconf.cpp
src/gromacs/gmxpreprocess/grompp.cpp
src/gromacs/gmxpreprocess/insert-molecules.cpp
src/gromacs/gmxpreprocess/tests/genconf.cpp
src/gromacs/gmxpreprocess/tests/insert-molecules.cpp
src/gromacs/gmxpreprocess/tests/refdata/GenconfTest_nbox_rot_Works.xml
src/gromacs/gmxpreprocess/tests/refdata/InsertMoleculesTest_InsertsMoleculesIntoEmptyBox.xml
src/gromacs/gmxpreprocess/tests/refdata/InsertMoleculesTest_InsertsMoleculesIntoEnlargedBox.xml
src/gromacs/gmxpreprocess/tests/refdata/InsertMoleculesTest_InsertsMoleculesIntoExistingConfiguration.xml
src/gromacs/gmxpreprocess/tests/refdata/InsertMoleculesTest_InsertsMoleculesIntoFixedPositions.xml
src/gromacs/math/utilities.h
src/gromacs/mdlib/coupling.cpp
src/gromacs/mdlib/expanded.cpp
src/gromacs/mdlib/tpi.cpp
src/gromacs/mdlib/update.cpp
src/gromacs/random.h [new file with mode: 0644]
src/gromacs/random/CMakeLists.txt
src/gromacs/random/exponentialdistribution.h [new file with mode: 0644]
src/gromacs/random/gammadistribution.h [new file with mode: 0644]
src/gromacs/random/normaldistribution.h [new file with mode: 0644]
src/gromacs/random/random.cpp [deleted file]
src/gromacs/random/random.h [deleted file]
src/gromacs/random/random_gausstable.h [deleted file]
src/gromacs/random/seed.cpp [moved from src/external/Random123-1.08/include/Random123/features/compilerfeatures.h with 61% similarity]
src/gromacs/random/seed.h [new file with mode: 0644]
src/gromacs/random/tabulatednormaldistribution.cpp [new file with mode: 0644]
src/gromacs/random/tabulatednormaldistribution.h [new file with mode: 0644]
src/gromacs/random/tests/CMakeLists.txt
src/gromacs/random/tests/exponentialdistribution.cpp [new file with mode: 0644]
src/gromacs/random/tests/gammadistribution.cpp [new file with mode: 0644]
src/gromacs/random/tests/normaldistribution.cpp [new file with mode: 0644]
src/gromacs/random/tests/refdata/ExponentialDistributionTest_Output.xml [new file with mode: 0644]
src/gromacs/random/tests/refdata/GammaDistributionTest_Output.xml [new file with mode: 0644]
src/gromacs/random/tests/refdata/KnownAnswersTest_ThreeFry2x64Test_Default_0.xml [moved from src/gromacs/random/tests/refdata/0_ff_pi_Threefry_2x64_0.xml with 88% similarity]
src/gromacs/random/tests/refdata/KnownAnswersTest_ThreeFry2x64Test_Default_1.xml [moved from src/gromacs/random/tests/refdata/0_ff_pi_Threefry_2x64_1.xml with 88% similarity]
src/gromacs/random/tests/refdata/KnownAnswersTest_ThreeFry2x64Test_Default_2.xml [moved from src/gromacs/random/tests/refdata/0_ff_pi_Threefry_2x64_2.xml with 88% similarity]
src/gromacs/random/tests/refdata/KnownAnswersTest_ThreeFry2x64Test_Fast_0.xml [new file with mode: 0644]
src/gromacs/random/tests/refdata/KnownAnswersTest_ThreeFry2x64Test_Fast_1.xml [new file with mode: 0644]
src/gromacs/random/tests/refdata/KnownAnswersTest_ThreeFry2x64Test_Fast_2.xml [new file with mode: 0644]
src/gromacs/random/tests/refdata/KnownAnswersTest_ThreeFry2x64Test_Using40Rounds_0.xml [new file with mode: 0644]
src/gromacs/random/tests/refdata/KnownAnswersTest_ThreeFry2x64Test_Using40Rounds_1.xml [new file with mode: 0644]
src/gromacs/random/tests/refdata/KnownAnswersTest_ThreeFry2x64Test_Using40Rounds_2.xml [new file with mode: 0644]
src/gromacs/random/tests/refdata/NormalDistributionTest_Output.xml [new file with mode: 0644]
src/gromacs/random/tests/refdata/TabulatedNormalDistributionTest_Output14.xml [new file with mode: 0644]
src/gromacs/random/tests/refdata/TabulatedNormalDistributionTest_Output16.xml [new file with mode: 0644]
src/gromacs/random/tests/refdata/TabulatedNormalDistributionTest_OutputDouble14.xml [new file with mode: 0644]
src/gromacs/random/tests/refdata/ThreeFry2x64Test_InternalCounterSequence.xml [new file with mode: 0644]
src/gromacs/random/tests/refdata/UniformIntDistributionTest_Output.xml [new file with mode: 0644]
src/gromacs/random/tests/refdata/UniformRealDistributionTest_GenerateCanonical.xml [new file with mode: 0644]
src/gromacs/random/tests/refdata/UniformRealDistributionTest_Output.xml [new file with mode: 0644]
src/gromacs/random/tests/seed.cpp [moved from src/gromacs/random/tests/random.cpp with 50% similarity]
src/gromacs/random/tests/tabulatednormaldistribution.cpp [new file with mode: 0644]
src/gromacs/random/tests/threefry.cpp [new file with mode: 0644]
src/gromacs/random/tests/uniformintdistribution.cpp [new file with mode: 0644]
src/gromacs/random/tests/uniformrealdistribution.cpp [new file with mode: 0644]
src/gromacs/random/threefry.h [new file with mode: 0644]
src/gromacs/random/uniformintdistribution.h [new file with mode: 0644]
src/gromacs/random/uniformrealdistribution.h [new file with mode: 0644]
src/gromacs/selection/tests/nbsearch.cpp
src/gromacs/tools/convert_tpr.cpp
src/gromacs/trajectoryanalysis/modules/freevolume.cpp
src/gromacs/trajectoryanalysis/tests/refdata/FreeVolumeModuleTest_ComputesFreeVolume.xml
src/gromacs/trajectoryanalysis/tests/refdata/FreeVolumeModuleTest_ComputesFreeVolumeSelection.xml
src/gromacs/trajectoryanalysis/tests/refdata/SurfaceAreaTest_Computes100Points.xml
src/gromacs/trajectoryanalysis/tests/refdata/SurfaceAreaTest_Computes100PointsWithRectangularPBC.xml
src/gromacs/trajectoryanalysis/tests/refdata/SurfaceAreaTest_Computes100PointsWithTriclinicPBC.xml
src/gromacs/trajectoryanalysis/tests/surfacearea.cpp
src/gromacs/utility/basedefinitions.h
src/programs/mdrun/repl_ex.cpp