Mercurial > repos > siwaa > redelac_stics_s
diff redelacSticsSimulator.R @ 6:41f652e6616f draft
"planemo upload for repository https://forgemia.inra.fr/redelac/redelac-toolbox/-/tree/f8a7aebffe0c850bef03045efa3772aca6cd51c2/tools/REDELACSticsSimulator commit f8a7aebffe0c850bef03045efa3772aca6cd51c2-dirty"
author | siwaa |
---|---|
date | Tue, 26 Sep 2023 15:21:42 +0000 |
parents | 70ae7516e925 |
children | 2586f7dbcde1 |
line wrap: on
line diff
--- a/redelacSticsSimulator.R Mon Aug 21 15:47:50 2023 +0000 +++ b/redelacSticsSimulator.R Tue Sep 26 15:21:42 2023 +0000 @@ -4,35 +4,34 @@ library(doParallel) library(readxl) +sessionInfo() + workspace <- paste0(getwd(), "/WS") javastics_path <- getwd() default_config_path <- paste0(javastics_path, "/config") txt_path <- paste0(getwd(), "/WS/txt_files") -print("==================================") - -print(paste0("Cores=", detectCores())) -print(paste0("javastics=", javastics_path)) -print(paste0("ws=", workspace)) -print(paste0("out_dir=", txt_path)) - -print("==================================") - # List of successive USMs successive_usms_file <- ("successionPlan.csv") successive_usms_tab <- read.csv(file = file.path(workspace, successive_usms_file), sep =";") -#no_cores <- detectCores() - 1 -#no_cores <- 10 -#cl <- makeCluster(no_cores) -#registerDoParallel(cl) +args = commandArgs(trailingOnly = TRUE) + +parallel <- (args[1] == "parallel") +nbSlots <- as.integer(args[2]) -result <- list() +if (parallel) { + cl <- makeCluster(nbSlots) + print(cl) + registerDoParallel(cl) + `%dordopar%` <- `%dopar%` +} else { + `%dordopar%` <- `%do%` +} -#result <- foreach(i=1:nrow(successive_usms_tab), -# .packages = c("SticsRFiles", "SticsOnR") ) %dopar% { - for(i in 1:nrow(successive_usms_tab)) { +result <- foreach(i=1:nrow(successive_usms_tab), + .packages = c("foreach", "SticsRFiles", "SticsOnR") ) %dordopar% { nusms <- as.numeric(successive_usms_tab[i,2]) @@ -47,12 +46,11 @@ successive = list_successive_usms) list_usms <- vec - singleResult = stics_wrapper(model_options = sim_options, situation = list_usms) + return(stics_wrapper(model_options = sim_options, situation = list_usms)) - result = append(result, list(singleResult)) - } +} -#stopCluster(cl) +if (parallel) stopCluster(cl) for (i in 1:nrow(successive_usms_tab)) { #i=1 if (i == 1) {