Skip to content

Commit

Permalink
Merge pull request #4 from SESYNC-ci/extensions
Browse files Browse the repository at this point in the history
Now on CRAN.
  • Loading branch information
itcarroll authored Apr 9, 2017
2 parents 19f5e71 + ac1a3a1 commit 6560de4
Show file tree
Hide file tree
Showing 26 changed files with 758 additions and 448 deletions.
3 changes: 2 additions & 1 deletion .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
^.*\.Rproj$
^\.Rproj\.user$
^\.travis\.yml$
cran-comments.md
^cran-comments\.md
^release\.R
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
.Rproj.user
.Rhistory
.RData
inst/doc
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
language: r
warnings_are_errors: true
sudo: required
r_build_args: "--no-build-vignettes"
r_check_args: "--no-vignettes --as-cran"

env:
global:
Expand Down
11 changes: 6 additions & 5 deletions DESCRIPTION
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
Package: rslurm
Type: Package
Title: Submit R Calculations to a 'SLURM' Cluster
Description: Functions that simplify the R interface the 'SLURM' cluster workload
manager, and automate the process of dividing a parallel calculation across
cluster nodes.
Version: 0.3.2
Description: Functions that simplify submitting R scripts to a 'SLURM' cluster
workload manager, in part by automating the division of embarrassingly parallel
calculations across cluster nodes.
Version: 0.3.3
License: GPL-3
URL: https://github.com/SESYNC-ci/rslurm
BugReports: https://github.com/SESYNC-ci/rslurm/issues
Expand All @@ -18,7 +18,8 @@ Imports:
parallel,
whisker (>= 0.3)
RoxygenNote: 6.0.1
Suggests: testthat,
Suggests:
testthat,
knitr,
rmarkdown
VignetteBuilder: knitr
109 changes: 0 additions & 109 deletions NEWS.md

This file was deleted.

