File: options.R

package info (click to toggle)
r-cran-rcppparallel 5.0.2%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 452 kB
  • sloc: cpp: 1,680; sh: 19; makefile: 2
file content (49 lines) | stat: -rw-r--r-- 1,232 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49

isUsingTbb <- function() {
   backend <- Sys.getenv("RCPP_PARALLEL_BACKEND", "tbb")
   identical(backend, "tbb")
}

setThreadOptions <- function(numThreads = "auto", stackSize = "auto") {
   
   # validate and resolve numThreads
   if (identical(numThreads, "auto"))
      numThreads <- -1L
   else if (!is.numeric(numThreads))
      stop("numThreads must be an integer")
   else
      numThreads <- as.integer(numThreads)
   
   # validate and resolve stackSize
   if (identical(stackSize, "auto"))
      stackSize <- 0L
   else if (!is.numeric(stackSize))
      stop("stackSize must be an integer")
   else
      stackSize <- as.integer(stackSize)
   
   # Call setThreadOptions if using tbb
   if (!is.null(dllInfo) && isUsingTbb())
      setTbbThreadOptions(numThreads, stackSize)
   
   if (numThreads == -1L)
      Sys.unsetenv("RCPP_PARALLEL_NUM_THREADS")
   else
      Sys.setenv(RCPP_PARALLEL_NUM_THREADS = numThreads)
}

setTbbThreadOptions <- function(numThreads, stackSize) {
   .Call(
      "setThreadOptions",
      as.integer(numThreads),
      as.integer(stackSize),
      PACKAGE = "RcppParallel"
   )
}

defaultNumThreads <- function() {
   .Call(
      "defaultNumThreads",
      PACKAGE = "RcppParallel"
   )
}