Skip to content

Commit 6d52c6d

Browse files
committed
don't set tbb thread options when disabled
1 parent 3e11a1f commit 6d52c6d

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

R/options.R

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11

2+
isUsingTbb <- function() {
3+
backend <- Sys.getenv("RCPP_PARALLEL_BACKEND", "tbb")
4+
identical(backend, "tbb")
5+
}
26

37
setThreadOptions <- function(numThreads = "auto", stackSize = "auto") {
48

@@ -19,18 +23,27 @@ setThreadOptions <- function(numThreads = "auto", stackSize = "auto") {
1923
stackSize <- as.integer(stackSize)
2024

2125
# Call setThreadOptions if using tbb
22-
if (!is.null(dllInfo)) {
23-
invisible(.Call("setThreadOptions", numThreads, stackSize,
24-
PACKAGE = "RcppParallel"))
25-
}
26+
if (!is.null(dllInfo) && isUsingTbb())
27+
setTbbThreadOptions(numThreads, stackSize)
2628

2729
if (numThreads == -1L)
2830
Sys.unsetenv("RCPP_PARALLEL_NUM_THREADS")
2931
else
3032
Sys.setenv(RCPP_PARALLEL_NUM_THREADS = numThreads)
3133
}
3234

33-
defaultNumThreads <- function() {
34-
.Call("defaultNumThreads", PACKAGE = "RcppParallel")
35+
setTbbThreadOptions <- function(numThreads, stackSize) {
36+
.Call(
37+
"setThreadOptions",
38+
as.integer(numThreads),
39+
as.integer(stackSize),
40+
PACKAGE = "RcppParallel"
41+
)
3542
}
3643

44+
defaultNumThreads <- function() {
45+
.Call(
46+
"defaultNumThreads",
47+
PACKAGE = "RcppParallel"
48+
)
49+
}

0 commit comments

Comments
 (0)