From b69f943c55bd0011288fb40994a2c0f1e0fb3b2a Mon Sep 17 00:00:00 2001 From: David Klein <dklein@pik-potsdam.de> Date: Thu, 23 Apr 2020 12:44:04 +0200 Subject: [PATCH] Allow providing additional SLURM parameters via cfg$slurmConfig. Parameters that are later provided interactively via start.R overwrite the cfg values. Closing #139 --- scripts/start/choose_slurmConfig.R | 41 ++++++++++++++++++++++++++++++ start.R | 4 +-- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/scripts/start/choose_slurmConfig.R b/scripts/start/choose_slurmConfig.R index d3db0cd..8bf3934 100644 --- a/scripts/start/choose_slurmConfig.R +++ b/scripts/start/choose_slurmConfig.R @@ -69,3 +69,44 @@ choose_slurmConfig <- function() { return(comp) } + +# combine_slurmconfig takes two strings with SLURM parameters (e.g. "--qos=priority --time=40000") +# and combines them into one sting of SLURM parameters overwriting the parameters in "original" +# if they also exist in "update_with". + +combine_slurmConfig <- function (original, update_with) { + + # trim whitespaces + original <- trimws(original) + update_with <- trimws(update_with) + + # remove double whitespaces + original <- gsub("\\s+"," ",original) + update_with <- gsub("\\s+"," ",update_with) + + # if user chose "direct" dont update any slurm commands + if(update_with == "direct") return(update_with) + + # ignore original if it is "direct" + if (original == "direct") original <- "" + + # put RHS strings into vector + v_update_with <- gsub("--.*=(.*)","\\1",unlist(strsplit(update_with,split=" "))) + # name the vector using LHS strings + names(v_update_with) <- gsub("--(.*)=.*","\\1",unlist(strsplit(update_with,split=" "))) + + # put RHS strings into vector + v_original <- gsub("--.*=(.*)","\\1",unlist(strsplit(original,split=" "))) + # name the vector using LHS strings + names(v_original) <- gsub("--(.*)=.*","\\1",unlist(strsplit(original,split=" "))) + + # remove elements from "original" that are existing in "update_with" + v_original <- v_original[!names(v_original) %in% "qos"] + + combined <- c(v_update_with,v_original) + + # concatenate SLURM command (insert "--" and "=") + res <- paste(paste0("--",names(combined),"=",combined),collapse = " ") + + return(res) +} diff --git a/start.R b/start.R index e295ce8..f8b44aa 100755 --- a/start.R +++ b/start.R @@ -196,7 +196,7 @@ if ('--restart' %in% argv) { for (outputdir in outputdirs) { cat("Restarting",outputdir,"\n") load(paste0("output/",outputdir,"/config.Rdata")) # read config.Rdata from results folder - cfg$slurmConfig <- slurmConfig # update the slurmConfig setting to what the user just chose (it was being ignored before) + cfg$slurmConfig <- combine_slurmConfig(cfg$slurmConfig,slurmConfig) # update the slurmConfig setting to what the user just chose (it was being ignored before) submit(cfg, restart = TRUE) #cat(paste0("output/",outputdir,"/config.Rdata"),"\n") } @@ -238,7 +238,7 @@ if ('--restart' %in% argv) { source("config/default.cfg") # Have the log output written in a file (not on the screen) - cfg$slurmConfig <- slurmConfig + cfg$slurmConfig <- combine_slurmConfig(cfg$slurmConfig,slurmConfig) cfg$logoption <- 2 start_now <- TRUE -- GitLab