Skip to content

Update TBB interface and allow using external lib #141

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 32 commits into from
Dec 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
1a679cd
Use system TBB and remove the embedded code
hsbadr Nov 17, 2020
6ff42cd
Update TBB functionality
hsbadr Nov 17, 2020
2eb99b6
tbb: Create lib directories anyway
hsbadr Nov 17, 2020
7c13d4e
Merge remote-tracking branch 'Rcpp/master' into develop
hsbadr Dec 5, 2020
dbd6ca6
tbb: Convert TBB_LIBRARY_FILE to canonical form
hsbadr Dec 12, 2020
73b076e
Load the package library only if TBB is found
hsbadr Dec 12, 2020
3621177
Fall back to building TBB from local source code
hsbadr Dec 12, 2020
9bba9bd
tbb: normalizePath only if file exists
hsbadr Dec 12, 2020
193b3b6
Fix Makevars.in
hsbadr Dec 12, 2020
f527e6a
tbb: Backward compatibility based on __TBB_tbb_stddef_H
hsbadr Dec 12, 2020
cb0b3f8
Fix URLs and use HTTPS
hsbadr Dec 12, 2020
d6347d2
Update package DESCRIPTION and bump version
hsbadr Dec 12, 2020
b2ae11b
Fix compilation for the new TBB interface
hsbadr Dec 12, 2020
e1b2cc4
tbbLibPath() uses the suffix argument
hsbadr Dec 12, 2020
8c3d280
Cleanup R/build.R
hsbadr Dec 12, 2020
bad7566
Resolved conflicts of TBB headers
hsbadr Dec 12, 2020
2cc8cbc
Update NEWS with increment package version
hsbadr Dec 12, 2020
1ce2854
DESCRIPTION: Add contributor
hsbadr Dec 12, 2020
e4915a2
Use TBB_INC & TBB_LIB and update CXXFLAGS
hsbadr Dec 13, 2020
6149954
Revert "Load the package library only if TBB is found"
hsbadr Dec 13, 2020
3dfe623
Update NEWS
hsbadr Dec 13, 2020
5118839
Update NEWS
hsbadr Dec 13, 2020
c5982ca
Update LDDFLAGS
hsbadr Dec 14, 2020
f971883
Update CXXFLAGS
hsbadr Dec 14, 2020
c6bedff
Copy TBB libs for reverse dependencies
hsbadr Dec 15, 2020
1622cf9
Use tbb::this_task_arena::max_concurrency()
hsbadr Dec 15, 2020
8d26191
Update PKG_LIBS if TBB_LIB is defined
hsbadr Dec 16, 2020
3a5a292
Makevars.in: Copy directories recursively with `cp -R`
hsbadr Dec 17, 2020
781819c
Check if libtbb.so exists if not found on Linux
hsbadr Dec 17, 2020
c843b2a
Makevars.in: Use -R with cp and rm
hsbadr Dec 17, 2020
6ff6eee
Copy the TBB header files
hsbadr Dec 17, 2020
06c99a9
Don't fail on copy
hsbadr Dec 17, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
Package: RcppParallel
Type: Package
Title: Parallel Programming Tools for 'Rcpp'
Version: 5.0.2-9000
Version: 5.1.0-9000
Authors@R: c(
person("JJ", "Allaire", role = c("aut"), email = "jj@rstudio.com"),
person("Romain", "Francois", role = c("aut", "cph")),
person("Kevin", "Ushey", role = c("aut", "cre"), email = "kevin@rstudio.com"),
person("Gregory", "Vandenbrouck", role = "aut"),
person("Marcus", "Geelnard", role = c("aut", "cph"),
comment = "TinyThread library, http://tinythreadpp.bitsnbites.eu/"),
comment = "TinyThread library, https://tinythreadpp.bitsnbites.eu/"),
person("Hamada S.", "Badr",
email = "badr@jhu.edu",
role = c("ctb"),
comment = c(ORCID = "0000-0002-9808-2344")),
person(family = "RStudio", role = "cph"),
person(family = "Intel", role = c("aut", "cph"),
comment = "Intel TBB library, https://www.threadingbuildingblocks.org/"),
Expand All @@ -24,12 +28,12 @@ Suggests:
RUnit,
knitr,
rmarkdown
SystemRequirements: GNU make, Windows: cmd.exe and cscript.exe, Solaris: g++ is required
SystemRequirements: GNU make, Intel TBB, Windows: cmd.exe and cscript.exe, Solaris: g++ is required
License: GPL (>= 2)
URL: http://rcppcore.github.io/RcppParallel, https://github.com/RcppCore/RcppParallel
URL: https://rcppcore.github.io/RcppParallel/, https://github.com/RcppCore/RcppParallel
BugReports: https://github.com/RcppCore/RcppParallel/issues
Biarch: TRUE
Collate:
Collate:
'build.R'
'hooks.R'
'options.R'
Expand Down
50 changes: 38 additions & 12 deletions R/build.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,23 @@ inlineCxxPlugin <- function() {
}

