Skip to content

Commit

Permalink
Allow providing additional SLURM parameters via cfg$slurmConfig. Para…
Browse files Browse the repository at this point in the history
…meters that are later provided interactively via start.R overwrite the cfg values. Closing #139
  • Loading branch information
dklein-pik committed Apr 23, 2020
1 parent c5bd375 commit b69f943
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
41 changes: 41 additions & 0 deletions scripts/start/choose_slurmConfig.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
4 changes: 2 additions & 2 deletions start.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit b69f943

Please sign in to comment.