Skip to content

Commit

Permalink
Now multicore futures use eager ones as backup
Browse files Browse the repository at this point in the history
  • Loading branch information
HenrikBengtsson committed Jun 19, 2015
1 parent f4d6ce0 commit 6dcf17a
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 286 deletions.
2 changes: 1 addition & 1 deletion R/Future-class.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Future <- function(expr=NULL, envir=parent.frame(), substitute=FALSE, ...) {
#' @param onError A character string specifying how errors
#' (\link[base]{conditions}) should be handled in case they occur.
#' If \code{"signal"}, the error is signalled, e.g. captured
#' errors and re-thrown. If instead \code{"return"}, they are
#' and re-thrown. If instead \code{"return"}, they are
#' \emph{returned} as is.
#' @param ... Not used.
#'
Expand Down
6 changes: 3 additions & 3 deletions R/multicore.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#' \code{\link[base]{substitute}()}:ed, otherwise not.
#' @param ... Not used.
#'
#' @return A \link{MulticoreFuture} (or a \link{LazyFuture}
#' @return A \link{MulticoreFuture} (or a \link{EagerFuture}
#' if multicore futures are not supported).
#'
#' @example incl/multicore.R
Expand All @@ -20,7 +20,7 @@
#' 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 \link{lazy} futures, which effectively
#' fall back to using \link{eager} futures, which effectively
#' corresponds to a multicore future that can handle one parallel
#' process (the current one) before blocking.
#'
Expand All @@ -41,7 +41,7 @@ multicore <- function(expr, envir=parent.frame(), substitute=TRUE, ...) {
## Fall back to lazy futures, iff multicore is not suported
if (!supportsMulticore()) {
## covr: skip=1
return(lazy(expr, envir=envir, substitute=FALSE, local=TRUE))
return(eager(expr, envir=envir, substitute=FALSE, local=TRUE))
}

future <- MulticoreFuture(expr=expr, envir=envir, substitute=FALSE)
Expand Down
272 changes: 0 additions & 272 deletions README.md

This file was deleted.

4 changes: 2 additions & 2 deletions man/multicore.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ is done and from which globals are obtained.}
\item{...}{Not used.}
}
\value{
A \link{MulticoreFuture} (or a \link{LazyFuture}
A \link{MulticoreFuture} (or a \link{EagerFuture}
if multicore futures are not supported).
}
\description{
Expand All @@ -30,7 +30,7 @@ parallel in another process}.
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 \link{lazy} futures, which effectively
fall back to using \link{eager} futures, which effectively
corresponds to a multicore future that can handle one parallel
process (the current one) before blocking.

Expand Down
2 changes: 1 addition & 1 deletion man/value.Future.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
\item{onError}{A character string specifying how errors
(\link[base]{conditions}) should be handled in case they occur.
If \code{"signal"}, the error is signalled, e.g. captured
errors and re-thrown. If instead \code{"return"}, they are
and re-thrown. If instead \code{"return"}, they are
\emph{returned} as is.}

\item{...}{Not used.}
Expand Down
14 changes: 7 additions & 7 deletions vignettes/future.md.rsp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ This works by (i) creating a future and (ii) assigning its value to variable `v`


### Eager, lazy and parallel futures
You are responsible for your own futures and how you choose to resolve them may differ depending on your needs and your resources. The 'future' package provides two _synchronous_ futures, namely "lazy" and "eager", implemented by functions `lazy()` and `eager()`. It also provides one _asynchronous_ future, the "multicore" future, implemented by function `multicore()`. The latter is available on systems where R supports multicore processing, that is, on Unix-like operating systems, but not on Windows. On non-supported systems, multicore futures automatically becomes lazy futures.
You are responsible for your own futures and how you choose to resolve them may differ depending on your needs and your resources. The 'future' package provides two _synchronous_ futures, namely "lazy" and "eager", implemented by functions `lazy()` and `eager()`. It also provides one _asynchronous_ future, the "multicore" future, implemented by function `multicore()`. The latter is available on systems where R supports multicore processing, that is, on Unix-like operating systems, but not on Windows. On non-supported systems, multicore futures automatically becomes eager futures.

Since an asynchronous strategy is more likely to be used in practice, the built-in eager and lazy mechanisms try to emulate those as far as possible while at the same time evaluating them in a synchronous way. For example, the default is that the future expression is evaluated in _a local environment_ (cf. `help("local")`), which means that any assignments are done to local variables only - such that the environment of the main/calling process is unaffected. Here is an example:

Expand Down Expand Up @@ -131,13 +131,13 @@ It is possible to nest futures in multiple levels and each of the nested futures
> plan(lazy)
> c %<=% {
+ message("Resolving 'c'")
+ a %<=% {
+ a %<=% {
+ message("Resolving 'a'")
+ 3
+ } %plan% eager
+ b %<=% {
+ message("Resolving 'b'")
+ -9 * a
+ -9 * a
+ }
+ message("Local variable 'x'")
+ x <- b / 3
Expand Down Expand Up @@ -202,10 +202,10 @@ Just as for any type of environment, all values of a list environment can be re


## Failed futures
Sometimes the future is not what you expected. If an error occurs while evaluating a future, the error is propagated and thrown as an error in the calling environment _when the future value is requested_. For example,
Sometimes the future is not what you expected. If an error occurs while evaluating a future, the error is propagated and thrown as an error in the calling environment _when the future value is requested_. For example,
```r
> plan(lazy)
> f <- future({
> f <- future({
+ stop("Whoops!")
+ 42
+ })
Expand All @@ -221,7 +221,7 @@ Error in eval(expr, envir, enclos) : Whoops!
Exception handling of future assignments via `%<=%` works analogously, e.g.
```r
> plan(lazy)
> x %<=% ({
> x %<=% ({
+ stop("Whoops!")
+ 42
+ })
Expand Down Expand Up @@ -262,7 +262,7 @@ plan(multicore)
demo("mandelbrot", package="future", ask=FALSE)
```

_Footnote_: (*) If you system does not support multicore processing, such as Windows, then it will automatically fall back to use lazy futures instead of multicore ones.
_Footnote_: (*) If you system does not support multicore processing, such as Windows, then it will automatically fall back to use eager futures instead of multicore ones.
---%>


Expand Down

0 comments on commit 6dcf17a

Please sign in to comment.