tbbCxxFlags <- function() {

flags <- c()

# opt-in to TBB on Windows
if (Sys.info()['sysname'] == "Windows")
flags <- paste(flags, "-DRCPP_PARALLEL_USE_TBB=1")


if (dir.exists(Sys.getenv("TBB_INC"))) {
TBB_INC <- asBuildPath(Sys.getenv("TBB_INC"))

if (file.exists(file.path(TBB_INC, "tbb", "version.h"))) {
flags <- paste0("-I", shQuote(TBB_INC), " -DTBB_INTERFACE_NEW")
} else {
flags <- paste0("-I", shQuote(TBB_INC))
}
}

flags
}

Expand All @@ -57,6 +67,9 @@ tbbLdFlags <- function() {
if ((Sys.info()['sysname'] %in% c("Windows", "SunOS")) && !isSparc()) {
tbb <- tbbLibPath()
paste("-L", asBuildPath(dirname(tbb)), " -ltbb -ltbbmalloc", sep = "")
} else if (dir.exists(Sys.getenv("TBB_LIB"))) {
TBB_LIB <- asBuildPath(Sys.getenv("TBB_LIB"))
paste0("-L", shQuote(TBB_LIB), " -Wl,-rpath,", TBB_LIB, " -ltbb -ltbbmalloc")
} else {
""
}
Expand All @@ -66,19 +79,32 @@ tbbLdFlags <- function() {
tbbLibPath <- function(suffix = "") {
sysname <- Sys.info()['sysname']
tbbSupported <- list(
"Darwin" = paste("libtbb", suffix, ".dylib", sep = ""),
"Linux" = paste("libtbb", suffix, ".so.2", sep = ""),
"Darwin" = paste("libtbb", suffix, ".dylib", sep = ""),
"Linux" = paste("libtbb", suffix, ".so.2", sep = ""),
"Windows" = paste("tbb", suffix, ".dll", sep = ""),
"SunOS" = paste("libtbb", suffix, ".so", sep = "")
)
if ((sysname %in% names(tbbSupported)) && !isSparc()) {
libDir <- "lib/"
if (sysname == "Windows")
libDir <- paste(libDir, .Platform$r_arch, "/", sep="")
system.file(paste(libDir, tbbSupported[[sysname]], sep = ""),
package = "RcppParallel")

if (dir.exists(Sys.getenv("TBB_LIB"))) {
TBB_LIB <- asBuildPath(Sys.getenv("TBB_LIB"))
asBuildPath(file.path(TBB_LIB, paste("libtbb", suffix, ".so", sep = "")))
} else {
NULL
if ((sysname %in% names(tbbSupported)) && !isSparc()) {
libDir <- "lib/"
if (sysname == "Windows")
libDir <- paste(libDir, .Platform$r_arch, "/", sep="")

tbb_path <- system.file(paste(libDir, tbbSupported[[sysname]], sep = ""),
package = "RcppParallel")
if (sysname == "Linux" && !file.exists(tbb_path)) {
system.file(paste(libDir, "libtbb", suffix, ".so", sep =""),
package = "RcppParallel")
} else {
tbb_path
}
} else {
NULL
}
}
}

Expand Down
9 changes: 8 additions & 1 deletion inst/NEWS
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
RcppParallel 5.0.3 (UNRELEASED)
RcppParallel 5.1.0 (UNRELEASED)
------------------------------------------------------------------------

* Added support for external TBB library via TBB_INC and/or TBB_LIB environment variables.
* Updated TBB functionality for the new interface.
* Falling back to building TBB from local source code.
* Backward TBB compatibility based on `__TBB_tbb_stddef_H`.
* Resolved conflicts between system and local TBB headers.
* Fixed URLs, used HTTPS, and minor cleanups.
* Updated package DESCRIPTION and bumped version.
* setThreadOptions(...) can again be called multiple times per session.
The requested number of threads will be used for invocations to parallelFor()
and parallelReduce() that don't explicitly request a specific number of threads.
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion man/RcppParallel-package.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
Blocks). On other platforms a less-performant fallback implementation based on the
TinyThread library is used.

For additional documentation see the package website at: \href{http://rcppcore.github.io/RcppParallel}{http://rcppcore.github.io/RcppParallel}.
For additional documentation see the package website at: \href{https://rcppcore.github.io/RcppParallel/}{https://rcppcore.github.io/RcppParallel/}.
}

\author{
Expand Down
32 changes: 30 additions & 2 deletions src/Makevars.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@

PKG_CPPFLAGS = -I../inst/include
PKG_CXXFLAGS = @CXX11STD@

ifdef TBB_INC
PKG_CPPFLAGS = -I../inst/include -I$(TBB_INC)
else
PKG_CPPFLAGS = -I../inst/include
endif

ifdef TBB_LIB
PKG_LIBS = -Wl,-L,"$(TBB_LIB)" -Wl,-rpath,"$(TBB_LIB)" -ltbb -ltbbmalloc
endif

ifeq ($(OS), Windows_NT)

USE_TBB=Windows
Expand Down Expand Up @@ -86,7 +95,21 @@ endif
all: tbb $(SHLIB)

tbb:
ifdef TBB_LIB
echo "Using system (Intel/OneAPI) TBB library..."; \
mkdir -p ../inst/lib/$(ARCH_DIR); \
cp $(TBB_LIB)/libtbb.so ../inst/lib/$(ARCH_DIR)/libtbb.so 2>/dev/null || :; \
cp $(TBB_LIB)/libtbbmalloc.so ../inst/lib/$(ARCH_DIR)/libtbbmalloc.so 2>/dev/null || :; \
rm -Rf ../inst/include/serial/ ../inst/include/tbb/; \
rm -Rf ../inst/include/tbb_local/; \
mkdir -p ../inst/include; \
cp -R $(TBB_INC)/serial ../inst/include/ 2>/dev/null || :; \
cp -R $(TBB_INC)/tbb ../inst/include/ 2>/dev/null || :
else
echo "Building TBB library from source code..."; \
mkdir -p ../inst/lib/$(ARCH_DIR); \
cp -R ../inst/include/tbb_local/* ../inst/include/; \
rm -Rf ../inst/include/tbb_local/; \
cd tbb/src; \
if [ -n "$(shell echo $(CC) | grep clang)" ]; then \
$(MAKE_CMD) stdver=@STDVER@ compiler=clang $(MAKE_ARGS); \
Expand All @@ -97,9 +120,14 @@ tbb:
fi; \
cd ../..; \
cp tbb/build/lib_release/$(TBB_COPY_PATTERN) ../inst/lib/$(ARCH_DIR)
endif

clean:
ifdef TBB_LIB
echo "Nothing to clean for TBB."
else
(cd tbb/src; make clean)

endif


endif
4 changes: 4 additions & 0 deletions src/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@

extern "C" SEXP defaultNumThreads() {
SEXP threadsSEXP = Rf_allocVector(INTSXP, 1);
#ifndef __TBB_tbb_stddef_H
INTEGER(threadsSEXP)[0] = tbb::this_task_arena::max_concurrency();
#else
INTEGER(threadsSEXP)[0] = tbb::task_scheduler_init::default_num_threads();
#endif
return threadsSEXP;
}

Expand Down