From 9b510e4b84b96e16cbc91a2a38ed0eaf2d53eda0 Mon Sep 17 00:00:00 2001 From: dklein <dklein@pik-potsdam.de> Date: Tue, 18 Feb 2020 16:33:37 +0100 Subject: [PATCH] Added file for choosing the slurm config --- scripts/utils/choose_slurmConfig.R | 45 ++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 scripts/utils/choose_slurmConfig.R diff --git a/scripts/utils/choose_slurmConfig.R b/scripts/utils/choose_slurmConfig.R new file mode 100644 index 0000000..f121607 --- /dev/null +++ b/scripts/utils/choose_slurmConfig.R @@ -0,0 +1,45 @@ +####################################################################### +############### Select slurm partitiion ############################### +####################################################################### + +get_line <- function(){ + # gets characters (line) from the terminal or from a connection + # and returns it + if(interactive()){ + s <- readline() + } else { + con <- file("stdin") + s <- readLines(con, 1, warn=FALSE) + on.exit(close(con)) + } + return(s); +} + +choose_slurmConfig <- function() { + + slurm <- suppressWarnings(ifelse(system2("srun",stdout=FALSE,stderr=FALSE) != 127, TRUE, FALSE)) + if (slurm) { + modes <- c(" SLURM standby ", + " SLURM priority" + ) + + cat("\nCurrent cluster utilization:\n") + system("sclass") + cat("\n") + + cat("\nPlease choose run submission type:\n") + cat(paste(1:length(modes), modes, sep=": " ),sep="\n") + cat("Number: ") + identifier <- get_line() + identifier <- as.numeric(strsplit(identifier,",")[[1]]) + comp <- switch(identifier, + "1" = "--qos=standby --nodes=1 --tasks-per-node=1" , + "2" = "--qos=priority --nodes=1 --tasks-per-node=1" ) + + if(is.null(comp)) stop("This type is invalid. Please choose a valid type") + } else { + comp <- "direct" + } + + return(comp) +} -- GitLab