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 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230
|
#' Batchtools futures for LSF, OpenLava, SGE, Slurm, TORQUE etc.
#'
#' Batchtools futures for LSF, OpenLava, SGE, Slurm, TORQUE etc. are
#' asynchronous multiprocess futures that will be evaluated on a compute
#' cluster via a job scheduler.
#'
#' @inheritParams BatchtoolsFuture
#'
#' @param template (optional) A batchtools template file or a template string
#' (in \pkg{brew} format). If not specified, it is left to the
#' \pkg{batchtools} package to locate such file using its search rules.
#'
#' @param \ldots Additional arguments passed to [BatchtoolsFuture()].
#'
#' @return An object of class `BatchtoolsFuture`.
#'
#' @details
#' These type of batchtools futures rely on batchtools backends set
#' up using the following \pkg{batchtools} functions:
#'
#' * [batchtools::makeClusterFunctionsLSF()] for
#' [Load Sharing Facility (LSF)](https://en.wikipedia.org/wiki/Platform_LSF)
#' * [batchtools::makeClusterFunctionsOpenLava()] for
#' [OpenLava](https://en.wikipedia.org/wiki/OpenLava)
#' * [batchtools::makeClusterFunctionsSGE()] for
#' [Sun/Oracle Grid Engine (SGE)](https://en.wikipedia.org/wiki/Oracle_Grid_Engine)
#' * [batchtools::makeClusterFunctionsSlurm()] for
#' [Slurm](https://en.wikipedia.org/wiki/Slurm_Workload_Manager)
#' * [batchtools::makeClusterFunctionsTORQUE()] for
#' [TORQUE](https://en.wikipedia.org/wiki/TORQUE) / PBS
#'
#' @export
#' @rdname batchtools_template
#' @name batchtools_template
batchtools_lsf <- function(expr, envir = parent.frame(), substitute = TRUE,
globals = TRUE, label = NULL,
template = NULL, resources = list(),
workers = NULL,
registry = list(), ...) {
if (substitute) expr <- substitute(expr)
batchtools_by_template(expr, envir = envir, substitute = FALSE,
globals = globals, label = label, template = template,
type = "lsf", resources = resources,
workers = workers, registry = registry, ...)
}
class(batchtools_lsf) <- c(
"batchtools_lsf", "batchtools_template",
"batchtools_multiprocess", "batchtools",
"multiprocess", "future", "function"
)
attr(batchtools_lsf, "tweakable") <- c(
"finalize",
## Arguments to batchtools::makeClusterFunctionsLSF()
"scheduler.latency", "fs.latency"
)
#' @export
#' @rdname batchtools_template
batchtools_openlava <- function(expr, envir = parent.frame(), substitute = TRUE,
globals = TRUE, label = NULL,
template = NULL, resources = list(),
workers = NULL,
registry = list(), ...) {
if (substitute) expr <- substitute(expr)
batchtools_by_template(expr, envir = envir, substitute = FALSE,
globals = globals, label = label, template = template,
type = "openlava", resources = resources,
workers = workers, registry = registry, ...)
}
class(batchtools_openlava) <- c(
"batchtools_openlava", "batchtools_template",
"batchtools_multiprocess", "batchtools",
"multiprocess", "future", "function"
)
attr(batchtools_openlava, "tweakable") <- c(
"finalize",
## Arguments to batchtools::makeClusterFunctionsOpenLava()
"scheduler.latency", "fs.latency"
)
#' @export
#' @rdname batchtools_template
batchtools_sge <- function(expr, envir = parent.frame(), substitute = TRUE,
globals = TRUE, label = NULL,
template = NULL, resources = list(),
workers = NULL,
registry = list(), ...) {
if (substitute) expr <- substitute(expr)
batchtools_by_template(expr, envir = envir, substitute = FALSE,
globals = globals, label = label, template = template,
type = "sge", resources = resources,
workers = workers, registry = registry, ...)
}
class(batchtools_sge) <- c(
"batchtools_sge", "batchtools_template",
"batchtools_multiprocess", "batchtools",
"multiprocess", "future", "function"
)
attr(batchtools_sge, "tweakable") <- c(
"finalize",
## Arguments to batchtools::makeClusterFunctionsSGE()
"nodename", "scheduler.latency", "fs.latency"
)
#' @export
#' @rdname batchtools_template
batchtools_slurm <- function(expr, envir = parent.frame(), substitute = TRUE,
globals = TRUE, label = NULL,
template = NULL, resources = list(),
workers = NULL,
registry = list(), ...) {
if (substitute) expr <- substitute(expr)
batchtools_by_template(expr, envir = envir, substitute = FALSE,
globals = globals, label = label, template = template,
type = "slurm", resources = resources,
workers = workers, registry = registry, ...)
}
class(batchtools_slurm) <- c(
"batchtools_slurm", "batchtools_template",
"batchtools_multiprocess", "batchtools",
"multiprocess", "future", "function"
)
attr(batchtools_slurm, "tweakable") <- c(
"finalize",
## Arguments to batchtools::makeClusterFunctionsSlurm()
"array.jobs", "nodename", "scheduler.latency", "fs.latency"
)
#' @export
#' @rdname batchtools_template
batchtools_torque <- function(expr, envir = parent.frame(), substitute = TRUE,
globals = TRUE, label = NULL,
template = NULL, resources = list(),
workers = NULL,
registry = list(), ...) {
if (substitute) expr <- substitute(expr)
batchtools_by_template(expr, envir = envir, substitute = FALSE,
globals = globals, label = label, template = template,
type = "torque", resources = resources,
workers = workers, registry = registry, ...)
}
class(batchtools_torque) <- c(
"batchtools_torque", "batchtools_template",
"batchtools_multiprocess", "batchtools",
"multiprocess", "future", "function"
)
attr(batchtools_torque, "tweakable") <- c(
"finalize",
## Arguments to batchtools::makeClusterFunctionsTORQUE()
"scheduler.latency", "fs.latency"
)
#' @importFrom batchtools makeClusterFunctionsLSF
#' @importFrom batchtools makeClusterFunctionsOpenLava
#' @importFrom batchtools makeClusterFunctionsSGE
#' @importFrom batchtools makeClusterFunctionsSlurm
#' @importFrom batchtools makeClusterFunctionsTORQUE
batchtools_by_template <- function(expr, envir = parent.frame(),
substitute = TRUE, globals = TRUE,
template = NULL,
type = c("lsf", "openlava", "sge",
"slurm", "torque"),
resources = list(), label = NULL,
workers = NULL,
registry = list(), ...) {
if (substitute) expr <- substitute(expr)
type <- match.arg(type)
dotdotdot <- list(...)
make_cfs <- switch(type,
lsf = makeClusterFunctionsLSF,
openlava = makeClusterFunctionsOpenLava,
sge = makeClusterFunctionsSGE,
slurm = makeClusterFunctionsSlurm,
torque = makeClusterFunctionsTORQUE
)
constructor <- switch(type,
lsf = BatchtoolsLsfFuture,
openlava = BatchtoolsOpenLavaFuture,
sge = BatchtoolsSGEFuture,
slurm = BatchtoolsSlurmFuture,
torque = BatchtoolsTorqueFuture
)
make_cfs_formals <- formals(make_cfs)
## Get the default template?
if (is.null(template)) {
template <- make_cfs_formals$template
}
stop_if_not(is.character(template), length(template) == 1L,
!is.na(template), nzchar(template))
template <- find_template_file(template)
keep <- which(names(dotdotdot) %in% names(make_cfs_formals))
args <- c(list(template = template), dotdotdot[keep])
cluster.functions <- do.call(make_cfs, args = args)
attr(cluster.functions, "template") <- template
## Drop used '...' arguments
if (length(keep) > 0) dotdotdot <- dotdotdot[-keep]
args <- list(
expr = quote(expr), ## Avoid 'expr' being resolved by do.call()
substitute = FALSE, envir = envir,
globals = globals,
label = label,
cluster.functions = cluster.functions,
registry = registry,
resources = resources,
workers = workers
)
if (length(dotdotdot) > 0) args <- c(args, dotdotdot)
future <- do.call(constructor, args = args)
if (!future$lazy) future <- run(future)
invisible(future)
} ## batchtools_by_template()
|