mirai_cluster: Mirai-based cluster futures

View source: R/MiraiFutureBackend-class.R

mirai_clusterR Documentation

Mirai-based cluster futures

Description

WARNING: This function must never be called. It may only be used with future::plan()

Usage

mirai_cluster(..., envir = parent.frame())

Arguments

envir

The environment from where global objects should be identified.

...

Not used.

Value

Nothing.

Examples

# Manually launch mirai workers
mirai::daemons(parallelly::availableCores())

plan(mirai_cluster)

# 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)

## Switch back to sequential processing
plan(sequential)

## Shut down manually launched mirai workers
invisible(mirai::daemons(0))

future.mirai documentation built on June 8, 2025, 12:43 p.m.