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 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
source("incl/start,load-only.R")
message("*** plan() ...")
message("*** future::plan(future.batchtools::batchtools_local)")
oplan <- future::plan(future.batchtools::batchtools_local)
print(future::plan())
future::plan(oplan)
print(future::plan())
library("future.batchtools")
for (type in c("batchtools_interactive", "batchtools_local")) {
mprintf("*** plan('%s') ...\n", type)
plan(type)
stopifnot(inherits(plan("next"), "batchtools"))
a <- 0
f <- future({
b <- 3
c <- 2
a * b * c
})
a <- 7 ## Make sure globals are frozen
v <- value(f)
print(v)
stopifnot(v == 0)
## Customize the 'work.dir' of the batchtools registries
normalize_path <- function(path) {
if (!utils::file_test("-d", path)) stop("No such path: ", path)
opwd <- getwd()
on.exit(setwd(opwd))
setwd(normalizePath(path))
getwd()
}
plan(type, registry = list(work.dir = NULL))
f <- future(42, lazy = TRUE)
## In future releases, lazy futures may stay vanilla Future objects
if (inherits(f, "BatchtoolsFuture")) {
if (!is.null(f$config$reg)) {
utils::str(list(
normalize_path(f$config$reg$work.dir),
getwd = getwd()
))
stopifnot(normalize_path(f$config$reg$work.dir) == getwd())
}
}
path <- tempdir()
plan(type, registry = list(work.dir = path))
f <- future(42, lazy = TRUE)
## In future releases, lazy futures may stay vanilla Future objects
if (inherits(f, "BatchtoolsFuture")) {
if (!is.null(f$config$reg)) {
utils::str(list(
normalize_path(f$config$reg$work.dir),
path = normalize_path(path)
))
stopifnot(normalize_path(f$config$reg$work.dir) == normalize_path(path))
}
}
mprintf("*** plan('%s') ... DONE\n", type)
} # for (type ...)
message("*** Assert that default backend can be overridden ...")
mpid <- Sys.getpid()
print(mpid)
plan(batchtools_interactive)
pid %<-% { Sys.getpid() }
print(pid)
stopifnot(pid == mpid)
plan(batchtools_local)
pid %<-% { Sys.getpid() }
print(pid)
stopifnot(pid != mpid)
message("*** plan() ... DONE")
source("incl/end.R")
|