| safe_mclapply | R Documentation |
Drop-in replacement for parallel::mclapply that prevents deadlocks from
nested fork calls. Uses an R option (.DiceView_parallel_depth) inherited by forked
children to detect nesting and fall back to lapply in that case.
This avoids the classic pipe deadlock where a forked worker tries to fork grandchildren
while the parent is still waiting on pipes.
safe_mclapply(X, FUN, ..., mc.cores = getOption("mc.cores", maxWorkers()))
X |
a vector (atomic or list) |
FUN |
the function to be applied to each element of X |
... |
optional arguments to FUN |
mc.cores |
number of cores (default: |
list of results, like lapply
safe_mclapply(1:4, function(i) i^2)
# nested call falls back to lapply automatically:
outer <- safe_mclapply(1:2, function(i) safe_mclapply(1:3, function(j) i*j))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.