All Projects → miraisolutions → rTRNG

miraisolutions / rTRNG

Licence: GPL-3.0 license
R package providing access and examples to TRNG C++ library

Programming Languages

C++
36643 projects - #6 most used programming language
r
7636 projects
shell
77523 projects

Projects that are alternatives of or similar to rTRNG

parallel
PARALLEL: Stata module for parallel computing
Stars: ✭ 97 (+470.59%)
Mutual labels:  hpc, parallel
Raftlib
The RaftLib C++ library, streaming/dataflow concurrency via C++ iostream-like operators
Stars: ✭ 717 (+4117.65%)
Mutual labels:  hpc, parallel
cruise
User space POSIX-like file system in main memory
Stars: ✭ 27 (+58.82%)
Mutual labels:  hpc, parallel
future.batchtools
🚀 R package future.batchtools: A Future API for Parallel and Distributed Processing using batchtools
Stars: ✭ 77 (+352.94%)
Mutual labels:  hpc, parallel
Singularity
Singularity: Application containers for Linux
Stars: ✭ 2,290 (+13370.59%)
Mutual labels:  hpc, parallel
ParallelUtilities.jl
Fast and easy parallel mapreduce on HPC clusters
Stars: ✭ 28 (+64.71%)
Mutual labels:  hpc, parallel
Easylambda
distributed dataflows with functional list operations for data processing with C++14
Stars: ✭ 475 (+2694.12%)
Mutual labels:  hpc, parallel
pennylane-lightning
The PennyLane-Lightning plugin provides a fast state-vector simulator written in C++ for use with PennyLane
Stars: ✭ 28 (+64.71%)
Mutual labels:  hpc, parallel
Hpcinfo
Information about many aspects of high-performance computing. Wiki content moved to ~/docs.
Stars: ✭ 171 (+905.88%)
Mutual labels:  hpc, parallel
Future.apply
🚀 R package: future.apply - Apply Function to Elements in Parallel using Futures
Stars: ✭ 159 (+835.29%)
Mutual labels:  hpc, parallel
Core
parallel finite element unstructured meshes
Stars: ✭ 124 (+629.41%)
Mutual labels:  hpc, parallel
ParMmg
Distributed parallelization of 3D volume mesh adaptation
Stars: ✭ 19 (+11.76%)
Mutual labels:  hpc, parallel
hp2p
Heavy Peer To Peer: a MPI based benchmark for network diagnostic
Stars: ✭ 17 (+0%)
Mutual labels:  hpc, parallel
t8code
Parallel algorithms and data structures for tree-based AMR with arbitrary element shapes.
Stars: ✭ 37 (+117.65%)
Mutual labels:  hpc, parallel
hpc
Learning and practice of high performance computing (CUDA, Vulkan, OpenCL, OpenMP, TBB, SSE/AVX, NEON, MPI, coroutines, etc. )
Stars: ✭ 39 (+129.41%)
Mutual labels:  hpc
CARE
CHAI and RAJA provide an excellent base on which to build portable codes. CARE expands that functionality, adding new features such as loop fusion capability and a portable interface for many numerical algorithms. It provides all the basics for anyone wanting to write portable code.
Stars: ✭ 22 (+29.41%)
Mutual labels:  hpc
PTTmineR
Parallel Searching and Crawling Data from PTT 🚀
Stars: ✭ 31 (+82.35%)
Mutual labels:  parallel
YACLib
Yet Another Concurrency Library
Stars: ✭ 193 (+1035.29%)
Mutual labels:  parallel
video features
Extract video features from raw videos using multiple GPUs. We support RAFT and PWC flow frames as well as S3D, I3D, R(2+1)D, VGGish, CLIP, ResNet features.
Stars: ✭ 225 (+1223.53%)
Mutual labels:  parallel
noroutine
Goroutine analogue for Node.js, spreads I/O-bound routine calls to utilize thread pool (worker_threads) using balancer with event loop utilization. 🌱
Stars: ✭ 86 (+405.88%)
Mutual labels:  parallel

rTRNG: R package providing access and examples to TRNG C++ library

CRAN status R-CMD-check valgrind Codecov coverage

TRNG (Tina’s Random Number Generator) is a state-of-the-art C++ pseudo-random number generator library for sequential and parallel Monte Carlo simulations. It provides a variety of random number engines (pseudo-random number generators) and distributions. In particular, parallel random number engines provided by TRNG can be manipulated by jump and split operations. These allow to jump ahead by an arbitrary number of steps and to split a sequence into any desired sub-sequence(s), thus enabling techniques such as block-splitting and leapfrogging suitable to parallel algorithms.

Package rTRNG provides the R user with access to the functionality of the underlying TRNG C++ library, both in R directly or more typically as part of other projects combining R with C++.

An introduction to rTRNG [pdf] was given at the useR!2017 conference, and is also available as package vignette:

