| parallelism | R Documentation |
Work is parallelised in one of two ways, according to what is being run.
parallelBackend()
canFork()
resolveThreads(threads = NULL)
threads |
A thread count, or |
Compiled kernels run concurrently in process, using Grand Central Dispatch
or OpenMP where one or other is available. Which of these was compiled in
is reported by parallelBackend().
An R function cannot be called from a worker thread, because R is single-threaded and its interpreter is not reentrant. Applying an R function is therefore parallelised by forking the R session instead, dividing the calls between workers. Forked workers share the image through copy-on-write, so nothing large is duplicated. Forking is unavailable on Windows, where such work runs serially; the alternative, a socket cluster, would copy the whole image to every worker and so defeat the purpose.
The number of threads may be given per call, or set globally with
options(imply.threads = n). Leaving both unset means serial, for compiled
kernels and R functions alike. Multi-core use is opt-in.
parallelBackend() returns "libdispatch", "openmp" or "none".
canFork() reports whether R functions can be run in parallel.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.