10 changes: 7 additions & 3 deletions R/get_slurm_out.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
get_slurm_out <- function(slr_job, outtype = "raw", wait = TRUE) {

# Check arguments
if (!(class(slr_job) == "slurm_job")) stop("slr_job must be a slurm_job")
if (!(class(slr_job) == "slurm_job")) {
stop("slr_job must be a slurm_job")
}
outtypes <- c("table", "raw")
if (!(outtype %in% outtypes)) {
stop(paste("outtype should be one of:", paste(outtypes, collapse = ', ')))
Expand All @@ -37,9 +39,11 @@ get_slurm_out <- function(slr_job, outtype = "raw", wait = TRUE) {
}

# Wait for slr_job using SLURM dependency
if (wait) wait_for_job(slr_job)
if (wait) {
wait_for_job(slr_job)
}

res_files <- paste0("results_", 0:(slr_job$nodes - 1), ".RData")
res_files <- paste0("results_", 0:(slr_job$nodes - 1), ".RDS")
tmpdir <- paste0("_rslurm_", slr_job$jobname)
missing_files <- setdiff(res_files, dir(path = tmpdir))
if (length(missing_files) > 0) {
Expand Down
16 changes: 6 additions & 10 deletions R/rslurm.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
#' rslurm: Submit R calculations to a SLURM cluster
#'
#' This package automates the process of sending simple function calls or
#' parallel calculations to a cluster using the SLURM workload manager.
#'
#' @section Overview:
#' This package includes two core functions used to send computations to a
#' SLURM cluster. While \code{\link{slurm_call}} executes a function using a
Expand All @@ -19,7 +14,7 @@
#' \code{\link{get_slurm_out}} and \code{\link{cleanup_files}}.
#'
#' For bug reports or questions about this package, contact
#' Philippe Marchand (pmarchand@@sesync.org).
#' Ian Carroll(icarroll@sesync.org).
#'
#' @section Function Specification:
#' To be compatible with \code{\link{slurm_apply}}, a function may accept
Expand Down Expand Up @@ -65,9 +60,10 @@
#' cleanup_files(sjob1)
#' }
#'
#' @docType package
#' @name rslurm-package
#' @aliases rslurm
#' @section Acknowledgement:
#' Development of this R package was supported by the National
#' Socio-Environmental Synthesis Center (SESYNC) under funding received
#' from the National Science Foundation DBI-1052875.
#'
#' @importFrom utils capture.output
NULL
"_PACKAGE"
14 changes: 9 additions & 5 deletions R/slurm_apply.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#' parameters in parallel, spread across multiple nodes of a SLURM cluster.
#'
#' This function creates a temporary folder ("_rslurm_[jobname]") in the current
#' directory, holding the .RData files, the R script and the Bash submission
#' script generated for the SLURM job.
#' directory, holding .RData and .RDS data files, the R script to run and the Bash
#' submission script generated for the SLURM job.
#'
#' The set of input parameters is divided in equal chunks sent to each node, and
#' \code{f} is evaluated in parallel within each node using functions from the
Expand All @@ -23,7 +23,7 @@
#'
#' When processing the computation job, the SLURM cluster will output two types
#' of files in the temporary folder: those containing the return values of the
#' function for each subset of parameters ("results_[node_id].RData") and those
#' function for each subset of parameters ("results_[node_id].RDS") and those
#' containing any console or error output produced by R on each node
#' ("slurm_[node_id].out").
#'
Expand Down Expand Up @@ -100,9 +100,9 @@ slurm_apply <- function(f, params, jobname = NA, nodes = 2, cpus_per_node = 2,

# Create temp folder
tmpdir <- paste0("_rslurm_", jobname)
dir.create(tmpdir)
dir.create(tmpdir, showWarnings = FALSE)

saveRDS(params, file = file.path(tmpdir, "params.RData"))
saveRDS(params, file = file.path(tmpdir, "params.RDS"))
if (!is.null(add_objects)) {
save(list = add_objects, file = file.path(tmpdir, "add_objects.RData"))
}
Expand Down Expand Up @@ -142,6 +142,10 @@ slurm_apply <- function(f, params, jobname = NA, nodes = 2, cpus_per_node = 2,
writeLines(script_sh, file.path(tmpdir, "submit.sh"))

# Submit job to SLURM if applicable
if (submit && system('squeue', ignore.stdout = TRUE)) {
submit <- FALSE
cat("Cannot submit; no SLURM workload manager on path\n")
}
if (submit) {
jobid <- submit_slurm_job(tmpdir)
} else {
Expand Down
14 changes: 9 additions & 5 deletions R/slurm_call.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#' cluster.
#'
#' This function creates a temporary folder ("_rslurm_[jobname]") in the current
#' directory, holding the .RData files, the R script and the Bash submission
#' script generated for the SLURM job.
#' directory, holding .RData and .RDS data files, the R script to run and the Bash
#' submission script generated for the SLURM job.
#'
#' The names of any other R objects (besides \code{params}) that \code{f} needs
#' to access should be listed in the \code{add_objects} argument.
Expand All @@ -20,7 +20,7 @@
#'
#' When processing the computation job, the SLURM cluster will output two files
#' in the temporary folder: one with the return value of the function
#' ("results_0.RData") and one containing any console or error output produced
#' ("results_0.RDS") and one containing any console or error output produced
#' by R ("slurm_[node_id].out").
#'
#' If \code{submit = TRUE}, the job is sent to the cluster and a confirmation
Expand Down Expand Up @@ -74,9 +74,9 @@ slurm_call <- function(f, params, jobname = NA, add_objects = NULL,

# Create temp folder
tmpdir <- paste0("_rslurm_", jobname)
dir.create(tmpdir)
dir.create(tmpdir, showWarnings = FALSE)

saveRDS(params, file = file.path(tmpdir, "params.RData"))
saveRDS(params, file = file.path(tmpdir, "params.RDS"))
if (!is.null(add_objects)) {
save(list = add_objects, file = file.path(tmpdir, "add_objects.RData"))
}
Expand All @@ -103,6 +103,10 @@ slurm_call <- function(f, params, jobname = NA, add_objects = NULL,
writeLines(script_sh, file.path(tmpdir, "submit.sh"))

# Submit job to SLURM if applicable
if (system('squeue', ignore.stdout = TRUE)) {
submit <- FALSE
cat("Cannot submit; no SLURM workload manager on path\n")
}
if (submit) {
jobid <- submit_slurm_job(tmpdir)
} else {
Expand Down
5 changes: 1 addition & 4 deletions R/slurm_job.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@
#' @return A \code{slurm_job} object.
#' @export
slurm_job <- function(jobname, nodes, jobid) {
slr_job <- list(jobname = jobname, nodes = nodes)
if (!missing(jobid)) {
slr_job$jobid <- as.integer(jobid)
}
slr_job <- list(jobname = jobname, nodes = nodes, jobid = jobid)
class(slr_job) <- "slurm_job"
slr_job
}
5 changes: 4 additions & 1 deletion R/slurm_utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ func_to_str <- function(f) {
}


# Make jobname by cleaning user-provided name or (if NA) generate one from clock
# Make jobname by cleaning user-provided name or (if NA) generate one
# from base::tempfile
make_jobname <- function(name) {
if (is.na(name)) {
tmpfile <- tempfile("_rslurm_", tmpdir=".")
Expand Down Expand Up @@ -47,7 +48,9 @@ local_slurm_array <- function(slr_job) {
"Sys.setenv(SLURM_ARRAY_TASK_ID = i)",
"source('slurm_run.R')", "}"), "local_run.R")
system(paste(rscript_path, "--vanilla local_run.R"))
slr_job$jobid = 0L
}, finally = setwd(olddir))
return(slr_job)
}

# Submit job capturing jobid
Expand Down
Loading

0 comments on commit 6560de4

Please sign in to comment.