From b02e8efe6abf5bdef6861c21ad9bd6ab1fa1f67c Mon Sep 17 00:00:00 2001 From: janek Date: Wed, 13 Apr 2016 16:08:07 +0200 Subject: [PATCH 1/3] possibility to skip list lines for slurm and supply cluster name --- R/clusterFunctionsSLURM.R | 26 ++++++++++++++++++++++++-- man/makeClusterFunctionsSLURM.Rd | 10 +++++++++- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/R/clusterFunctionsSLURM.R b/R/clusterFunctionsSLURM.R index d3432f0..2ae8a7a 100644 --- a/R/clusterFunctionsSLURM.R +++ b/R/clusterFunctionsSLURM.R @@ -19,10 +19,23 @@ #' @template arg_template #' @template arg_list_jobs_cmd #' @template ret_cf +#' @param list.job.line.skip [\code{integer(1)}]\cr +#' Change how many lines of the job list should be skipped. Can be useful if \code{squeue} is giving +#' additional output. +#' @param cluster.name [\code{character(1)}]\cr +#' If an additional cluster name has to be specified for listing or deleting jobs it can be +#' supplied with this argument. it will be added as \code{--clusters=cluster.name} for SLURM. #' @family clusterFunctions #' @export -makeClusterFunctionsSLURM = function(template.file, list.jobs.cmd = c("squeue", "-h", "-o %i", "-u $USER")) { +makeClusterFunctionsSLURM = function(template.file, list.jobs.cmd = c("squeue", "-h", "-o %i", "-u $USER"), + list.job.line.skip = 0L, cluster.name) { + + if (!missing(cluster.name)) { + assertString(cluster.name) + list.jobs.cmd = append(list.jobs.cmd, paste0("--clusters=", cluster.name)) + } assertCharacter(list.jobs.cmd, min.len = 1L, any.missing = FALSE) + assertCount(list.job.line.skip) template = cfReadBrewTemplate(template.file) submitJob = function(conf, reg, job.name, rscript, log.file, job.dir, resources, arrayjobs) { @@ -45,12 +58,21 @@ makeClusterFunctionsSLURM = function(template.file, list.jobs.cmd = c("squeue", } killJob = function(conf, reg, batch.job.id) { - cfKillBatchJob("scancel", batch.job.id) + + killCmd = "scancel" + if (!missing(cluster.name)) { + killCmd = paste0(killCmd, " --clusters=", cluster.name) + } + cfKillBatchJob(killCmd, batch.job.id) } listJobs = function(conf, reg) { # Result is lines of fully quantified batch.job.ids jids = runOSCommandLinux(list.jobs.cmd[1L], list.jobs.cmd[-1L])$output + if (list.job.line.skip > 0) { + jids <- jids[-seq_len(list.job.line.skip)] + } + jids stri_extract_first_regex(jids, "[0-9]+") } diff --git a/man/makeClusterFunctionsSLURM.Rd b/man/makeClusterFunctionsSLURM.Rd index 62a6966..f09f1b3 100644 --- a/man/makeClusterFunctionsSLURM.Rd +++ b/man/makeClusterFunctionsSLURM.Rd @@ -5,7 +5,7 @@ \title{Create cluster functions for SLURM-based systems.} \usage{ makeClusterFunctionsSLURM(template.file, list.jobs.cmd = c("squeue", "-h", - "-o \%i", "-u $USER")) + "-o \%i", "-u $USER"), list.job.line.skip = 0L, cluster.name) } \arguments{ \item{template.file}{[\code{character(1)}]\cr @@ -15,6 +15,14 @@ Path to a brew template file that is used for the PBS job file.} Change default system command / options to list jobs. The first entry is the command, the following the options. See \code{\link[BBmisc]{system3}}.} + +\item{list.job.line.skip}{[\code{integer(1)}]\cr +Change how many lines of the job list should be skipped. Can be useful if \code{squeue} is giving +additional output.} + +\item{cluster.name}{[\code{character(1)}]\cr +If an additional cluster name has to be specified for listing or deleting jobs it can be +supplied with this argument. it will be added as \code{--clusters=cluster.name} for SLURM.} } \value{ [\code{\link{ClusterFunctions}}]. From 323eda5fae5b0936836adc32efea094e13c9d25c Mon Sep 17 00:00:00 2001 From: janek Date: Wed, 13 Apr 2016 16:33:34 +0200 Subject: [PATCH 2/3] fixed bug that jids was printed --- R/clusterFunctionsSLURM.R | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/R/clusterFunctionsSLURM.R b/R/clusterFunctionsSLURM.R index 2ae8a7a..9c0b29f 100644 --- a/R/clusterFunctionsSLURM.R +++ b/R/clusterFunctionsSLURM.R @@ -69,10 +69,9 @@ makeClusterFunctionsSLURM = function(template.file, list.jobs.cmd = c("squeue", listJobs = function(conf, reg) { # Result is lines of fully quantified batch.job.ids jids = runOSCommandLinux(list.jobs.cmd[1L], list.jobs.cmd[-1L])$output - if (list.job.line.skip > 0) { - jids <- jids[-seq_len(list.job.line.skip)] + if (list.job.line.skip > 0L) { + jids = jids[-seq_len(list.job.line.skip)] } - jids stri_extract_first_regex(jids, "[0-9]+") } From c2f94878b2d23b35f9a339ba50ce7b2f62cb4805 Mon Sep 17 00:00:00 2001 From: janek Date: Wed, 13 Apr 2016 18:04:40 +0200 Subject: [PATCH 3/3] killing jobs on LRZ works now --- R/clusterFunctionsSLURM.R | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/R/clusterFunctionsSLURM.R b/R/clusterFunctionsSLURM.R index 9c0b29f..dfafaa4 100644 --- a/R/clusterFunctionsSLURM.R +++ b/R/clusterFunctionsSLURM.R @@ -28,9 +28,9 @@ #' @family clusterFunctions #' @export makeClusterFunctionsSLURM = function(template.file, list.jobs.cmd = c("squeue", "-h", "-o %i", "-u $USER"), - list.job.line.skip = 0L, cluster.name) { + list.job.line.skip = 0L, cluster.name = NULL) { - if (!missing(cluster.name)) { + if (!is.null(cluster.name)) { assertString(cluster.name) list.jobs.cmd = append(list.jobs.cmd, paste0("--clusters=", cluster.name)) } @@ -58,17 +58,19 @@ makeClusterFunctionsSLURM = function(template.file, list.jobs.cmd = c("squeue", } killJob = function(conf, reg, batch.job.id) { + - killCmd = "scancel" - if (!missing(cluster.name)) { - killCmd = paste0(killCmd, " --clusters=", cluster.name) + if (!is.null(cluster.name)) { + cfKillBatchJob("scancel",paste0("--clusters=", cluster.name, " ", batch.job.id)) } - cfKillBatchJob(killCmd, batch.job.id) + cfKillBatchJob("scancel", batch.job.id) } listJobs = function(conf, reg) { # Result is lines of fully quantified batch.job.ids jids = runOSCommandLinux(list.jobs.cmd[1L], list.jobs.cmd[-1L])$output + # if squeue returns additional information (like cluster name), one or more + # lines can be omitted if (list.job.line.skip > 0L) { jids = jids[-seq_len(list.job.line.skip)] }