future.mirai: A Future API for Parallel Processing using 'mirai'
Source:R/package.R
future.mirai.Rd
The future.mirai package implements the Future API using the mirai package.
Author
Maintainer: Henrik Bengtsson henrikb@braju.com (ORCID) [copyright holder]
Other contributors:
Charlie Gao charlie.gao@shikokuchuo.net (ORCID) (For 'mirai'-related patches and implementing feature requests in 'mirai') [contributor]
Examples
plan(mirai_multisession)
# A function that returns a future
# (note that N is a global variable)
f <- function() future({
4 * sum((runif(N) ^ 2 + runif(N) ^ 2) < 1) / N
}, seed = TRUE)
# Run a simple sampling approximation of pi in parallel using M * N points:
N <- 1e6 # samples per worker
M <- 10 # iterations
pi_est <- Reduce(sum, Map(value, replicate(M, f()))) / M
print(pi_est)
#> [1] 3.141674
## Switch back to sequential processing, which also
## shuts down the automatically launched mirai workers
plan(sequential)