mirai_cluster {future.mirai} | R Documentation |
Mirai-based cluster futures
Description
Mirai-based cluster futures
Usage
mirai_cluster(expr, substitute = TRUE, envir = parent.frame(), ...)
Arguments
expr |
An R expression. |
substitute |
If TRUE, argument |
envir |
The environment from where global objects should be identified. |
... |
Additional named elements of the future. |
Value
An object of class MiraiFuture.
Examples
mirai::daemons(parallelly::availableCores(), dispatcher = FALSE)
plan(mirai_cluster)
# A function that returns a future, note that N uses lexical scoping...
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)
plan(sequential)
invisible(mirai::daemons(0)) ## Shut down mirai workers
[Package future.mirai version 0.2.2 Index]