parallelism: Parallelism

parallelismR Documentation

Parallelism

Description

Work is parallelised in one of two ways, according to what is being run.

Usage

parallelBackend()

canFork()

resolveThreads(threads = NULL)

Arguments

threads

A thread count, or NULL to consult getOption("imply.threads"). Leaving both unset runs serially.

Details

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.

Value

parallelBackend() returns "libdispatch", "openmp" or "none". canFork() reports whether R functions can be run in parallel.


imply documentation built on Sept. 15, 2026, 5:09 p.m.