Skip to content
Snippets Groups Projects
Commit 74146c6f authored by David Klein's avatar David Klein
Browse files

Refactoring start scripts: adapt coupling scripts (get rid of *.cmd files by...

Refactoring start scripts: adapt coupling scripts (get rid of *.cmd files by creating the SLURM command on the fly)
parent a0ad851f
No related branches found
No related tags found
1 merge request!34Refactoring start scripts (yeah!)
...@@ -239,11 +239,6 @@ for(scen in common){ ...@@ -239,11 +239,6 @@ for(scen in common){
settings_remind[scen, "path_gdx_ref"] <- scenarios_coupled[scen, "path_gdx_ref"] settings_remind[scen, "path_gdx_ref"] <- scenarios_coupled[scen, "path_gdx_ref"]
cat("Replacing gdx_ref information with those specified in\n ",path_settings_coupled,"\n ",settings_remind[scen, "path_gdx_ref"],"\n") cat("Replacing gdx_ref information with those specified in\n ",path_settings_coupled,"\n ",settings_remind[scen, "path_gdx_ref"],"\n")
} }
if (!is.na(scenarios_coupled[scen, "path_gdx_opt"])) {
settings_remind[scen, "path_gdx_opt"] <- scenarios_coupled[scen, "path_gdx_opt"]
cat("Replacing gdx_opt information with those specified in\n ",path_settings_coupled,"\n ",settings_remind[scen, "path_gdx_opt"],"\n")
}
# Create list of previously defined paths to gdxs # Create list of previously defined paths to gdxs
gdxlist <- c(input.gdx = settings_remind[scen, "path_gdx"], # eventually this was updated if older runs exists in this folder (see above) gdxlist <- c(input.gdx = settings_remind[scen, "path_gdx"], # eventually this was updated if older runs exists in this folder (see above)
...@@ -255,7 +250,7 @@ for(scen in common){ ...@@ -255,7 +250,7 @@ for(scen in common){
# add information on subsequent runs to start after the current run is finished # add information on subsequent runs to start after the current run is finished
# take rownames (which is the runname) of that row, that has the current scenario in its gdx_ref # take rownames (which is the runname) of that row, that has the current scenario in its gdx_ref
cfg_rem$subsequentruns <- intersect(rownames(settings_remind[settings_remind$path_gdx_ref == scen & !is.na(settings_remind$path_gdx_ref),]),common) cfg_rem$subsequentruns <- intersect(rownames(settings_remind[settings_remind$path_gdx_ref == scen & !is.na(settings_remind$path_gdx_ref),]),common)
# immediately start run if it has a real gdx file (not a runname) given (last four letters are ".gdx") in path_gdx_ref or where this field is empty (NA) # immediately start run if it has a real gdx file (not a runname) given (last four letters are ".gdx") in path_gdx_ref or where this field is empty (NA)
start_now <- (substr(settings_remind[scen,"path_gdx_ref"], nchar(settings_remind[scen,"path_gdx_ref"])-3, nchar(settings_remind[scen,"path_gdx_ref"])) == ".gdx" start_now <- (substr(settings_remind[scen,"path_gdx_ref"], nchar(settings_remind[scen,"path_gdx_ref"])-3, nchar(settings_remind[scen,"path_gdx_ref"])) == ".gdx"
...@@ -300,22 +295,24 @@ for(scen in common){ ...@@ -300,22 +295,24 @@ for(scen in common){
# create cluster_start_coupled_scen.cmd file # create cluster_start_coupled_scen.cmd file
# 1. copy general cluster_start_coupled file # 1. copy general cluster_start_coupled file
system(paste0("cp cluster_start_coupled.cmd cluster_start_coupled_",scen,".cmd")) #system(paste0("cp cluster_start_coupled.cmd cluster_start_coupled_",scen,".cmd"))
# 2. modify accordingly # 2. modify accordingly
manipulateConfig(paste0("cluster_start_coupled_",scen,".cmd"),coupled_config=paste0(runname,".RData"),line_endings = "NOTwin") #manipulateConfig(paste0("cluster_start_coupled_",scen,".cmd"),coupled_config=paste0(runname,".RData"),line_endings = "NOTwin")
manipulateConfig(paste0("cluster_start_coupled_",scen,".cmd"),"--job-name"=runname,line_endings = "NOTwin") #manipulateConfig(paste0("cluster_start_coupled_",scen,".cmd"),"--job-name"=runname,line_endings = "NOTwin")
manipulateConfig(paste0("cluster_start_coupled_",scen,".cmd"),"--output"=paste0(runname,".log"),line_endings = "NOTwin") #manipulateConfig(paste0("cluster_start_coupled_",scen,".cmd"),"--output"=paste0(runname,".log"),line_endings = "NOTwin")
if (cfg_rem$gms$optimization == "nash" && cfg_rem$gms$cm_nash_mode == "parallel") { if (cfg_rem$gms$optimization == "nash" && cfg_rem$gms$cm_nash_mode == "parallel") {
# for nash: set the number of CPUs per node to number of regions + 1 # for nash: set the number of CPUs per node to number of regions + 1
nr_of_regions <- length(levels(read.csv2(cfg_rem$regionmapping)$RegionCode)) + 1 nr_of_regions <- length(levels(read.csv2(cfg_rem$regionmapping)$RegionCode)) + 1
manipulateConfig(paste0("cluster_start_coupled_",scen,".cmd"),"--tasks-per-node"=nr_of_regions,line_endings = "NOTwin") #manipulateConfig(paste0("cluster_start_coupled_",scen,".cmd"),"--tasks-per-node"=nr_of_regions,line_endings = "NOTwin")
} else { } else {
# for negishi: use only one CPU # for negishi: use only one CPU
manipulateConfig(paste0("cluster_start_coupled_",scen,".cmd"),"--tasks-per-node"=1,line_endings = "NOTwin") nr_of_regions <- 1
#manipulateConfig(paste0("cluster_start_coupled_",scen,".cmd"),"--tasks-per-node"=1,line_endings = "NOTwin")
} }
if (start_now){ if (start_now){
if (!exists("test")) system(paste0("sbatch cluster_start_coupled_",scen,".cmd")) #if (!exists("test")) system(paste0("sbatch cluster_start_coupled_",scen,".cmd"))
if (!exists("test")) system(paste0("sbatch --qos=standby --job-name=",runname," --output=",runname,".log --mail-type=END --comment=REMIND-MAgPIE --tasks-per-node=",nr_of_regions," --wrap=\"Rscript start_coupled.R \" coupled_config=",runname,".RData"))
else cat("Test mode: run NOT submitted to the cluster\n") else cat("Test mode: run NOT submitted to the cluster\n")
} else { } else {
cat(paste0("Run ",runname," will start after preceding run ",prefix_runname,settings_remind[scen,"path_gdx_ref"]," has finished\n")) cat(paste0("Run ",runname," will start after preceding run ",prefix_runname,settings_remind[scen,"path_gdx_ref"]," has finished\n"))
......
...@@ -201,10 +201,22 @@ start_coupled <- function(path_remind,path_magpie,cfg_rem,cfg_mag,runname,max_it ...@@ -201,10 +201,22 @@ start_coupled <- function(path_remind,path_magpie,cfg_rem,cfg_mag,runname,max_it
setwd(mainwd) setwd(mainwd)
cat(" to",getwd(),"\n") cat(" to",getwd(),"\n")
# for the sbatch command of the subsequent runs below set the number of tasks per node
# this not clean, because we use the number of regions of the *current* run to set the number of tasks for the *subsequent* runs
# but it is sufficiently clean, since the number of regions should not differ between current and subsequent
if (cfg_rem$gms$optimization == "nash" && cfg_rem$gms$cm_nash_mode == "parallel") {
# for nash: set the number of CPUs per node to number of regions + 1
nr_of_regions <- length(levels(read.csv2(cfg_rem$regionmapping)$RegionCode)) + 1
} else {
# for negishi: use only one CPU
nr_of_regions <- 1
}
#start subsequent runs via cmd scripts created at the end of start_bundle_coupled.R #start subsequent runs via cmd scripts created at the end of start_bundle_coupled.R
for(run in cfg_rem$subsequentruns){ for(run in cfg_rem$subsequentruns){
cat("Submitting subsequent run",run,"\n") cat("Submitting subsequent run",run,"\n")
system(paste0("sbatch cluster_start_coupled_",run,".cmd")) #system(paste0("sbatch cluster_start_coupled_",run,".cmd"))
system(paste0("sbatch --qos=standby --job-name=",run," --output=",run,".log --mail-type=END --comment=REMIND-MAgPIE --tasks-per-node=13",nr_of_regions," --wrap=\"Rscript start_coupled.R \" coupled_config=",run,".RData"))
} }
# Read runtime of ALL coupled runs (not just the current scenario) and produce comparison pdf # Read runtime of ALL coupled runs (not just the current scenario) and produce comparison pdf
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment