1% Generated by roxygen2: do not edit by hand
2% Please edit documentation in R/multiprocess.R
3\name{multiprocess}
4\alias{multiprocess}
5\title{Create a multiprocess future whose value will be resolved asynchronously using multicore or a multisession evaluation}
6\usage{
7multiprocess(..., workers = availableCores(), envir = parent.frame())
8}
9\arguments{
10\item{\dots}{Additional arguments passed to \code{\link[=Future]{Future()}}.}
11
12\item{workers}{A positive numeric scalar or a function specifying the
13maximum number of parallel futures that can be active at the same time
14before blocking.
15If a function, it is called without arguments \emph{when the future
16is created} and its value is used to configure the workers.
17The function should return a numeric scalar.}
18
19\item{envir}{The \link{environment} from where global objects should be
20identified.}
21}
22\value{
23A \link{MultiprocessFuture} implemented as either a
24\link{MulticoreFuture} or a \link{MultisessionFuture}.
25}
26\description{
27A multiprocess future is a future that uses \link{multicore} evaluation
28if supported, otherwise it uses \link{multisession} evaluation.
29Regardless, its \emph{value is computed and resolved in
30parallel in another process}.\cr
31\cr
32\emph{WARNING: Consider the 'multiprocess' future plan deprecated.
33Instead, explicitly specify 'multisession' or 'multicore'.  The former works
34everywhere and is the recommended one between the two. \emph{Forked processing},
35which 'multicore' uses, is unstable in various environment and setups.
36The 'multiprocess' alias is therefore being phased out.}
37}
38\examples{
39\donttest{
40
41## Use multiprocess futures
42plan(multiprocess)
43
44## A global variable
45a <- 0
46
47## Create future (explicitly)
48f <- future({
49  b <- 3
50  c <- 2
51  a * b * c
52})
53
54## A multiprocess future is evaluated in a separate R process.
55## Changing the value of a global variable will not affect
56## the result of the future.
57a <- 7
58print(a)
59
60v <- value(f)
61print(v)
62stopifnot(v == 0)
63
64## Explicitly close multisession workers, if they were used
65plan(sequential)
66}
67}
68\seealso{
69Internally \code{\link[=multicore]{multicore()}} and \code{\link[=multisession]{multisession()}}
70are used.
71}
72\keyword{internal}
73