Skip to content

Commit 2394425

Browse files
committed
make TBB opt-in for packages on windows
1 parent 8c98d8b commit 2394425

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
lines changed

R/build.R

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ RcppParallelLibs <- function() {
1616
# Inline plugin used by sourceCpp to link to the TBB library
1717
inlineCxxPlugin <- function() {
1818
list(
19-
env = list(PKG_LIBS = tbbLdFlags()),
19+
env = list(
20+
PKG_CXXFLAGS = "-DRCPP_PARALLEL_USE_TBB=1",
21+
PKG_LIBS = tbbLdFlags()
22+
),
2023
includes = "#include <RcppParallel.h>",
2124
LinkingTo = "RcppParallel",
2225
body = function( x ) x,

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,12 @@ importFrom(RcppParallel, RcppParallelLibs)
4949
```
5050

5151
Finally, for Windows builds you'll need the following in **src\\Makevars.win**
52-
to ensure that your package can link against the TBB DLL:
52+
to ensure that your package can use TBB (if you don't do
53+
this the TinyThread fallback implementation will be used):
54+
55+
```make
56+
PKG_CXXFLAGS += -DRCPP_PARALLEL_USE_TBB=1
5357

54-
```makefile
5558
PKG_LIBS += $(shell "${R_HOME}/bin${R_ARCH_BIN}/Rscript.exe" \
5659
-e "RcppParallel::RcppParallelLibs()")
5760
```

inst/include/RcppParallel.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@
66
#include "RcppParallel/TinyThread.h"
77

88
// Use TBB only where it's known to compile and work correctly
9+
// (NOTE: Windows TBB is temporarily opt-in for packages for
10+
// compatibility with CRAN packages not previously configured
11+
// to link to TBB in Makevars.win)
912
#ifndef RCPP_PARALLEL_USE_TBB
10-
#if defined(_WIN32) || defined(__APPLE__) || defined(__gnu_linux__)
13+
#if defined(__APPLE__) || defined(__gnu_linux__)
1114
#define RCPP_PARALLEL_USE_TBB 1
1215
#include "RcppParallel/TBB.h"
1316
#else

src/options.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ extern "C" SEXP defaultNumThreads() {
4949

5050
#include <tthread/tinythread.h>
5151

52+
extern "C" SEXP setThreadOptions(SEXP numThreadsSEXP, SEXP stackSizeSEXP) {
53+
return R_NilValue;
54+
}
55+
5256
extern "C" SEXP defaultNumThreads() {
5357
SEXP threadsSEXP = Rf_allocVector(INTSXP, 1);
5458
INTEGER(threadsSEXP)[0] = tthread::thread::hardware_concurrency();

0 commit comments

Comments
 (0)