Skip to content

Commit 816b40e

Browse files
committed
Allow user to disable core prescheduling in slurm_apply
Passes argument to mcmapply() via template Documentation updated Also removed some extraneous test output from the repo
1 parent 4e537ab commit 816b40e

File tree

13 files changed

+35
-46
lines changed

13 files changed

+35
-46
lines changed

R/slurm_apply.R

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@
5252
#' @param cpus_per_node The number of CPUs requested per node, i.e., how many
5353
#' processes to run in parallel per node. This argument is mapped to the
5454
#' Slurm parameter \code{cpus-per-task}.
55+
#' @param preschedule_cores Corresponds to the \code{mc.preschedule} argument of
56+
#' \code{parallel::mcmapply}. Defaults to \code{TRUE}. If \code{TRUE}, the
57+
#' jobs are assigned to cores before computation. If \code{FALSE}, a new job is
58+
#' created for each row of \code{params}. Setting \code{FALSE} may be faster if
59+
#' different values of \code{params} result in very variable completion time for
60+
#' jobs.
5561
#' @param add_objects A character vector containing the name of R objects to be
5662
#' saved in a .RData file and loaded on each cluster node prior to calling
5763
#' \code{f}.
@@ -76,17 +82,18 @@
7682
#' number of \code{nodes} effectively used.
7783
#' @seealso \code{\link{slurm_call}} to evaluate a single function call.
7884
#' @seealso \code{\link{cancel_slurm}}, \code{\link{cleanup_files}},
79-
#' \code{\link{get_slurm_out}} and \code{\link{print_job_status}}
85+
#' \code{\link{get_slurm_out}} and \code{\link{get_job_status}}
8086
#' which use the output of this function.
8187
#' @examples
8288
#' \dontrun{
8389
#' sjob <- slurm_apply(func, pars)
84-
#' print_job_status(sjob) # Prints console/error output once job is completed.
90+
#' get_job_status(sjob) # Prints console/error output once job is completed.
8591
#' func_result <- get_slurm_out(sjob, "table") # Loads output data into R.
8692
#' cleanup_files(sjob)
8793
#' }
8894
#' @export
89-
slurm_apply <- function(f, params, jobname = NA, nodes = 2, cpus_per_node = 2,
95+
slurm_apply <- function(f, params, jobname = NA,
96+
nodes = 2, cpus_per_node = 2, preschedule_cores = TRUE,
9097
add_objects = NULL, pkgs = rev(.packages()), libPaths = NULL,
9198
rscript_path = NULL, r_template = NULL, sh_template = NULL,
9299
slurm_options = list(), submit = TRUE) {
@@ -146,6 +153,7 @@ slurm_apply <- function(f, params, jobname = NA, nodes = 2, cpus_per_node = 2,
146153
add_obj = !is.null(add_objects),
147154
nchunk = nchunk,
148155
cpus_per_node = cpus_per_node,
156+
preschedule_cores = preschedule_cores,
149157
libPaths = libPaths))
150158
writeLines(script_r, file.path(tmpdir, "slurm_run.R"))
151159

R/slurm_call.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
#' @seealso \code{\link{slurm_apply}} to parallelize a function over a parameter
6464
#' set.
6565
#' @seealso \code{\link{cancel_slurm}}, \code{\link{cleanup_files}},
66-
#' \code{\link{get_slurm_out}} and \code{\link{print_job_status}} which use
66+
#' \code{\link{get_slurm_out}} and \code{\link{get_job_status}} which use
6767
#' the output of this function.
6868
#' @export
6969
slurm_call <- function(f, params, jobname = NA, add_objects = NULL,

R/slurm_job.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#'
33
#' This function creates a \code{slurm_job} object which can be passed to other
44
#' functions such as \code{\link{cancel_slurm}}, \code{\link{cleanup_files}},
5-
#' \code{\link{get_slurm_out}} and \code{\link{print_job_status}}.
5+
#' \code{\link{get_slurm_out}} and \code{\link{get_job_status}}.
66
#'
77
#' In general, \code{slurm_job} objects are created automatically as the output of
88
#' \code{\link{slurm_apply}} or \code{\link{slurm_call}}, but it may be necessary

README.Rmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ knitr::opts_chunk$set(
2727

2828
Development of this R package was supported by the National Socio-Environmental Synthesis Center (SESYNC) under funding received from the National Science Foundation grants DBI-1052875 and DBI-1639145.
2929

30-
The package was developed by Philippe Marchand (current maintainer), with Ian Carroll and Mike Smorul contributing.
30+
The package was developed by Philippe Marchand, with Ian Carroll and Mike Smorul contributing. Quentin Read is the current maintainer.
3131

3232

3333
### Installation

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ Development of this R package was supported by the National
2424
Socio-Environmental Synthesis Center (SESYNC) under funding received
2525
from the National Science Foundation grants DBI-1052875 and DBI-1639145.
2626

27-
The package was developed by Philippe Marchand (current maintainer),
28-
with Ian Carroll and Mike Smorul contributing.
27+
The package was developed by Philippe Marchand, with Ian Carroll and
28+
Mike Smorul contributing. Quentin Read is the current maintainer.
2929

3030
### Installation
3131

_rslurm_test_apply/f.RDS

-1.29 KB
Binary file not shown.

_rslurm_test_apply/params.RDS

-214 Bytes
Binary file not shown.

_rslurm_test_apply/slurm_run.R

Lines changed: 0 additions & 22 deletions
This file was deleted.

_rslurm_test_apply/submit.sh

Lines changed: 0 additions & 6 deletions
This file was deleted.

inst/templates/slurm_run_R.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ load('add_objects.RData')
1616
FUN = .rslurm_func,
1717
.rslurm_params[.rslurm_istart:.rslurm_iend, , drop = FALSE],
1818
mc.cores = {{{cpus_per_node}}},
19+
mc.preschedule = {{{preschedule_cores}}},
1920
SIMPLIFY = FALSE))
2021

2122
saveRDS(.rslurm_result, file = paste0('results_', .rslurm_id, '.RDS'))

0 commit comments

Comments
 (0)