Skip to content

Commit fd8f510

Browse files
authored
update to oneTBB 2022.0 (#232)
* update to oneTBB 2022.0 * use Rtools TBB if available * remove more bazel stuff * more * finishing up * tweaks * relax version constraint, just in case * more cleanup; remove GNU-isms * try cleaning up build dir after we're done * check for cmake * tweaks (support alternate build types) * more cleanup * fixup for macOS * make sure RcppParallel still builds with older R * try to support older R + Windows * more Windows fun * fixup
1 parent 69d50f6 commit fd8f510

File tree

804 files changed

+57515
-168548
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

804 files changed

+57515
-168548
lines changed

.Rbuildignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
^inst/libs$
1212
^revdep$
1313
^src/.*\.o$
14-
^src/tbb/build/lib_.*$
14+
^src/tbb/build$
1515
^tags$
1616
^tests/testthat/pkg/RcppParallelTest/src/.*\.dll$
1717
^tests/testthat/pkg/RcppParallelTest/src/.*\.s?o$

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ src-i386
1212
src-x64
1313
tbb.log
1414

15+
src/tbb/build
16+
src/tbb/build-tbb
17+
1518
R/tbb-autodetected.R
16-
src/install.libs.R
1719

DESCRIPTION

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,37 @@ Type: Package
33
Title: Parallel Programming Tools for 'Rcpp'
44
Version: 5.1.9.9000
55
Authors@R: c(
6+
person("Kevin", "Ushey", role = c("aut", "cre"), email = "[email protected]",
7+
comment = c(ORCID = "0000-0003-2880-7407")),
68
person("JJ", "Allaire", role = c("aut"), email = "[email protected]"),
79
person("Romain", "Francois", role = c("aut", "cph")),
8-
person("Kevin", "Ushey", role = c("aut", "cre"), email = "[email protected]"),
910
person("Gregory", "Vandenbrouck", role = "aut"),
1011
person("Marcus", "Geelnard", role = c("aut", "cph"),
1112
comment = "TinyThread library, https://tinythreadpp.bitsnbites.eu/"),
12-
person("Hamada S.", "Badr",
13-
email = "[email protected]",
14-
role = c("ctb"),
13+
person("Hamada S.", "Badr", email = "[email protected]", role = c("ctb"),
1514
comment = c(ORCID = "0000-0002-9808-2344")),
16-
person(family = "Posit, PBC", role = "cph"),
17-
person(family = "Intel", role = c("aut", "cph"),
18-
comment = "Intel TBB library, https://www.threadingbuildingblocks.org/"),
19-
person(family = "Microsoft", role = "cph")
15+
person("Dirk", "Eddelbuettel", role = c("aut"), email = "[email protected]",
16+
comment = c(ORCID = "0000-0001-6419-907X")),
17+
person(family = "Intel", role = c("aut", "cph"), comment = "oneTBB library"),
18+
person(family = "UXL Foundation", role = c("aut", "cph"), comment = "oneTBB library"),
19+
person(family = "Microsoft", role = "cph"),
20+
person(family = "Posit, PBC", role = "cph")
2021
)
2122
Description: High level functions for parallel programming with 'Rcpp'.
2223
For example, the 'parallelFor()' function can be used to convert the work of
2324
a standard serial "for" loop into a parallel one and the 'parallelReduce()'
2425
function can be used for accumulating aggregate or other values.
25-
Depends: R (>= 3.0.2)
26+
Depends: R (>= 3.6.0)
2627
Suggests:
2728
Rcpp,
2829
RUnit,
2930
knitr,
3031
rmarkdown
3132
Roxygen: list(markdown = TRUE)
32-
SystemRequirements: GNU make, Intel TBB, Windows: cmd.exe and cscript.exe, Solaris: g++ is required
33+
SystemRequirements: CMake (>= 3.5)
3334
License: GPL (>= 3)
3435
URL: https://rcppcore.github.io/RcppParallel/, https://github.com/RcppCore/RcppParallel
3536
BugReports: https://github.com/RcppCore/RcppParallel/issues
3637
Biarch: TRUE
37-
RoxygenNote: 7.1.1
38+
RoxygenNote: 7.3.2
3839
Encoding: UTF-8

NEWS.md

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

22
## RcppParallel 5.1.10 (UNRELEASED)
33

4+
* RcppParallel now bundles oneTBB 2022.0.0.
5+
6+
* On Windows, RcppParallel now uses the copy of TBB provided by Rtools, if any.
7+
If TBB is not available, RcppParallel will use only the fallback 'tinythread'
8+
implementation. In practice, this implies that RcppParallel will now only
9+
provide a TBB backend with R (>= 4.2.0).
410

511
## RcppParallel 5.1.9
612

R/aaa.R

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

22
# stubs that get overridden via configure script
3-
TBB_LIB <- ""
4-
TBB_INC <- ""
3+
TBB_ENABLED <- TRUE
4+
TBB_LIB <- ""
5+
TBB_INC <- ""
6+
7+
TBB_NAME <- "tbb"
8+
TBB_MALLOC_NAME <- "tbbmalloc"

R/tbb-autodetected.R.in

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

2-
TBB_LIB <- "@TBB_LIB@"
3-
TBB_INC <- "@TBB_INC@"
2+
TBB_ENABLED <- @TBB_ENABLED@
3+
TBB_LIB <- "@TBB_LIB@"
4+
TBB_INC <- "@TBB_INC@"
5+
6+
TBB_NAME <- "@TBB_NAME@"
7+
TBB_MALLOC_NAME <- "@TBB_MALLOC_NAME@"

R/tbb.R

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ tbbCxxFlags <- function() {
5050

5151
# opt-in to TBB on Windows
5252
if (is_windows()) {
53-
flags <- c(flags, "-DRCPP_PARALLEL_USE_TBB=1")
53+
enabled <- if (TBB_ENABLED) "1" else "0"
54+
flags <- c(flags, sprintf("-DRCPP_PARALLEL_USE_TBB=%s", enabled))
5455
if (R.version$arch == "aarch64") {
5556
# TBB does not have assembly code for Windows ARM64
5657
# so we need to use compiler builtins
@@ -60,6 +61,10 @@ tbbCxxFlags <- function() {
6061

6162
# if TBB_INC is set, apply those library paths
6263
tbbInc <- Sys.getenv("TBB_INC", unset = TBB_INC)
64+
if (!file.exists(tbbInc)) {
65+
tbbInc <- system.file("include", package = "Rcpp")
66+
}
67+
6368
if (nzchar(tbbInc)) {
6469

6570
# add include path
@@ -80,20 +85,30 @@ tbbCxxFlags <- function() {
8085
# Return the linker flags required for TBB on this platform
8186
tbbLdFlags <- function() {
8287

88+
# on Windows, we statically link to oneTBB
89+
if (is_windows()) {
90+
91+
libPath <- system.file("libs", package = "RcppParallel")
92+
if (nzchar(.Platform$r_arch))
93+
libPath <- file.path(libPath, .Platform$r_arch)
94+
95+
ldFlags <- sprintf("-L%s -lRcppParallel", asBuildPath(libPath))
96+
return(ldFlags)
97+
98+
}
99+
83100
# shortcut if TBB_LIB defined
84101
tbbLib <- Sys.getenv("TBB_LINK_LIB", Sys.getenv("TBB_LIB", unset = TBB_LIB))
85102
if (nzchar(tbbLib)) {
86-
fmt <- if (is_windows()) "-L%1$s -ltbb -ltbbmalloc"
87-
else "-L%1$s -Wl,-rpath,%1$s -ltbb -ltbbmalloc"
88-
return(sprintf(fmt, asBuildPath(tbbLib)))
103+
fmt <- "-L%1$s -Wl,-rpath,%1$s -l%2$s -l%3$s"
104+
return(sprintf(fmt, asBuildPath(tbbLib), TBB_NAME, TBB_MALLOC_NAME))
89105
}
90106

91-
# on Mac, Windows and Solaris, we need to explicitly link (#206)
92-
needsExplicitFlags <- is_mac() || is_windows() || (is_solaris() && !is_sparc())
93-
if (needsExplicitFlags) {
94-
libPath <- asBuildPath(tbbLibraryPath())
95-
libFlag <- paste0("-L", libPath)
96-
return(paste(libFlag, "-ltbb", "-ltbbmalloc"))
107+
# explicitly link on macOS
108+
# https://github.com/RcppCore/RcppParallel/issues/206
109+
if (is_mac()) {
110+
fmt <- "-L%s -l%s -l%s"
111+
return(sprintf(fmt, asBuildPath(tbbLibraryPath()), TBB_NAME, TBB_MALLOC_NAME))
97112
}
98113

99114
# nothing required on other platforms

RcppParallel.Rproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
Version: 1.0
2+
ProjectId: 8e3d73b0-404c-42f5-b2ef-46f759f65dd4
23

34
RestoreWorkspace: No
45
SaveWorkspace: No

inst/include/RcppParallel/Common.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ inline int resolveValue(const char* envvar,
1313
U defaultValue)
1414
{
1515
// if the requested value is non-zero and not the default, we can use it
16-
if (requestedValue != defaultValue && requestedValue > 0)
16+
bool useRequestedValue =
17+
requestedValue != static_cast<T>(defaultValue) &&
18+
requestedValue > 0;
19+
20+
if (useRequestedValue)
1721
return requestedValue;
1822

1923
// otherwise, try reading the default from associated envvar

src/Makevars.in

Lines changed: 14 additions & 161 deletions
Original file line numberDiff line numberDiff line change
@@ -1,144 +1,17 @@
11

2-
PKG_CXXFLAGS = @CXX11STD@
2+
CMAKE = @CMAKE@
3+
R = @R@
34

4-
TBB_LIB = @TBB_LIB@
5-
TBB_INC = @TBB_INC@
5+
TBB_LIB = @TBB_LIB@
6+
TBB_INC = @TBB_INC@
7+
TBB_NAME = @TBB_NAME@
8+
TBB_MALLOC_NAME = @TBB_MALLOC_NAME@
69

7-
# If TBB_INC is defined, include those library paths.
8-
ifdef TBB_INC
9-
PKG_CPPFLAGS = -I../inst/include -I$(TBB_INC)
10-
else
11-
PKG_CPPFLAGS = -I../inst/include
12-
endif
10+
PKG_CPPFLAGS = @PKG_CPPFLAGS@
11+
PKG_CXXFLAGS = @PKG_CXXFLAGS@
1312

14-
# If TBB_LIB is defined, link to that explicitly.
15-
ifdef TBB_LIB
16-
ifeq ($(OS), Windows_NT)
17-
PKG_LIBS = -Wl,-L"$(TBB_LIB)" -ltbb -ltbbmalloc
18-
else
19-
PKG_LIBS = -Wl,-L"$(TBB_LIB)" -Wl,-rpath,"$(TBB_LIB)" -ltbb -ltbbmalloc
20-
endif
21-
endif
13+
PKG_LIBS = @PKG_LIBS@ @PKG_LIBS_EXTRA@
2214

23-
ifeq ($(OS), Windows_NT)
24-
25-
USE_TBB=Windows
26-
TBB_COPY_PATTERN=tbb*.dll
27-
28-
ARCH=$(shell "${R_HOME}/bin/R" --vanilla -s -e 'cat(R.version$$arch)')
29-
TBB_CXXFLAGS = @CXX11FLAGS@ -DTBB_NO_LEGACY=1
30-
ifeq "$(ARCH)" "aarch64"
31-
PKG_CPPFLAGS += -DTBB_USE_GCC_BUILTINS
32-
TBB_CXXFLAGS += -DTBB_USE_GCC_BUILTINS
33-
CLANG_CHECK := $(shell echo | $(CC) -E -dM - | findstr __clang__)
34-
ifneq ($(CLANG_CHECK), )
35-
WINARM64_CLANG=true
36-
endif
37-
endif
38-
39-
MAKE = make
40-
MAKEFLAGS = -e -j1
41-
MAKE_CMD = \
42-
MSYS2_ARG_CONV_EXCL="*" \
43-
CYGWIN=nodosfilewarning \
44-
CONLY="@WINDOWS_CC@" \
45-
CPLUS="@WINDOWS_CXX11@" \
46-
CXXFLAGS="$(TBB_CXXFLAGS)" \
47-
PIC_KEY="@CXX11PICFLAGS@" \
48-
WARNING_SUPPRESS="" \
49-
WINARM64_CLANG="$(WINARM64_CLANG)" \
50-
$(MAKE)
51-
52-
else
53-
54-
UNAME := $(shell uname)
55-
TBB_COPY_PATTERN=libtbb*.*
56-
57-
ifeq ($(UNAME), Darwin)
58-
USE_TBB=Mac
59-
MAKE_ARGS += arch=$(shell uname -m)
60-
endif
61-
62-
ifeq ($(UNAME), Linux)
63-
USE_TBB=Linux
64-
endif
65-
66-
ifeq ($(UNAME), SunOS)
67-
SUNOS_ARCH = $(shell uname -p)
68-
ifeq ($(SUNOS_ARCH), i386)
69-
USE_TBB=SunOS
70-
endif
71-
endif
72-
73-
MAKEFLAGS += -e
74-
MAKE_CMD = \
75-
CONLY="@CC@ $(PKG_CPPFLAGS) @CPPFLAGS@" \
76-
CPLUS="@CXX11@ $(PKG_CPPFLAGS) @CPPFLAGS@" \
77-
CXXFLAGS="@CXX11FLAGS@ -DTBB_NO_LEGACY=1" \
78-
PIC_KEY="@CXX11PICFLAGS@" \
79-
WARNING_SUPPRESS="" \
80-
$(MAKE)
81-
82-
endif
83-
84-
ifdef USE_TBB
85-
86-
PKG_CXXFLAGS += -DRCPP_PARALLEL_USE_TBB=1
87-
PKG_CXXFLAGS += -DTBB_SUPPRESS_DEPRECATED_MESSAGES=1
88-
89-
MAKE_TARGETS = tbb_build_prefix=lib tbb_release tbbmalloc_release
90-
91-
ifeq ($(USE_TBB), Windows)
92-
93-
# rtools: turn on hacks to compensate for make and shell differences rtools<=>MinGW
94-
# compiler: overwrite default (which is cl = MS compiler)
95-
MAKE_ARGS += rtools=true compiler=gcc
96-
97-
# TBB configure will detect mingw runtime with unknown arch on WINARM64_CLANG but not an
98-
# issue as we are using compiler built-ins instead of arch-specific code
99-
ifneq ($(WINARM64_CLANG), true)
100-
ifeq ($(WIN), 64)
101-
MAKE_ARGS += arch=intel64 runtime=mingw
102-
ARCH_DIR=x64/
103-
else
104-
MAKE_ARGS += arch=ia32 runtime=mingw
105-
ARCH_DIR=i386/
106-
endif
107-
endif
108-
109-
# Linker needs access to the tbb dll; otherwise you get errors such as:
110-
# "undefined reference to `tbb::task_scheduler_init::terminate()'"
111-
PKG_LIBS += -Ltbb/build/lib_release -ltbb -ltbbmalloc
112-
endif
113-
114-
# write compiler if set
115-
ifneq (@COMPILER@, )
116-
MAKE_ARGS += compiler=@COMPILER@
117-
endif
118-
119-
# When TBB_LIB is unset on MacOS, link to the bundled version (#206)
120-
ifeq ($(USE_TBB)$(TBB_LIB),Mac)
121-
PKG_LIBS += -Ltbb/build/lib_release -ltbb -Wl,-rpath,'@loader_path/../lib'
122-
endif
123-
124-
# For Solaris detect if this is 32-bit R on x86 and if so forward that to TBB
125-
ifeq ($(USE_TBB), SunOS)
126-
R_32BIT = $(shell ${R_HOME}/bin/Rscript -e 'cat(.Machine$$sizeof.pointer == 4)')
127-
ifeq ($(R_32BIT), TRUE)
128-
MAKE_ARGS += arch=ia32
129-
endif
130-
endif
131-
132-
# Write compilation output to file, and log it if installation fails.
133-
ifeq ($(VERBOSE), )
134-
MAKE_LOG = > tbb.log 2>&1 \
135-
&& echo "(tbb) TBB compilation finished successfully." \
136-
|| cat tbb.log; rm -f tbb.log
137-
endif
138-
139-
.PHONY: all tbb tbb-clean
140-
141-
# Order is important in Windows' case. See PKG_LIBS above
14215
all: tbb $(SHLIB)
14316

14417
# TBB needs to be built before our C++ sources are built, so that
@@ -148,21 +21,11 @@ $(OBJECTS): tbb
14821
# NOTE: TBB libraries are installed via install.libs.R.
14922
# However, we need to copy headers here so that they are visible during compilation.
15023
tbb: tbb-clean
151-
ifdef TBB_LIB
152-
@echo "(tbb) Using system (Intel / OneAPI) TBB library."
153-
@echo "(tbb) TBB_LIB = $(TBB_LIB)"
154-
@echo "(tbb) TBB_INC = $(TBB_INC)"
155-
@mkdir -p ../inst/include
156-
@cp -R $(TBB_INC)/oneapi ../inst/include/ 2> /dev/null || :
157-
@cp -R $(TBB_INC)/serial ../inst/include/ 2> /dev/null || :
158-
@cp -R $(TBB_INC)/tbb ../inst/include/ 2> /dev/null || :
159-
else
160-
@echo "(tbb) Building TBB using bundled sources ..."
161-
@mkdir -p ../inst/include
162-
@cp -R tbb/include/* ../inst/include/
163-
@(cd tbb/src && $(MAKE_CMD) $(MAKE_ARGS) info)
164-
@(cd tbb/src && $(MAKE_CMD) $(MAKE_ARGS) $(MAKE_TARGETS) $(MAKE_LOG))
165-
endif
24+
TBB_LIB="$(TBB_LIB)" TBB_INC="$(TBB_INC)" \
25+
TBB_NAME="$(TBB_NAME)" TBB_MALLOC_NAME="$(TBB_MALLOC_NAME)" \
26+
CC="$(CC)" CFLAGS="$(CFLAGS)" CPPFLAGS="$(CPPFLAGS)" \
27+
CXX="$(CXX)" CXXFLAGS="$(CXXFLAGS)" LDFLAGS="$(LDFLAGS)" \
28+
CMAKE="$(CMAKE)" "@R@" -s -f install.libs.R --args build
16629

16730
# NOTE: we do not want to clean ../inst/lib or ../inst/libs here,
16831
# as we may be writing to those locations in multiarch builds
@@ -171,13 +34,3 @@ tbb-clean:
17134
@rm -rf ../inst/include/oneapi
17235
@rm -rf ../inst/include/tbb_local
17336
@rm -rf ../inst/include/serial
174-
175-
clean: tbb-clean
176-
ifdef TBB_LIB
177-
@echo "Nothing to clean for TBB."
178-
else
179-
@(cd tbb/src; make clean)
180-
endif
181-
182-
183-
endif

0 commit comments

Comments
 (0)