-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsim-local.R
39 lines (35 loc) · 1.21 KB
/
sim-local.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
#############################################################################
##
## Any local development requirements
##
## For example, this was required for C/C++ on MacOS
Sys.setenv(PKG_LIBS="-llapack")
#############################################################################
##
## A single line source that loads ones simulation code.
##
## Must export `simulation <- function(x)`
source("simulation.R")
#############################################################################
##
## For execution on local desktop/laptop
library(parallel) # Note: library is called parallel, when it's
# really batch array
nCores <- 8 # <=== Number of local cpus use to batch
# Windows can only use 1 core
fail <- try(mclapply(1, length, mc.cores = nCores), TRUE)
if(grepl('Windows', fail)) nCores <- 1
# Change the input
mclapply(12:13, # <=== MODIFY HERE Batch Array numbers to run locally
mc.cores = nCores,
function(x)
{
set.seed(x)
tryCatch(simulation(x), error = function(e)
{
print(sprintf('failure in iteration %d', x))
print(e)
NULL
})
}
)