Skip to content

Commit 6404681

Browse files
committed
tweaks for TBB auto-detection and handling
1 parent ac488f6 commit 6404681

File tree

11 files changed

+112
-51
lines changed

11 files changed

+112
-51
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ revdep
1111
src-i386
1212
src-x64
1313
tbb.log
14+
15+
R/tbb-autodetected.R

R/aaa.R

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
# stubs that get overridden via configure script
3+
TBB_LIB <- ""
4+
TBB_INC <- ""

R/tbb-autodetected.R.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
TBB_LIB <- "@TBB_LIB@"
3+
TBB_INC <- "@TBB_INC@"

R/tbb.R

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ tbbCxxFlags <- function() {
5353
flags <- c(flags, "-DRCPP_PARALLEL_USE_TBB=1")
5454

5555
# if TBB_INC is set, apply those library paths
56-
tbbInc <- Sys.getenv("TBB_INC", unset = NA)
57-
if (!is.na(tbbInc)) {
56+
tbbInc <- Sys.getenv("TBB_INC", unset = TBB_INC)
57+
if (nzchar(tbbInc)) {
5858

5959
# add include path
6060
flags <- c(flags, paste0("-I", asBuildPath(tbbInc)))
@@ -75,8 +75,8 @@ tbbCxxFlags <- function() {
7575
tbbLdFlags <- function() {
7676

7777
# shortcut if TBB_LIB defined
78-
tbbLib <- Sys.getenv("TBB_LIB", unset = NA)
79-
if (!is.na(tbbLib)) {
78+
tbbLib <- Sys.getenv("TBB_LIB", unset = TBB_LIB)
79+
if (nzchar(tbbLib)) {
8080
fmt <- "-L%1$s -Wl,-rpath,%1$s -ltbb -ltbbmalloc"
8181
return(sprintf(fmt, asBuildPath(tbbLib)))
8282
}
@@ -96,8 +96,8 @@ tbbLdFlags <- function() {
9696

9797
tbbRoot <- function() {
9898

99-
# TODO: rstan
100-
# parts <- c("libs", if (nzchar(rArch)) rArch, "tbb")
99+
if (nzchar(TBB_LIB))
100+
return(TBB_LIB)
101101

102102
rArch <- .Platform$r_arch
103103
parts <- c("lib", if (nzchar(rArch)) rArch)

inst/include/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

22
# These TBB libraries are copied in at configure time.
33
/index.html
4+
/oneapi
45
/serial
56
/tbb
67

inst/tests/runit.distance.R

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11

2+
library(Rcpp)
3+
library(RUnit)
4+
25
sourceCpp(system.file("tests/cpp/distance.cpp", package = "RcppParallel"))
36

47
test.distance <- function() {
58

6-
n = 1000
7-
m = matrix(runif(n*10), ncol = 10)
8-
m = m/rowSums(m)
9+
n <- 1000
10+
m <- matrix(runif(n*10), ncol = 10)
11+
m <- m/rowSums(m)
912

1013
checkEquals(
1114
rcpp_js_distance(m),
1215
rcpp_parallel_js_distance(m)
1316
)
17+
1418
}

inst/tests/runit.innerproduct.R

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11

2+
library(Rcpp)
3+
library(RUnit)
4+
25
sourceCpp(system.file("tests/cpp/innerproduct.cpp", package = "RcppParallel"))
36

47
test.innerproduct <- function() {
@@ -10,4 +13,5 @@ test.innerproduct <- function() {
1013
innerProduct(x, y),
1114
parallelInnerProduct(x, y)
1215
)
16+
1317
}

inst/tests/runit.sum.R

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11

2+
library(Rcpp)
3+
library(RUnit)
4+
25
sourceCpp(system.file("tests/cpp/sum.cpp", package = "RcppParallel"))
36

47
test.sum <- function() {

inst/tests/runit.transform.R

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11

2+
library(Rcpp)
3+
library(RUnit)
4+
25
sourceCpp(system.file("tests/cpp/transform.cpp", package = "RcppParallel"))
36

47
test.transform <- function() {

src/Makevars.in

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,17 @@
11

22
PKG_CXXFLAGS = @CXX11STD@
33

4-
# If TBB_ROOT is defined, use it.
5-
ifdef TBB_ROOT
6-
7-
ifndef TBB_LIB
8-
TBB_LIB = $(TBB_ROOT)/lib
9-
endif
10-
11-
ifndef TBB_INC
12-
TBB_INC = $(TBB_ROOT)/include
13-
endif
14-
15-
endif
16-
17-
# If TBB_LIB is not defined, try to use autodetection
18-
ifndef TBB_LIB
19-
TBB_LIB = @TBB_LIB_AUTO@
20-
TBB_INC = @TBB_INC_AUTO@
21-
endif
22-
23-
# If TBB_LIB is defined but TBB_INC is not, make a guess.
24-
ifdef TBB_LIB
25-
ifndef TBB_INC
26-
TBB_INC = $(TBB_LIB)/../include
27-
endif
28-
endif
4+
TBB_LIB = @TBB_LIB@
5+
TBB_INC = @TBB_INC@
296

7+
# If TBB_INC is defined, include those library paths.
308
ifdef TBB_INC
319
PKG_CPPFLAGS = -I../inst/include -I$(TBB_INC)
3210
else
3311
PKG_CPPFLAGS = -I../inst/include
3412
endif
3513

14+
# If TBB_LIB is defined, link to that explicitly.
3615
ifdef TBB_LIB
3716
PKG_LIBS = -Wl,-L,"$(TBB_LIB)" -Wl,-rpath,"$(TBB_LIB)" -ltbb -ltbbmalloc
3817
endif

0 commit comments

Comments
 (0)