do_parallel {simmer.bricks} | R Documentation |
Perform Parallel Tasks
Description
This brick encapsulates the activity of n
workers running parallel
sub-trajectories.
Usage
do_parallel(.trj, ..., .env, wait = TRUE, mon_all = FALSE)
Arguments
.trj |
the trajectory object. |
... |
sub-trajectories or list of sub-trajectories to parallelise. |
.env |
the simulation environment. |
wait |
if |
mon_all |
if |
Value
Returns the following chain of activities: clone
> synchronize
(> wait
> untrap
if wait=FALSE
) (see examples below).
Examples
env <- simmer()
signal <- function() get_name(env)
task.1 <- trajectory("task 1") %>%
timeout(function() rexp(1))
task.2 <- trajectory("task 2") %>%
timeout(function() rexp(1))
## These are equivalent:
trajectory() %>%
do_parallel(
task.1,
task.2,
.env = env, wait = TRUE
)
trajectory() %>%
clone(
n = 3,
trajectory("original") %>%
trap(signal) %>%
wait() %>%
wait() %>%
untrap(signal),
task.1[] %>%
send(signal),
task.2[] %>%
send(signal)) %>%
synchronize(wait = TRUE)
## These are equivalent:
trajectory() %>%
do_parallel(
task.1,
task.2,
.env = env, wait = FALSE
)
trajectory() %>%
clone(
n = 3,
trajectory("original") %>%
trap(signal),
task.1[] %>%
send(signal),
task.2[] %>%
send(signal)) %>%
synchronize(wait = FALSE) %>%
wait() %>%
untrap(signal)
[Package simmer.bricks version 0.2.2 Index]