comparison parallelSticsRRotation.R @ 0:ca96540c23cd draft

"planemo upload for repository https://forgemia.inra.fr/redelac"
author siwaa
date Thu, 08 Jun 2023 01:13:08 +0000
parents
children be10e3fb6e64
comparison
equal deleted inserted replaced
-1:000000000000 0:ca96540c23cd
1 library(SticsRFiles)
2 library(SticsOnR)
3 library(parallel)
4 library(doParallel)
5 library(readxl)
6
7 workspace <- paste0(getwd(), "/WS")
8 javastics_path <- getwd()
9 default_config_path <- paste0(javastics_path, "/config")
10
11 # copy of the var.mod and rap.mod into the config folder
12 # generalizing maybe should be inside a config folder
13
14 #file.copy(from = file.path(workspace, "var.mod"),
15 # to = file.path(default_config_path, "var.mod"),
16 # overwrite = TRUE)
17 #file.copy(from = file.path(workspace, "rap.mod"),
18 # to = file.path(default_config_path, "rap.mod"),
19 # overwrite = TRUE)
20
21 txt_path <- paste0(getwd(), "/WS/txt_files")
22 #dir.create(txt_path,recursive = T)
23
24 #gen_usms_xml2txt(javastics = javastics_path,
25 # workspace = workspace,
26 # out_dir = txt_path,
27 # check = FALSE)
28
29 print("==================================")
30
31 print(paste0("Cores=", detectCores()))
32 print(paste0("javastics=", javastics_path))
33 print(paste0("ws=", workspace))
34 print(paste0("out_dir=", txt_path))
35
36 print("==================================")
37
38
39 # List of successive USMs
40 successive_usms_file <- ("successionPlan.csv")
41 successive_usms_tab <- read.csv(file = file.path(workspace, successive_usms_file), sep =";")
42
43 no_cores <- detectCores() - 1
44 cl <- makeCluster(no_cores)
45 registerDoParallel(cl)
46
47 result <- foreach(i=1:nrow(successive_usms_tab),
48 .packages = c("SticsRFiles", "SticsOnR") ) %dopar% {
49
50
51 print(paste("coucou ", i))
52 nusms <- as.numeric(successive_usms_tab[i,2])
53 print(paste0("coco ", nusms))
54
55 vec <- as.character(successive_usms_tab[i,c(3:(2+nusms))])
56
57 list_successive_usms <- list(vec)
58
59 sim_options <- stics_wrapper_options(javastics = javastics_path,
60 stics_exe = paste0(javastics_path,"/bin/stics_modulo"),
61 workspace = txt_path,
62 verbose = TRUE,
63 successive = list_successive_usms)
64 list_usms <- vec
65
66 stics_wrapper(model_options = sim_options, situation = list_usms)
67 }
68
69 stopCluster(cl)
70
71 for (i in 1:nrow(successive_usms_tab)) { #i=1
72 if (i == 1) {
73 simPCP <- result[[i]]
74 } else {
75 simPCP$sim_list <- c(simPCP$sim_list, result[[i]]$sim_list)
76 }
77
78 }
79
80 save(simPCP, file = "results.RData")