Title: | A 'Future' API for Parallel Processing using 'mirai' |
---|---|
Description: | Implementation of the 'Future' API <doi:10.32614/RJ-2021-048> on top of the 'mirai' package <doi:10.5281/zenodo.7912722>. This allows you to process futures, as defined by the 'future' package, in parallel out of the box, on your local machine or across remote machines. Contrary to back-ends relying on the 'parallel' package (e.g. 'multisession') and socket connections, 'mirai_cluster' and 'mirai_multisession', provided here, can run more than 125 parallel R processes. |
Authors: | Henrik Bengtsson [aut, cre, cph] , Charlie Gao [ctb] |
Maintainer: | Henrik Bengtsson <[email protected]> |
License: | GPL (>= 3) |
Version: | 0.2.2 |
Built: | 2024-11-01 06:44:06 UTC |
Source: | CRAN |
The future.mirai package implements the Future API using the mirai package.
Maintainer: Henrik Bengtsson [email protected] (ORCID) [copyright holder]
Other contributors:
Charlie Gao [email protected] (ORCID) [contributor]
Useful links:
Report bugs at https://github.com/futureverse/future.mirai/issues
TRUE
TRUE
Mirai-based cluster futures
mirai_cluster(expr, substitute = TRUE, envir = parent.frame(), ...)
mirai_cluster(expr, substitute = TRUE, envir = parent.frame(), ...)
expr |
An R expression. |
substitute |
If TRUE, argument |
envir |
The environment from where global objects should be identified. |
... |
Additional named elements of the future. |
An object of class MiraiFuture.
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
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
Mirai-based localhost multisession futures
mirai_multisession( expr, substitute = TRUE, envir = parent.frame(), ..., workers = availableCores() )
mirai_multisession( expr, substitute = TRUE, envir = parent.frame(), ..., workers = availableCores() )
expr |
An R expression. |
substitute |
If TRUE, argument |
envir |
The environment from where global objects should be identified. |
... |
Additional named elements of the future. |
workers |
The number of parallel processes to use. If a function, it is called without arguments when the future is created and its value is used to configure the workers. |
An object of class MiraiFuture.
plan(mirai_multisession) # 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
plan(mirai_multisession) # 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