future (version 1.3.0)

multicore: Create a multicore future whose value will be resolved asynchronously in a forked parallel process

Description

A multicore future is a future that uses multicore evaluation, which means that its value is computed and resolved in parallel in another process.

Usage

multicore(expr, envir = parent.frame(), substitute = TRUE, lazy = FALSE,
  seed = NULL, globals = TRUE, workers = availableCores(constraints =
  "multicore"), earlySignal = FALSE, label = NULL, ...)

Arguments

expr
An R expression to be evaluated.
envir
The environment from where global objects should be identified. Depending on the future strategy (the evaluator), it may also be the environment in which the expression is evaluated.
substitute
If TRUE, argument expr is substitute():ed, otherwise not.
lazy
Specifies whether a future should be resolved lazily or eagerly. The default is eager evaluation (except when the deprecated plan(lazy) is used).
seed
(optional) A L'Ecuyer-CMRG RNG seed.
globals
A logical, a character vector, or a named list for controlling how globals are handled. For details, see below section.
workers
The maximum number of multicore futures that can be active at the same time before blocking.
earlySignal
Specified whether conditions should be signaled as soon as possible or not.
label
An optional character string label attached to the future.
...
Additional arguments passed to the "evaluator".

Value

A MulticoreFuture If workers == 1, then all processing using done in the current/main R session and we therefore fall back to using an sequential future. This is also the case whenever multicore processing is not supported, e.g. on Windows.

Details

This function will block if all cores are occupied and will be unblocked as soon as one of the already running multicore futures is resolved. For the total number of cores available including the current/main R process, see availableCores(). Not all systems support multicore futures. For instance, it is not supported on Microsoft Windows. Trying to create multicore futures on non-supported systems will silently fall back to using sequential futures, which effectively corresponds to a multicore future that can handle one parallel process (the current one) before blocking. The preferred way to create an multicore future is not to call this function directly, but to register it via plan(multicore) such that it becomes the default mechanism for all futures. After this future() and %<-% will create multicore futures.

See Also

For processing in multiple background R sessions, see multisession futures. For multicore processing with fallback to multisession where the former is not supported, see multiprocess futures. Use availableCores() to see the total number of cores that are available for the current R session. Use availableCores("multicore") > 1L to check whether multicore futures are supported or not on the current system.

Examples

Run this code
## Use multicore futures
plan(multicore)

## A global variable
a <- 0

## Create multicore future (explicitly)
f <- future({
  b <- 3
  c <- 2
  a * b * c
})

## A multicore future is evaluated in a separate forked
## process.  Changing the value of a global variable
## will not affect the result of the future.
a <- 7
print(a)

v <- value(f)
print(v)
stopifnot(v == 0)

Run the code above in your browser using DataLab