| set_num_threads | R Documentation |
OpenFHE parallelizes its core arithmetic with OpenMP and, by default,
uses every hardware thread the machine reports. set_num_threads()
sets the cap through OpenFHE's own thread controls, which every
parallel region in the library consults when it starts, so the change
takes effect immediately, on every platform, and regardless of which
thread the work runs on. It is a no-op when the package was built
without OpenMP.
set_num_threads(n)
n |
integer; the requested maximum number of threads (at least 1). |
Requests above the number of threads available when the library was
loaded (the hardware count, or OMP_NUM_THREADS if that was set
before R started) are reduced to that number. The value in effect is
returned, so a reduced request is visible to the caller;
get_num_threads() reports the same value later.
The package default is uncapped, so interactive users get full
parallelism. Under R CMD check, which sets _R_CHECK_LIMIT_CORES_,
the package caps itself at two threads when it is loaded, in line with
CRAN's two-thread policy. This also covers packages that depend on
'openfhe.R', which therefore need no thread handling of their own.
integer; the cap now in effect, invisibly.
get_num_threads()
old <- get_num_threads()
set_num_threads(2L)
set_num_threads(old)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.