-
Notifications
You must be signed in to change notification settings - Fork 0
/
simulation.R
62 lines (51 loc) · 1.91 KB
/
simulation.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
51
52
53
54
55
56
57
58
59
60
61
62
###########################################################################
##
## This is the principal / source that starts the simulation
## This can call out and source any number of things.
##
## Our simulation will focus on adding it's design
## parameters together
##
## Array numbers in the slurm file, the design and this file are
## principal intended modification points
source('design.R') # Design from a consistent source
###########################################################################
##
## Load ones actual target simulation here
# source('the_real_work.R') # <==== MODIFY HERE to load the real work
# Silly example, DELETE for doing real work. Preferred to load from
# external R file for a real project
add_it_up <- function(design)
{
rnorm(1e6) # Chew up some CPU for demonstration
rowSums(design)
}
###########################################################################
##
## Create directories if they don't exist
if(!file.exists("output")) dir.create("output")
if(!file.exists("status")) dir.create("status")
###########################################################################
##
##
simulation <- function(array_task_id)
{
# For educational purposes, array job 12 will crash
# DELETE THIS, of course to do real work
if(array_task_id == 12) stop("SOMETHING WENT HORRIBLY WRONG!")
# Get the simulation design for this batch array
design <- simulation_design[array_task_id,]
# Add it up (this would be the actual simulation call for ones research)
result <- add_it_up(design) # <==== MODIFY HERE to call real work function
# Save the result
# Note: ACCRE accounts have limited storage space, some models save
# with the entire dataset. Some judicious selection of results might
# be in order.
save(result, file=file.path(
"output",
paste0("result-",
formatC(array_task_id, width=4, format='d', flag='0'),
".Rdata")
)
)
}