Skip to content

Commit 47e0444

Browse files
batchtools_openlava(): help + add template script
1 parent 550cadb commit 47e0444

File tree

7 files changed

+193
-32
lines changed

7 files changed

+193
-32
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Package: future.batchtools
2-
Version: 0.12.2-9922
2+
Version: 0.12.2-9923
33
Depends:
44
R (>= 3.2.0),
55
parallelly,

NEWS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* Canceling batchtools futures will now interrupt them by default,
1515
if the backend supports it.
1616

17-
* Add built-in template job script for LSF.
17+
* Add built-in template job script for LSF and OpenLava.
1818

1919
## Documentation
2020

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
#' [TORQUE](https://en.wikipedia.org/wiki/TORQUE) / PBS
3333
#'
3434
#' @aliases BatchtoolsLsfFutureBackend BatchtoolsOpenLavaFutureBackend BatchtoolsSGEFutureBackend BatchtoolsSlurmFutureBackend BatchtoolsTorqueFutureBackend
35-
#' @aliases batchtools_openlava
3635
#'
3736
#' @importFrom batchtools makeClusterFunctionsLSF
3837
#' @importFrom batchtools makeClusterFunctionsOpenLava
@@ -84,30 +83,3 @@ BatchtoolsTemplateFutureBackend <- function(..., template = NULL, type = c("lsf"
8483
core <- structure(core, class = c("BatchtoolsTemplateFutureBackend", class(core)))
8584
core
8685
}
87-
88-
89-
#' @export
90-
BatchtoolsOpenLavaFutureBackend <- function(...) {
91-
core <- BatchtoolsTemplateFutureBackend(..., type = "openlava")
92-
core[["futureClasses"]] <- c("BatchtoolsOpenLavaFuture", core[["futureClasses"]])
93-
core <- structure(core, class = c("BatchtoolsOpenLavaFutureBackend", class(core)))
94-
core
95-
}
96-
97-
#' @export
98-
batchtools_openlava <- function(...) {
99-
stop("INTERNAL ERROR: The future.batchtools::batchtools_openlava() must never be called directly")
100-
}
101-
class(batchtools_openlava) <- c(
102-
"batchtools_openlava", "batchtools_template",
103-
"batchtools_multiprocess", "batchtools",
104-
"multiprocess", "future", "function"
105-
)
106-
attr(batchtools_openlava, "tweakable") <- c(
107-
"workers",
108-
"finalize",
109-
## Arguments to batchtools::makeClusterFunctionsOpenLava()
110-
"scheduler.latency", "fs.latency"
111-
)
112-
attr(batchtools_openlava, "init") <- TRUE
113-
attr(batchtools_openlava, "factory") <- BatchtoolsOpenLavaFutureBackend

R/batchtools_openlava.R

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#' @export
2+
BatchtoolsOpenLavaFutureBackend <- function(...) {
3+
core <- BatchtoolsTemplateFutureBackend(..., type = "openlava")
4+
core[["futureClasses"]] <- c("BatchtoolsOpenLavaFuture", core[["futureClasses"]])
5+
core <- structure(core, class = c("BatchtoolsOpenLavaFutureBackend", class(core)))
6+
core
7+
}
8+
9+
10+
#' A batchtools openlava backend resolves futures in parallel via a OpenLava job scheduler
11+
#'
12+
#' @inheritParams BatchtoolsFutureBackend
13+
#' @inheritParams BatchtoolsTemplateFutureBackend
14+
#'
15+
#' @param template (optional) Name of job-script template to be searched
16+
#' for by [batchtools::findTemplateFile()]. If not found, it defaults to
17+
#' the `templates/openlava.tmpl` part of this package (see below).
18+
#'
19+
#' @param \ldots Not used.
20+
#'
21+
#' @details
22+
#' Batchtools openlava futures use \pkg{batchtools} cluster functions
23+
#' created by [batchtools::makeClusterFunctionsOpenLava()], which requires
24+
#' that OpenLava commands `sbatch`, `squeue`, and `scancel` are installed on
25+
#' the current machine.
26+
#'
27+
#' The default template script `templates/openlava.tmpl` can be found in:
28+
#'
29+
#' ```r
30+
#' system.file("templates", "openlava.tmpl", package = "future.batchtools")
31+
#' ```
32+
#'
33+
#' and comprise:
34+
#'
35+
#' `r paste(c("\x60\x60\x60bash", readLines("inst/templates/openlava.tmpl"), "\x60\x60\x60"), collapse = "\n")`
36+
#'
37+
#' @examplesIf interactive()
38+
#' # Limit runtime to 3 minutes and memory to 200 MiB per future
39+
#' plan(batchtools_openlava, resources = list(time = "00:03:00", mem = "200M"))
40+
#'
41+
#' message("Main process ID: ", Sys.getpid())
42+
#'
43+
#' f <- future(Sys.getpid())
44+
#' pid <- value(f)
45+
#' message("Worker process ID: ", pid)
46+
#'
47+
#' @export
48+
batchtools_openlava <- function(..., template = "openlava") {
49+
stop("INTERNAL ERROR: The future.batchtools::batchtools_openlava() must never be called directly")
50+
}
51+
class(batchtools_openlava) <- c(
52+
"batchtools_openlava", "batchtools_template",
53+
"batchtools_multiprocess", "batchtools",
54+
"multiprocess", "future", "function"
55+
)
56+
attr(batchtools_openlava, "tweakable") <- c(
57+
"workers",
58+
"finalize",
59+
## Arguments to batchtools::makeClusterFunctionsOpenLava()
60+
"scheduler.latency", "fs.latency"
61+
)
62+
attr(batchtools_openlava, "init") <- TRUE
63+
attr(batchtools_openlava, "factory") <- BatchtoolsOpenLavaFutureBackend

inst/templates/openlava.tmpl

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/bash
2+
######################################################################
3+
# A batchtools launch script template for OpenLava
4+
#
5+
# Author: Henrik Bengtsson
6+
######################################################################
7+
8+
## Job name:
9+
#BSUB -J <%= job.name %>
10+
11+
## Direct streams to logfile:
12+
#BSUB -o <%= log.file %>
13+
14+
## Resources needed:
15+
<% if (length(resources) > 0) {
16+
opts <- unlist(resources, use.names = TRUE)
17+
opts <- sprintf("-%s=%s", names(opts), opts)
18+
cat(sprintf("#BSUB %s\n", opts))
19+
<% } %>
20+
21+
echo "Batchtools job name: '<%= job.name %>'"
22+
23+
echo "Session information:"
24+
date
25+
hostname
26+
which Rscript
27+
Rscript --version
28+
Rscript -e ".libPaths()"
29+
30+
## Launch R and evaluate the batchtools R job
31+
echo "Command: Rscript -e 'batchtools::doJobCollection("<%= uri %>")' ..."
32+
Rscript -e 'batchtools::doJobCollection("<%= uri %>")'
33+
res=$?
34+
echo " - exit code: ${res}"
35+
echo "Command: Rscript -e 'batchtools::doJobCollection("<%= uri %>")' ... done"
36+
37+
## End-of-job summary
38+
bjobs -l "${LSB_JOBID}"
39+
40+
## Relay the exit code from Rscript
41+
exit "${res}"

man/BatchtoolsTemplateFutureBackend.Rd

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/batchtools_openlava.Rd

Lines changed: 86 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)