future (version 0.8.0)

multicore: Create a multicore future whose value will be resolved asynchroneously in a 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,
  maxCores = availableCores(), ...)

Arguments

expr
envir
The environment in which the evaluation is done and from which globals are obtained.
substitute
If TRUE, argument expr is substitute():ed, otherwise not.
maxCores
The maximum number of CPU cores that can be active at the same time before blocking.
...
Not used.

Value

Details

This function will block if all CPU cores are occupied and will be unblocked as soon as one of the already running multicore futures is resolved. For the total number of CPU cores availble to the current 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 eager 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 %<=%< a=""> will create multicore futures.

See Also

availableCores() > 1L to check whether multicore futures are supported or not.

Examples

Run this code
## A global variable
a <- 0

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

## A multicore future is evaluated in a separated
## 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