Provided within are two high quality and fast PPRNGs that may be used in an 'OpenMP' parallel environment. In addition, there is a generator for one dimensional low-discrepancy sequence. The objective of this library to consolidate the distribution of the 'sitmo' (C++98 & C++11), 'threefry' and 'vandercorput' (C++11-only) engines on CRAN by enabling others to link to the header files inside of 'sitmo' instead of including a copy of each engine within their individual package. Lastly, the package contains example implementations using the 'sitmo' package and three accompanying vignette that provide additional information.
The repository houses the sitmo R package for Parallel Psuedo Random
Number Generation (PPRNG). The package provides a way to obtain the
SITMO Consulting’s PPRNG header files via LinkTo.
sitmositmo is available on both CRAN (Stable) and GitHub (Development).
Using CRAN to download and install sitmo is the preferred option as it
is significantly more stable vs. the GitHub version.
To install the package from CRAN, you can simply type:
install.packages("sitmo")
The package will be installed and available in a similar fashion to
other R packages. The main exception to this note is that to use sitmo
to create a package you will need to acquire a compiler. This is
detailed under the development install instructions.
To install the package, you must first have a compiler on your system that is compatible with R.
For help on obtaining a compiler consult:
With a compiler in hand, one can then install the package from GitHub by:
install.packages("devtools")devtools::install_github("coatless/sitmo")
sitmoThere are two ways to use sitmo. The first is to use sitmo in a
standalone script. The script is typically built using sourceCpp().
The second approach allows for sitmo to be used within an R package.
Within the C++ file, the sitmo package provides an Rcpp plugins’
depends statement that must be included after sitmo.h header. This
plugin statement indicates that a dependency is sitmo.
// [[Rcpp::depends(sitmo)]]
To use the two other engines, threefry and vandercorput, they must
be loaded like:
// or use #include <vandercorput.h>// [[Rcpp::depends(sitmo)]]// [[Rcpp::plugins(cpp11)]]
sitmo Engine ExampleBelow is a hello world example meant to show a basic implementation of
sitmo.
// C++11 RNG library// SITMO PPRNG// Rcpp depends attribute is required for standalone use.// It is not needed if in package linking to the sitmo package (detailed next).// [[Rcpp::depends(sitmo)]]// [[Rcpp::export]]Rcpp::NumericVector/*** Rsitmo_draws_ex(5)*/
threefry Engine ExampleBelow is a hello world example meant to show a basic implementation of
threefry. This engine requires C++11.
// Rcpp depends attribute is required for standalone use.// It is not needed if in package linking to the sitmo package (detailed next).// [[Rcpp::depends(sitmo)]]// threefry requires access to a C++11 compatible compiler// [[Rcpp::plugins(cpp11)]]// [[Rcpp::export]]void
vandercorput Engine ExampleBelow is a hello world example meant to show a basic implementation of
vandercorput. This engine requires C++11.
// Rcpp depends attribute is required for standalone use.// It is not needed if in package linking to the sitmo package (detailed next).// [[Rcpp::depends(sitmo)]]// vandercorput requires access to a C++11 compatible compiler// [[Rcpp::plugins(cpp11)]]// [[Rcpp::export]]void
To use sitmo in your R package, modify the DESCRIPTION file by
adding:
LinkingTo: Rcpp, sitmo
Imports:
Rcpp (>= 0.12.11)
To use C++11’s statistical distributions, you may want to add the
following to your src/Makevars and src/Makevars.win file:
CXX_STD = CXX11
Within a C++ file in src/, then add:
// SITMO for C++98 & C++11 PPRNG// THREEFRY C++11-only PPRNG// VANDERCORPUT C++11-only Low-discrepancy sequence
You do not need to add each header file. Pick and choose the appropriate engine for your needs.
vandercorput.h by adding a newline to the end of the file.Makevars{.win} to use $(SHLIB_OPENMP_CXXFLAGS) instead of $(SHLIB_OPENMP_CFLAGS) in PKG_CXXFLAGS.travis.yml to compile using both cores instead of only one.threefry and vandercorput (#9, #10).threefry to be fully C++11 compliant. (#11, @rstub)Rcpp.plugin.maker()Rcpp.plugin.maker() by using the exported variable name,
e.g. ::, in place of the internal variable name, e.g. ::: (#7).sitmo URL to point to stdfin/random (#8).sitmo_two_seeds() src and documentation in "Deployment of sitmo within C++ Code"
so that it uses the second seed for eng2 and returns an n x 2 matrix instead of n x 3. (#5, thanks @helske)Rcpp:::Rcpp.plugin.maker() (#3)CxxFlags() and sitmoCxxFlags() functions to display CXX_FLAGS
required by sitmo. (#3)sitmo" vignette.sitmo" vignette.src/init.c to address R 3.4 C++ registration requirement (#2)sitmo" vignette.sitmo within C++ Code" vignette.sitmo header file in an R package.sitmo header file.sitmo contents:
sitmo within C++ Codesitmositmo's BigCrush Results