Skip to contents

charr_threads() sets how many threads charr's "altrep" backend may use for the operations that have a data-parallel shape. Operations without that shape, and the "base" and "reference" backends, always run on one thread.

Usage

charr_threads(value = NULL)

Arguments

value

NULL to query the current count, or a positive whole number of threads. parallel::detectCores() is the usual source of an upper bound.

Value

The current count when querying. When setting, the previous count is returned invisibly.

Details

An eligible operation uses the requested count, capped by its number of tasks and an internal safety limit of 256. Charr does not apply an input-size heuristic, so even a small eligible input starts workers when the count is greater than one. A few modes must stay serial because their results depend on the order in which elements run.

The count defaults to 1, so charr is single-threaded until asked otherwise. It is held in native code rather than in an R option, because threading happens only in native code. This accessor is the only way to change it: setting an option named charr_threads has no effect.

Examples

old <- charr_threads(2)
charr_threads()
#> [1] 2
charr_threads(old)