vignette("rTRNG.useR2017", "rTRNG")

The sub-matrix simulation vignette shows rTRNG in action for a flexible and consistent (parallel) simulation of a matrix of Monte Carlo variates:

vignette("mcMat", "rTRNG")

A full applied example of using rTRNG for the simulation of credit defaults was presented at the R/Finance 2017 conference. The underlying code and data are hosted on GitHub, as is the corresponding R Markdown output.

For more information and references, you can consult the package documentation page via help("rTRNG-package").

Installation

You can install the package from CRAN:

install.packages("rTRNG")

The development version of rTRNG can be installed from our GitHub repository with:

# install.packages("remotes")
remotes::install_github("miraisolutions/rTRNG")
# in order to also build the vignettes, you'll have to run below instead
remotes::install_github("miraisolutions/rTRNG", build_vignettes = TRUE)

Build note

If you try to build the package yourself from source and run Rcpp::compileAttributes() during the process, you need to use a version of Rcpp >= 0.12.11.2. Earlier versions like 0.12.11 will not generate the desired _rcpp_module_boot_trng symbol in RcppExports.cpp.

Examples

Use TRNG engines from R

Similar to base-R (?Random), rTRNG allows to select and manipulate a current TRNG engine of a given kind (e.g. yarn2), and to draw from it using any of the provided r<dist>_trng functions:

library(rTRNG)
TRNGkind("yarn2") 
TRNGseed(12358)
runif_trng(15)
#>  [1] 0.58025981 0.33943403 0.22139368 0.36940239 0.54267877
#>  [6] 0.00285146 0.12399649 0.34681378 0.12179942 0.94712445
#> [11] 0.33651657 0.12892618 0.38037989 0.55069238 0.43600265

The special jump and split operations can be applied to the current engine in a similar way:

TRNGseed(12358)
TRNGjump(6) # advance by 6 the internal state
TRNGsplit(5, 3) # subsequence: one element every 5 starting from the 3rd
runif_trng(2)
#> [1] 0.121799 0.550692
#   => compare to the full sequence above

TRNG engines can also be created and manipulated directly as Reference Class objects, and passed as engine argument to r<dist>_trng:

rng <- yarn2$new()
rng$seed(12358)
rng$jump(6)
rng$split(5, 3)
runif_trng(2, engine = rng)
#> [1] 0.121799 0.550692

In addition, parallel generation of random variates can be enabled in r<dist>_trng via RcppParallel using argument parallelGrain > 0:

TRNGseed(12358)
RcppParallel::setThreadOptions(numThreads = 2)
x_parallel <- rnorm_trng(1e5L, parallelGrain = 100L)
TRNGseed(12358)
x_serial <- rnorm_trng(1e5L)
identical(x_serial, x_parallel)
#> [1] TRUE

Use TRNG from standalone C++

The TRNG C++ library is made available by rTRNG to standalone C++ code compiled with Rcpp::sourceCpp thanks to the Rcpp::depends attribute, with Rcpp::plugins(cpp11) enforcing the C++11 standard required by TRNG >= 4.22:

// [[Rcpp::depends(rTRNG)]]
// TRNG >= 4.22 requires C++11
// [[Rcpp::plugins(cpp11)]]
#include <Rcpp.h>
#include <trng/yarn2.hpp>
#include <trng/uniform_dist.hpp>
// [[Rcpp::export]]
Rcpp::NumericVector exampleCpp() {
  trng::yarn2 rng(12358);
  rng.jump(6);
  rng.split(5, 2); // 0-based index
  Rcpp::NumericVector x(2);
  trng::uniform_dist<>unif(0, 1);
  for (unsigned int i = 0; i < 2; i++) {
    x[i] = unif(rng);
  }
  return x;
}
exampleCpp()
#> [1] 0.121799 0.550692

Use TRNG from other R packages

Creating an R package with C++ code using the TRNG library and headers through rTRNG is achieved by

  • adding Imports: rTRNG and LinkingTo: rTRNG to the DESCRIPTION file
  • importing one symbol in the NAMESPACE: importFrom(rTRNG, TRNG.Version)
  • enforcing compilation using C++11 in Makevars[.win] via CXX_STD = CXX11
  • setting the relevant linker flags in Makevars[.win] via rTRNG::LdFlags()
    • Makevars: PKG_LIBS += $(shell ${R_HOME}/bin/Rscript -e "rTRNG::LdFlags()")
    • Makevars.win: PKG_LIBS += $(shell "${R_HOME}/bin${R_ARCH_BIN}/Rscript.exe" -e "rTRNG::LdFlags()")

Note about C++ code on macOS

C++ code using the TRNG library (sourced via Rcpp::sourceCpp or part of an R package) might fail on certain systems due to issues with building and linking against rTRNG. This is typically the case for macOS, and can generally be checked by running

rTRNG::check_rTRNG_linking()
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].