-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.R
50 lines (39 loc) · 1.67 KB
/
run.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
run_HPC <- function(scenarios, experiment, om, NTASKS)
{
file.copy(paste0(om$path, "/densities.csv"), paste0(experiment, "/"))
file.copy(paste0(om$path, "/scenario_", om$version, ".xsd"), paste0(experiment, "/"))
commands = list()
for(scenario in scenarios)
{
index = scenario$index
outputfile = paste0("txt/", scenario$index, ".txt")
command = paste0(om$exe, " -s xml/", index, ".xml --output ", outputfile)
full_command = paste0("export PATH=$PATH:", om$path, " && ", command)
commands = append(commands, full_command)
}
writeLines(as.character(commands), paste0(experiment, "/commands.txt"))
n = length(scenarios)
NTASKS = min(n, NTASKS)
script = readLines("job.sh")
script = gsub(pattern = "@NTASKS@", replace = NTASKS, x = script)
writeLines(script, con=paste0(experiment, "/start_array_job.sh"))
system(paste0("cd ", experiment, " && sbatch --wait start_array_job.sh"))
}
run_local <- function(scenarios, experiment, om)
{
n = length(scenarios)
n_cores = detectCores() - 1
registerDoParallel(n_cores)
cluster = makeCluster(n_cores, type="FORK")
registerDoParallel(cluster)
foreach(i=1:n, .combine = 'c') %do% {
scenario = scenarios[[i]]
index = scenario$index
outputfile = paste0("txt/", scenario$index, ".txt")
command = paste0("openMalaria -s xml/", index, ".xml --output ", outputfile)
full_command = paste0("export PATH=$PATH:", om$path, " && cd ", experiment, " && ", command)
system(full_command, ignore.stdout = TRUE, ignore.stderr = TRUE)
NULL
}
stopCluster(cluster)
}