Use proper doxygen tags in modular simulator
[gromacs.git] / src / gromacs / random.h
blob13da87ca0c546ea997831f687b894c0b11a89937
1 /*
2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2015,2016, by the GROMACS development team, led by
5 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 * and including many others, as listed in the AUTHORS file in the
7 * top-level source directory and at http://www.gromacs.org.
9 * GROMACS is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; either version 2.1
12 * of the License, or (at your option) any later version.
14 * GROMACS is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with GROMACS; if not, see
21 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * If you want to redistribute modifications to GROMACS, please
25 * consider that scientific software is very special. Version
26 * control is crucial - bugs must be traceable. We will be happy to
27 * consider code for inclusion in the official distribution, but
28 * derived work must not be called official GROMACS. Details are found
29 * in the README & COPYING files - if they are missing, get the
30 * official version at http://www.gromacs.org.
32 * To help us fund GROMACS development, we humbly ask that you cite
33 * the research papers on the package. Check out http://www.gromacs.org.
35 /*! \defgroup module_random Random engines and distributions (random)
36 * \ingroup group_utilitymodules
37 * \brief
38 * Provides efficient and portable random generators and distributions
40 * <H3>Basic Use</H3>
42 * \Gromacs relies on random numbers in several different modules, and in
43 * particular for methods that influence the integration we both require the
44 * generation to be very fast and the resulting numbers of high quality.
45 * In addition, it is highly desirable that we generate the same trajectories
46 * in parallel as for a single-core run.
48 * To realize this, we have implemented the ThreeFry2x64 counter-based random
49 * engine. In contrast to a normal random engine that is seeded and then keeps
50 * an internal state, ThreeFry2x64 is derived from cryptographic applications
51 * where we use a key to turn a highly regular counter int a stream of random
52 * numbers. This makes it possible to quickly set the counter in the random
53 * engine based e.g. on the timestep and atom index, and get the same random
54 * numbers regardless of parallelization.
56 * The TreeFry2x64 engine has been implemented to be fully compatible with
57 * standard C++11 random engines. There is a gmx::ThreeFry2x64General class that
58 * allows full control over the accuracy (more iterations means higher quality),
59 * and gmx::ThreeFry2x64 and gmx::ThreeFry2x64Fast that are specialized to 20
60 * and 13 iterations, respectively. With 20 iterations this engine passes all
61 * tests in the standard BigCrush test, and with 13 iterations only a single
62 * test fails (in comparision, Mersenne Twister fails two).
64 * All these engines take a template parameter that specifies the number of
65 * bits to reserve for an internal counter. This is based on an idea of
66 * John Salmon, and it makes it possible to set your external counter based
67 * on two simple values (usually timestep and particle index), but then it is
68 * still possible to draw more than one value for this external counter since
69 * the internal counter increments. If you run out of internal counter space
70 * the class will throw an exception to make sure you don't silently end up
71 * with corrupted/overlapping random data.
73 * <H3>But what if I just want a vanilla random number generator?</H3>
75 * We've thought about that. Just use the gmx::DefaultRandomEngine class and
76 * forget everything about counters. Initialize the class with a single value
77 * for the seed (up to 64 bits), and you are good to go.
79 * <H3>Random number distributions</H3>
81 * The ThreeFry random engine is fully compatible with all distributions from
82 * the C++11 standard library, but unfortunately implementation differences
83 * (and bugs) mean you will typically not get the same sequence of numbers from
84 * two different library implementations. Since this causes problems for our
85 * unit tests, we prefer to use our own implementations - they should work
86 * exactly like the corresponding C++11 versions.
88 * The normal distribution is frequently used in integration, and it can be
89 * a performance bottleneck. To avoid this, we use a special tabulated
90 * distribution gmx::TabulatedNormalDistribution that provides very high
91 * performance at the cost of slightly discretized values; the default 14-bit
92 * table gives us 16,384 unique values, but this has been thoroughly tested to
93 * be sufficient for all integration usage.
95 * \author Erik Lindahl <erik.lindahl@gmail.com>
97 /*! \file
98 * \brief
99 * Public API convenience header for random engines and distributions.
101 * \author Erik Lindahl <erik.lindahl@gmail.com>
102 * \inpublicapi
103 * \ingroup module_random
105 #ifndef GMX_RANDOM_H
106 #define GMX_RANDOM_H
108 #include "gromacs/random/exponentialdistribution.h"
109 #include "gromacs/random/gammadistribution.h"
110 #include "gromacs/random/normaldistribution.h"
111 #include "gromacs/random/seed.h"
112 #include "gromacs/random/threefry.h"
113 #include "gromacs/random/uniformintdistribution.h"
114 #include "gromacs/random/uniformrealdistribution.h"
116 #endif