Skip to content

Commit def5b0f

Browse files
batchtools_torque(): help + tweak template script
1 parent 7a9d5f6 commit def5b0f

File tree

6 files changed

+179
-34
lines changed

6 files changed

+179
-34
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-9920
2+
Version: 0.12.2-9921
33
Depends:
44
R (>= 3.2.0),
55
parallelly,

R/batchtools_template.R

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#' [TORQUE](https://en.wikipedia.org/wiki/TORQUE) / PBS
3333
#'
3434
#' @aliases BatchtoolsLsfFutureBackend BatchtoolsOpenLavaFutureBackend BatchtoolsSGEFutureBackend BatchtoolsSlurmFutureBackend BatchtoolsTorqueFutureBackend
35-
#' @aliases batchtools_lsf batchtools_openlava batchtools_torque
35+
#' @aliases batchtools_lsf batchtools_openlava
3636
#'
3737
#' @importFrom batchtools makeClusterFunctionsLSF
3838
#' @importFrom batchtools makeClusterFunctionsOpenLava
@@ -138,31 +138,3 @@ attr(batchtools_openlava, "tweakable") <- c(
138138
)
139139
attr(batchtools_openlava, "init") <- TRUE
140140
attr(batchtools_openlava, "factory") <- BatchtoolsOpenLavaFutureBackend
141-
142-
143-
144-
#' @export
145-
BatchtoolsTorqueFutureBackend <- function(...) {
146-
core <- BatchtoolsTemplateFutureBackend(..., type = "torque")
147-
core[["futureClasses"]] <- c("BatchtoolsTorqueFuture", core[["futureClasses"]])
148-
core <- structure(core, class = c("BatchtoolsTorqueFutureBackend", class(core)))
149-
core
150-
}
151-
152-
#' @export
153-
batchtools_torque <- function(...) {
154-
stop("INTERNAL ERROR: The future.batchtools::batchtools_torque() must never be called directly")
155-
}
156-
class(batchtools_torque) <- c(
157-
"batchtools_torque", "batchtools_template",
158-
"batchtools_multiprocess", "batchtools",
159-
"multiprocess", "future", "function"
160-
)
161-
attr(batchtools_torque, "tweakable") <- c(
162-
"workers",
163-
"finalize",
164-
## Arguments to batchtools::makeClusterFunctionsTORQUE()
165-
"scheduler.latency", "fs.latency"
166-
)
167-
attr(batchtools_torque, "init") <- TRUE
168-
attr(batchtools_torque, "factory") <- BatchtoolsTorqueFutureBackend

R/batchtools_torque.R

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

inst/templates/torque.tmpl

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#!/bin/bash
22
######################################################################
3-
# A batchtools launch script template for Torque/PBS
3+
# A batchtools launch script template for TORQUE/PBS
44
#
55
# Author: Henrik Bengtsson
66
######################################################################
77

88
## Job name:
9-
#PBS -N <%= if (exists("job.name", mode = "character")) job.name else job.hash %>
9+
#PBS -N <%= job.name %>
1010

1111
## Direct streams to logfile:
1212
#PBS -o <%= log.file %>
@@ -25,5 +25,24 @@
2525
#PBS -l <%= opts %>
2626
<% } %>
2727

28-
## Launch R and evaluated the batchtools R job
28+
echo "Batchtools job name: '<%= job.name %>'"
29+
30+
echo "Session information:"
31+
date
32+
hostname
33+
which Rscript
34+
Rscript --version
35+
Rscript -e ".libPaths()"
36+
37+
## Launch R and evaluate the batchtools R job
38+
echo "Command: Rscript -e 'batchtools::doJobCollection("<%= uri %>")' ..."
2939
Rscript -e 'batchtools::doJobCollection("<%= uri %>")'
40+
res=$?
41+
echo " - exit code: ${res}"
42+
echo "Command: Rscript -e 'batchtools::doJobCollection("<%= uri %>")' ... done"
43+
44+
## End-of-job summary
45+
qstat -f "${PBS_JOBID}"
46+
47+
## Relay the exit code from Rscript
48+
exit "${res}"

man/BatchtoolsTemplateFutureBackend.Rd

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

man/batchtools_torque.Rd

Lines changed: 93 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)