Description Usage Arguments Details Value See Also Examples
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.
1 2 3 4 5 6 7 | multisession(
...,
workers = availableCores(),
lazy = FALSE,
rscript_libs = .libPaths(),
envir = parent.frame()
)
|
... |
Additional arguments passed to |
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. |
lazy |
If FALSE (default), the future is resolved eagerly (starting immediately), otherwise not. |
rscript_libs |
A character vector of R package library folders that
the workers should use. The default is |
envir |
The environment from where global objects should be identified. |
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
parallelly::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.
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.
For processing in multiple forked R sessions, see multicore futures.
Use parallelly::availableCores()
to see the total number of
cores that are available for the current R session.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | ## 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)
## Explicitly close multisession workers by switching plan
plan(sequential)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.