The ParallelRngManager
class simplifies the task of initializing and coordinating random number generation for multiple threads in OpenMP and other multi-threaded programming environments without the need for locks or the possibility of false sharing. A single integer value is used to seed a single random number generator that is partitioned into independent parallel random number generator streams.
Using a single random number generator seed makes deterministic testing and debugging of parallel stochastic algorithms practical. Additionally it is important to use a random number generator specifically designed for parallel use, as it is not in general safe to use independent random seeds for each processor if strong randomness properties and guaranteed a-correlation of the streams are arithmetically important considerations.
More generally, a parallel random number generator (PRNG) provides a set of N random number generator streams for multi-threaded applications, where each stream is produced from a single underlying random number generator with a single global seed. For certain classes of random number generators, a single stream can efficiently be partitioned into N threads without communication overhead. The parallel_rng::ParallelRngManager
class functions as an OpenMP-aware manager for the PRNGs from the Tina's Random Number Generator (TRNG) Library.
-
ParallelRngManager
is CMake based, and providesParallelRngManagerConfig.cmake
files allowingfind_pacakge(ParallelRngManager)
to find the package in either the build or install trees. -
ParallelRngManager
can automatically configure and install TRNG and alongside itself if it does not exist on the system. -
ParallelRngManager
is designed to work seamlessly with OpenMP. It automatically manages the number of RNG streams based on hardware concurrency and prevents false sharing. -
A ParallelRngManager object manages a single stream and uses OpenMP
get_num_threads()
to allocate the correct number of sub-streams, which are kept on separate cache lines usingaligned_array::AArray<RngT>
.
The ParallelRngManager Doxygen documentation can be build with the OPT_DOC
CMake option and is also available on online:
The easiest method is to use the default build script, which can be easily customized. The default build directory is ./_build
and the default install directory is ./_install
.
$ git clone https://github.com/markjolah/ParallelRngManager.git
$ cd ParallelRngManager
$ ./build.sh
If TRNG is not available on the system, it is important to have CMAKE_INSTALL_PREFIX
set to a valid install directory, even if it is just a local directory, as the autotools build is designed to install into the CMAKE_INSTALL_PREFIX
and ParallelRngManager is then expecting to find the TRNG library there.
The following CMake options control the build.
BUILD_SHARED_LIBS
- Build shared librariesBUILD_STATIC_LIBS
- Build static librariesBUILD_TESTING
- Build testing frameworkOPT_DOC
- Build documentationOPT_INSTALL_TESTING
- Install testing executables in install-tree.OPT_EXPORT_BUILD_TREE
- Configure the package so it is usable from the build tree. Useful for development.OPT_BLAS_INT64
- Use 64-bit integers for Armadillo, BLAS, and LAPACK.
ParallelRngManager is designed to be portable, but relies on several system development and numerical libraries. Currently Travis CI uses the trusty image to test ParallelRngManager Standard system dependencies
- >=g++-4.9 - A
--std=c++11
compliant GCC compiler - >=CMake-3.9
- OpenMP
- Armadillo - A high-performance array library for C++.
- googletest - Required for testing (
BUILD_TESTING=On
) - Doxygen - Required to generate documentation (
OPT_DOC=On
)- graphviz - Required to generate documentation (
make doc
) - LAPACK - Required for generate pdf documenation (
make pdf
)
- graphviz - Required to generate documentation (
The ParallelRngManager is a lightweight wrapper around the Tina's Random Number Generator (TRNG) library. This rather specialized numerical library is normally not available on most Linux distributions, so for convenience the ParallelRngManager CMake build system will automatically download, configure, build, and install TRNG (libtrng4.so
) into the CMAKE_INSTALL_PREFIX
path if it is not already present on the build system. This process uses the AddExternalAutotoolsDependency.cmake
function from the UncommonCMakeModules dependency.
- TRNG Manual
- H. Bauke and S. Mertens. Random Numbers for Large Scale Distributed Monte Carlo Simulations.
ParallelRngManager uses these reusable header-only component libraries via git subrepo
- AlignedArray - Provides
aligned_array::AArray<T>
which is an STL conforming fixed-length array container which guarantees no two elements share a cache line, preventing false sharing in multi-threaded or OpenMP programs. ParallelRngManager stores RNG streams in anAArray<RngT>
array to prevent false sharing. - AnyRng - Provides
any_rng::AnyRng<result_type>
which is a type-erased STL random number generator type. - UncommonCMakeModules - Provides
FindTRNG.cmake
FindArmadillo.cmake
and other useful CMake functions likeExportPackageWizzard.cmake
. ParallelRngManager only uses a small portion of these CMake modules but using agit subrepo
pulls in the entire repository.
ParallelRngManager uses googletest for C++ unit testing and integrates with CTest. To build tests, enable the BUILD_TESTING
CMake option and possibly also the OPT_INSTALL_TESTING
option to install tests along with ParallelRngManager.
Tests can be run with:
> make test