Skip to content

Commit 538323c

Browse files
committed
Merge branch 'feature/windows-tbb' of github.com:RcppCore/RcppParallel into feature/windows-tbb
2 parents b0db51c + c059ff1 commit 538323c

File tree

4 files changed

+70
-18
lines changed

4 files changed

+70
-18
lines changed

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export(setThreadOptions)
22
export(defaultNumThreads)
3+
export(RcppParallelLibs)
34

R/build.R

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11

22

3+
# Output the LD flags for building against TBB. These flags are propagated
4+
# to sourceCpp via the inlineCxxPlugin (defined below) and to packages
5+
# via a line in Makevars.win like this:
6+
#
7+
# PKG_LIBS += $(shell "${R_HOME}/bin${R_ARCH_BIN}/Rscript.exe" -e "RcppParallel::LdFlags()")
8+
#
9+
# Note that this is only required for Windows builds (on Linux and OS X no
10+
# explicit link to TBB is required).
11+
RcppParallelLibs <- function() {
12+
cat(tbbLdFlags())
13+
}
314

4-
inlineCxxPlugin <- function() {
515

6-
# For sourceCpp on Windows we need to explicitly link against tbb.dll
7-
if (Sys.info()['sysname'] == "Windows") {
8-
tbb <- tbbLibPath()
9-
pkgLibs <- paste("-L", asBuildPath(dirname(tbb)),
10-
" -ltbb", sep="")
11-
env <- list(PKG_LIBS = pkgLibs)
12-
} else {
13-
env <- list()
14-
}
15-
16+
# Inline plugin used by sourceCpp to link to the TBB library
17+
inlineCxxPlugin <- function() {
1618
list(
17-
env = env,
19+
env = list(PKG_LIBS = tbbLdFlags()),
1820
includes = "#include <RcppParallel.h>",
1921
LinkingTo = "RcppParallel",
2022
body = function( x ) x,
@@ -23,6 +25,19 @@ inlineCxxPlugin <- function() {
2325
}
2426

2527

28+
# Return the linker flags requried for TBB on this platform
29+
tbbLdFlags <- function() {
30+
# on Windows we need to explicitly link against tbb.dll
31+
if (Sys.info()['sysname'] == "Windows") {
32+
tbb <- tbbLibPath()
33+
paste("-L", asBuildPath(dirname(tbb)), " -ltbb", sep="")
34+
} else {
35+
""
36+
}
37+
}
38+
39+
40+
# Determine the platform-specific path to the TBB library
2641
tbbLibPath <- function() {
2742
sysname <- Sys.info()['sysname']
2843
tbbSupported <- list(
@@ -41,14 +56,15 @@ tbbLibPath <- function() {
4156
}
4257
}
4358

59+
60+
# Helper function to ape the behavior of the R build system
61+
# when providing paths to libraries
4462
asBuildPath <- function(path) {
45-
4663
if (.Platform$OS.type == "windows") {
4764
path <- normalizePath(path)
4865
if (grepl(' ', path, fixed=TRUE))
4966
path <- utils::shortPathName(path)
5067
path <- gsub("\\\\", "/", path)
5168
}
52-
5369
return(path)
5470
}

README.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,25 @@ You can use the RcppParallel library from within a standalone C++ source file as
3535

3636
#### Packages
3737

38-
If you want to use RcppParallel from within an R package you add the following to your DESCRIPTION file:
38+
If you want to use RcppParallel from within an R package you add the following to your **DESCRIPTION** file:
3939

4040
```yaml
4141
Imports: RcppParallel
4242
LinkingTo: RcppParallel
4343
```
4444
45-
And the following to your NAMESPACE file:
45+
And the following to your **NAMESPACE** file:
4646
47-
```s
48-
import(RcppParallel)
47+
```R
48+
importFrom(RcppParallel, RcppParallelLibs)
49+
```
50+
51+
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:
53+
54+
```makefile
55+
PKG_LIBS += $(shell "${R_HOME}/bin${R_ARCH_BIN}/Rscript.exe" \
56+
-e "RcppParallel::RcppParallelLibs()")
4957
```
5058

5159
### License

man/RcppParallelLibs.Rd

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
\name{RcppParallelLibs}
2+
\alias{RcppParallelLibs}
3+
\alias{RcppParallelLibs}
4+
\title{
5+
Linker flags for RcppParallel
6+
}
7+
\description{
8+
Output the linker flags required to link to RcppParallel. On
9+
Windows this includes the underlying TBB library, on other
10+
platforms no linker flags are required.
11+
}
12+
\usage{
13+
RcppParallelLibs()
14+
}
15+
\details{
16+
This function is typically called from \code{Makevars.win} as follows:
17+
18+
\code{PKG_LIBS += $(shell "${R_HOME}/bin${R_ARCH_BIN}/Rscript.exe" -e "RcppParallel::RcppParallelLibs()")}
19+
20+
}
21+
22+
\value{
23+
Returns \code{NULL} invisibly. The function is not called for it's
24+
return value rather for the side effect of outputting the linker
25+
flags.
26+
}
27+

0 commit comments

Comments
 (0)