multisession: Create a multisession future whose value will be resolved...

Description Usage Arguments Details Value See Also Examples

View source: R/multisession.R

Description

A multisession future is a future that uses multisession evaluation, which means that its value is computed and resolved in parallel in another R session.

Usage

1
2
3
4
multisession(expr, envir = parent.frame(), substitute = TRUE,
  lazy = FALSE, seed = NULL, globals = TRUE, persistent = FALSE,
  workers = availableCores(), gc = FALSE, earlySignal = FALSE,
  label = NULL, ...)

Arguments

expr

An R expression.

envir

The environment from where global objects should be identified.

substitute

If TRUE, argument expr is substitute():ed, otherwise not.

lazy

If FALSE (default), the future is resolved eagerly (starting immediately), otherwise not.

seed

(optional) A L'Ecuyer-CMRG RNG seed.

globals

(optional) a logical, a character vector, or a named list to control how globals are handled. For details, see section 'Globals used by future expressions' in the help for future().

persistent

If FALSE, the evaluation environment is cleared from objects prior to the evaluation of the future.

workers

A positive numeric scalar or a function specifying the maximum number of parallel futures that can be active at the same time before blocking. If a function, it is called without arguments when the future is created and its value is used to configure the workers. The function should return a numeric scalar.

gc

If TRUE, the garbage collector run (in the process that evaluated the future) only after the value of the future is collected. Exactly when the values are collected may depend on various factors such as number of free workers and whether earlySignal is TRUE (more frequently) or FALSE (less frequently). Some types of futures ignore this argument.

earlySignal

Specified whether conditions should be signaled as soon as possible or not.

label

An optional character string label attached to the future.

...

Additional named elements passed to Future().

Details

The background R sessions (the "workers") are created using makeClusterPSOCK().

The multisession() function will block if all available R session are occupied and will be unblocked as soon as one of the already running multisession futures is resolved. For the total number of R sessions available including the current/main R process, see availableCores().

A multisession future is a special type of cluster future.

The preferred way to create an multisession future is not to call this function directly, but to register it via plan(multisession) such that it becomes the default mechanism for all futures. After this future() and %<-% will create multisession futures.

Value

A MultisessionFuture. If workers == 1, then all processing using done in the current/main R session and we therefore fall back to using a lazy future.

See Also

For processing in multiple forked R sessions, see multicore 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.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
## Use multisession futures
plan(multisession)

## A global variable
a <- 0

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

## A multisession future is evaluated in a separate R session.
## 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)

future documentation built on Nov. 8, 2019, 5:06 p.m.