Skip to content

Commit

Permalink
Allow user to disable core prescheduling in slurm_apply
Browse files Browse the repository at this point in the history
Passes argument to mcmapply() via template
Documentation updated
Also removed some extraneous test output from the repo
  • Loading branch information
qdread committed Nov 12, 2019
1 parent 4e537ab commit 816b40e
Show file tree
Hide file tree
Showing 13 changed files with 35 additions and 46 deletions.
14 changes: 11 additions & 3 deletions R/slurm_apply.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@
#' @param cpus_per_node The number of CPUs requested per node, i.e., how many
#' processes to run in parallel per node. This argument is mapped to the
#' Slurm parameter \code{cpus-per-task}.
#' @param preschedule_cores Corresponds to the \code{mc.preschedule} argument of
#' \code{parallel::mcmapply}. Defaults to \code{TRUE}. If \code{TRUE}, the
#' jobs are assigned to cores before computation. If \code{FALSE}, a new job is
#' created for each row of \code{params}. Setting \code{FALSE} may be faster if
#' different values of \code{params} result in very variable completion time for
#' jobs.
#' @param add_objects A character vector containing the name of R objects to be
#' saved in a .RData file and loaded on each cluster node prior to calling
#' \code{f}.
Expand All @@ -76,17 +82,18 @@
#' number of \code{nodes} effectively used.
#' @seealso \code{\link{slurm_call}} to evaluate a single function call.
#' @seealso \code{\link{cancel_slurm}}, \code{\link{cleanup_files}},
#' \code{\link{get_slurm_out}} and \code{\link{print_job_status}}
#' \code{\link{get_slurm_out}} and \code{\link{get_job_status}}
#' which use the output of this function.
#' @examples
#' \dontrun{
#' sjob <- slurm_apply(func, pars)
#' print_job_status(sjob) # Prints console/error output once job is completed.
#' get_job_status(sjob) # Prints console/error output once job is completed.
#' func_result <- get_slurm_out(sjob, "table") # Loads output data into R.
#' cleanup_files(sjob)
#' }
#' @export
slurm_apply <- function(f, params, jobname = NA, nodes = 2, cpus_per_node = 2,
slurm_apply <- function(f, params, jobname = NA,
nodes = 2, cpus_per_node = 2, preschedule_cores = TRUE,
add_objects = NULL, pkgs = rev(.packages()), libPaths = NULL,
rscript_path = NULL, r_template = NULL, sh_template = NULL,
slurm_options = list(), submit = TRUE) {
Expand Down Expand Up @@ -146,6 +153,7 @@ slurm_apply <- function(f, params, jobname = NA, nodes = 2, cpus_per_node = 2,
add_obj = !is.null(add_objects),
nchunk = nchunk,
cpus_per_node = cpus_per_node,
preschedule_cores = preschedule_cores,
libPaths = libPaths))
writeLines(script_r, file.path(tmpdir, "slurm_run.R"))

Expand Down
2 changes: 1 addition & 1 deletion R/slurm_call.R
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
#' @seealso \code{\link{slurm_apply}} to parallelize a function over a parameter
#' set.
#' @seealso \code{\link{cancel_slurm}}, \code{\link{cleanup_files}},
#' \code{\link{get_slurm_out}} and \code{\link{print_job_status}} which use
#' \code{\link{get_slurm_out}} and \code{\link{get_job_status}} which use
#' the output of this function.
#' @export
slurm_call <- function(f, params, jobname = NA, add_objects = NULL,
Expand Down
2 changes: 1 addition & 1 deletion R/slurm_job.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#'
#' This function creates a \code{slurm_job} object which can be passed to other
#' functions such as \code{\link{cancel_slurm}}, \code{\link{cleanup_files}},
#' \code{\link{get_slurm_out}} and \code{\link{print_job_status}}.
#' \code{\link{get_slurm_out}} and \code{\link{get_job_status}}.
#'
#' In general, \code{slurm_job} objects are created automatically as the output of
#' \code{\link{slurm_apply}} or \code{\link{slurm_call}}, but it may be necessary
Expand Down
2 changes: 1 addition & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ knitr::opts_chunk$set(

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.

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


### Installation
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ 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.

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

### Installation

Expand Down
Binary file removed _rslurm_test_apply/f.RDS
Binary file not shown.
Binary file removed _rslurm_test_apply/params.RDS
Binary file not shown.
22 changes: 0 additions & 22 deletions _rslurm_test_apply/slurm_run.R

This file was deleted.

6 changes: 0 additions & 6 deletions _rslurm_test_apply/submit.sh

This file was deleted.

1 change: 1 addition & 0 deletions inst/templates/slurm_run_R.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ load('add_objects.RData')
FUN = .rslurm_func,
.rslurm_params[.rslurm_istart:.rslurm_iend, , drop = FALSE],
mc.cores = {{{cpus_per_node}}},
mc.preschedule = {{{preschedule_cores}}},
SIMPLIFY = FALSE))

saveRDS(.rslurm_result, file = paste0('results_', .rslurm_id, '.RDS'))
18 changes: 13 additions & 5 deletions man/slurm_apply.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions man/slurm_call.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/slurm_job.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 816b40e

Please sign in to comment.