Skip to content

update to oneTBB 2022.0 #232

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 17 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
^inst/libs$
^revdep$
^src/.*\.o$
^src/tbb/build/lib_.*$
^src/tbb/build$
^tags$
^tests/testthat/pkg/RcppParallelTest/src/.*\.dll$
^tests/testthat/pkg/RcppParallelTest/src/.*\.s?o$
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ src-i386
src-x64
tbb.log

src/tbb/build
src/tbb/build-tbb

R/tbb-autodetected.R
src/install.libs.R

23 changes: 12 additions & 11 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,37 @@ Type: Package
Title: Parallel Programming Tools for 'Rcpp'
Version: 5.1.9.9000
Authors@R: c(
person("Kevin", "Ushey", role = c("aut", "cre"), email = "[email protected]",
comment = c(ORCID = "0000-0003-2880-7407")),
person("JJ", "Allaire", role = c("aut"), email = "[email protected]"),
person("Romain", "Francois", role = c("aut", "cph")),
person("Kevin", "Ushey", role = c("aut", "cre"), email = "[email protected]"),
person("Gregory", "Vandenbrouck", role = "aut"),
person("Marcus", "Geelnard", role = c("aut", "cph"),
comment = "TinyThread library, https://tinythreadpp.bitsnbites.eu/"),
person("Hamada S.", "Badr",
email = "[email protected]",
role = c("ctb"),
person("Hamada S.", "Badr", email = "[email protected]", role = c("ctb"),
comment = c(ORCID = "0000-0002-9808-2344")),
person(family = "Posit, PBC", role = "cph"),
person(family = "Intel", role = c("aut", "cph"),
comment = "Intel TBB library, https://www.threadingbuildingblocks.org/"),
person(family = "Microsoft", role = "cph")
person("Dirk", "Eddelbuettel", role = c("aut"), email = "[email protected]",
comment = c(ORCID = "0000-0001-6419-907X")),
person(family = "Intel", role = c("aut", "cph"), comment = "oneTBB library"),
person(family = "UXL Foundation", role = c("aut", "cph"), comment = "oneTBB library"),
person(family = "Microsoft", role = "cph"),
person(family = "Posit, PBC", role = "cph")
)
Description: High level functions for parallel programming with 'Rcpp'.
For example, the 'parallelFor()' function can be used to convert the work of
a standard serial "for" loop into a parallel one and the 'parallelReduce()'
function can be used for accumulating aggregate or other values.
Depends: R (>= 3.0.2)
Depends: R (>= 3.6.0)
Suggests:
Rcpp,
RUnit,
knitr,
rmarkdown
Roxygen: list(markdown = TRUE)
SystemRequirements: GNU make, Intel TBB, Windows: cmd.exe and cscript.exe, Solaris: g++ is required
SystemRequirements: CMake (>= 3.5)
License: GPL (>= 3)
URL: https://rcppcore.github.io/RcppParallel/, https://github.com/RcppCore/RcppParallel
BugReports: https://github.com/RcppCore/RcppParallel/issues
Biarch: TRUE
RoxygenNote: 7.1.1
RoxygenNote: 7.3.2
Encoding: UTF-8
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@

## RcppParallel 5.1.10 (UNRELEASED)

* RcppParallel now bundles oneTBB 2022.0.0.

* On Windows, RcppParallel now uses the copy of TBB provided by Rtools, if any.
If TBB is not available, RcppParallel will use only the fallback 'tinythread'
implementation. In practice, this implies that RcppParallel will now only
provide a TBB backend with R (>= 4.2.0).

## RcppParallel 5.1.9

Expand Down
8 changes: 6 additions & 2 deletions R/aaa.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@

# stubs that get overridden via configure script
TBB_LIB <- ""
TBB_INC <- ""
TBB_ENABLED <- TRUE
TBB_LIB <- ""
TBB_INC <- ""

TBB_NAME <- "tbb"
TBB_MALLOC_NAME <- "tbbmalloc"
8 changes: 6 additions & 2 deletions R/tbb-autodetected.R.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@

TBB_LIB <- "@TBB_LIB@"
TBB_INC <- "@TBB_INC@"
TBB_ENABLED <- @TBB_ENABLED@
TBB_LIB <- "@TBB_LIB@"
TBB_INC <- "@TBB_INC@"

TBB_NAME <- "@TBB_NAME@"
TBB_MALLOC_NAME <- "@TBB_MALLOC_NAME@"
35 changes: 25 additions & 10 deletions R/tbb.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ tbbCxxFlags <- function() {

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

# if TBB_INC is set, apply those library paths
tbbInc <- Sys.getenv("TBB_INC", unset = TBB_INC)
if (!file.exists(tbbInc)) {
tbbInc <- system.file("include", package = "Rcpp")
}

if (nzchar(tbbInc)) {

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

# on Windows, we statically link to oneTBB
if (is_windows()) {

libPath <- system.file("libs", package = "RcppParallel")
if (nzchar(.Platform$r_arch))
libPath <- file.path(libPath, .Platform$r_arch)

ldFlags <- sprintf("-L%s -lRcppParallel", asBuildPath(libPath))
return(ldFlags)

}

# shortcut if TBB_LIB defined
tbbLib <- Sys.getenv("TBB_LINK_LIB", Sys.getenv("TBB_LIB", unset = TBB_LIB))
if (nzchar(tbbLib)) {
fmt <- if (is_windows()) "-L%1$s -ltbb -ltbbmalloc"
else "-L%1$s -Wl,-rpath,%1$s -ltbb -ltbbmalloc"
return(sprintf(fmt, asBuildPath(tbbLib)))
fmt <- "-L%1$s -Wl,-rpath,%1$s -l%2$s -l%3$s"
return(sprintf(fmt, asBuildPath(tbbLib), TBB_NAME, TBB_MALLOC_NAME))
}

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

# nothing required on other platforms
Expand Down
1 change: 1 addition & 0 deletions RcppParallel.Rproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Version: 1.0
ProjectId: 8e3d73b0-404c-42f5-b2ef-46f759f65dd4

RestoreWorkspace: No
SaveWorkspace: No
Expand Down
6 changes: 5 additions & 1 deletion inst/include/RcppParallel/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ inline int resolveValue(const char* envvar,
U defaultValue)
{
// if the requested value is non-zero and not the default, we can use it
if (requestedValue != defaultValue && requestedValue > 0)
bool useRequestedValue =
requestedValue != static_cast<T>(defaultValue) &&
requestedValue > 0;

if (useRequestedValue)
return requestedValue;

// otherwise, try reading the default from associated envvar
Expand Down
175 changes: 14 additions & 161 deletions src/Makevars.in
Original file line number Diff line number Diff line change
@@ -1,144 +1,17 @@

PKG_CXXFLAGS = @CXX11STD@
CMAKE = @CMAKE@
R = @R@

TBB_LIB = @TBB_LIB@
TBB_INC = @TBB_INC@
TBB_LIB = @TBB_LIB@
TBB_INC = @TBB_INC@
TBB_NAME = @TBB_NAME@
TBB_MALLOC_NAME = @TBB_MALLOC_NAME@

# If TBB_INC is defined, include those library paths.
ifdef TBB_INC
PKG_CPPFLAGS = -I../inst/include -I$(TBB_INC)
else
PKG_CPPFLAGS = -I../inst/include
endif
PKG_CPPFLAGS = @PKG_CPPFLAGS@
PKG_CXXFLAGS = @PKG_CXXFLAGS@

# If TBB_LIB is defined, link to that explicitly.
ifdef TBB_LIB
ifeq ($(OS), Windows_NT)
PKG_LIBS = -Wl,-L"$(TBB_LIB)" -ltbb -ltbbmalloc
else
PKG_LIBS = -Wl,-L"$(TBB_LIB)" -Wl,-rpath,"$(TBB_LIB)" -ltbb -ltbbmalloc
endif
endif
PKG_LIBS = @PKG_LIBS@ @PKG_LIBS_EXTRA@

ifeq ($(OS), Windows_NT)

USE_TBB=Windows
TBB_COPY_PATTERN=tbb*.dll

ARCH=$(shell "${R_HOME}/bin/R" --vanilla -s -e 'cat(R.version$$arch)')
TBB_CXXFLAGS = @CXX11FLAGS@ -DTBB_NO_LEGACY=1
ifeq "$(ARCH)" "aarch64"
PKG_CPPFLAGS += -DTBB_USE_GCC_BUILTINS
TBB_CXXFLAGS += -DTBB_USE_GCC_BUILTINS
CLANG_CHECK := $(shell echo | $(CC) -E -dM - | findstr __clang__)
ifneq ($(CLANG_CHECK), )
WINARM64_CLANG=true
endif
endif

MAKE = make
MAKEFLAGS = -e -j1
MAKE_CMD = \
MSYS2_ARG_CONV_EXCL="*" \
CYGWIN=nodosfilewarning \
CONLY="@WINDOWS_CC@" \
CPLUS="@WINDOWS_CXX11@" \
CXXFLAGS="$(TBB_CXXFLAGS)" \
PIC_KEY="@CXX11PICFLAGS@" \
WARNING_SUPPRESS="" \
WINARM64_CLANG="$(WINARM64_CLANG)" \
$(MAKE)

else

UNAME := $(shell uname)
TBB_COPY_PATTERN=libtbb*.*

ifeq ($(UNAME), Darwin)
USE_TBB=Mac
MAKE_ARGS += arch=$(shell uname -m)
endif

ifeq ($(UNAME), Linux)
USE_TBB=Linux
endif

ifeq ($(UNAME), SunOS)
SUNOS_ARCH = $(shell uname -p)
ifeq ($(SUNOS_ARCH), i386)
USE_TBB=SunOS
endif
endif

MAKEFLAGS += -e
MAKE_CMD = \
CONLY="@CC@ $(PKG_CPPFLAGS) @CPPFLAGS@" \
CPLUS="@CXX11@ $(PKG_CPPFLAGS) @CPPFLAGS@" \
CXXFLAGS="@CXX11FLAGS@ -DTBB_NO_LEGACY=1" \
PIC_KEY="@CXX11PICFLAGS@" \
WARNING_SUPPRESS="" \
$(MAKE)

endif

ifdef USE_TBB

PKG_CXXFLAGS += -DRCPP_PARALLEL_USE_TBB=1
PKG_CXXFLAGS += -DTBB_SUPPRESS_DEPRECATED_MESSAGES=1

MAKE_TARGETS = tbb_build_prefix=lib tbb_release tbbmalloc_release

ifeq ($(USE_TBB), Windows)

# rtools: turn on hacks to compensate for make and shell differences rtools<=>MinGW
# compiler: overwrite default (which is cl = MS compiler)
MAKE_ARGS += rtools=true compiler=gcc

# TBB configure will detect mingw runtime with unknown arch on WINARM64_CLANG but not an
# issue as we are using compiler built-ins instead of arch-specific code
ifneq ($(WINARM64_CLANG), true)
ifeq ($(WIN), 64)
MAKE_ARGS += arch=intel64 runtime=mingw
ARCH_DIR=x64/
else
MAKE_ARGS += arch=ia32 runtime=mingw
ARCH_DIR=i386/
endif
endif

# Linker needs access to the tbb dll; otherwise you get errors such as:
# "undefined reference to `tbb::task_scheduler_init::terminate()'"
PKG_LIBS += -Ltbb/build/lib_release -ltbb -ltbbmalloc
endif

# write compiler if set
ifneq (@COMPILER@, )
MAKE_ARGS += compiler=@COMPILER@
endif

# When TBB_LIB is unset on MacOS, link to the bundled version (#206)
ifeq ($(USE_TBB)$(TBB_LIB),Mac)
PKG_LIBS += -Ltbb/build/lib_release -ltbb -Wl,-rpath,'@loader_path/../lib'
endif

# For Solaris detect if this is 32-bit R on x86 and if so forward that to TBB
ifeq ($(USE_TBB), SunOS)
R_32BIT = $(shell ${R_HOME}/bin/Rscript -e 'cat(.Machine$$sizeof.pointer == 4)')
ifeq ($(R_32BIT), TRUE)
MAKE_ARGS += arch=ia32
endif
endif

# Write compilation output to file, and log it if installation fails.
ifeq ($(VERBOSE), )
MAKE_LOG = > tbb.log 2>&1 \
&& echo "(tbb) TBB compilation finished successfully." \
|| cat tbb.log; rm -f tbb.log
endif

.PHONY: all tbb tbb-clean

# Order is important in Windows' case. See PKG_LIBS above
all: tbb $(SHLIB)

# TBB needs to be built before our C++ sources are built, so that
Expand All @@ -148,21 +21,11 @@ $(OBJECTS): tbb
# NOTE: TBB libraries are installed via install.libs.R.
# However, we need to copy headers here so that they are visible during compilation.
tbb: tbb-clean
ifdef TBB_LIB
@echo "(tbb) Using system (Intel / OneAPI) TBB library."
@echo "(tbb) TBB_LIB = $(TBB_LIB)"
@echo "(tbb) TBB_INC = $(TBB_INC)"
@mkdir -p ../inst/include
@cp -R $(TBB_INC)/oneapi ../inst/include/ 2> /dev/null || :
@cp -R $(TBB_INC)/serial ../inst/include/ 2> /dev/null || :
@cp -R $(TBB_INC)/tbb ../inst/include/ 2> /dev/null || :
else
@echo "(tbb) Building TBB using bundled sources ..."
@mkdir -p ../inst/include
@cp -R tbb/include/* ../inst/include/
@(cd tbb/src && $(MAKE_CMD) $(MAKE_ARGS) info)
@(cd tbb/src && $(MAKE_CMD) $(MAKE_ARGS) $(MAKE_TARGETS) $(MAKE_LOG))
endif
TBB_LIB="$(TBB_LIB)" TBB_INC="$(TBB_INC)" \
TBB_NAME="$(TBB_NAME)" TBB_MALLOC_NAME="$(TBB_MALLOC_NAME)" \
CC="$(CC)" CFLAGS="$(CFLAGS)" CPPFLAGS="$(CPPFLAGS)" \
CXX="$(CXX)" CXXFLAGS="$(CXXFLAGS)" LDFLAGS="$(LDFLAGS)" \
CMAKE="$(CMAKE)" "@R@" -s -f install.libs.R --args build

# NOTE: we do not want to clean ../inst/lib or ../inst/libs here,
# as we may be writing to those locations in multiarch builds
Expand All @@ -171,13 +34,3 @@ tbb-clean:
@rm -rf ../inst/include/oneapi
@rm -rf ../inst/include/tbb_local
@rm -rf ../inst/include/serial

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


endif
Loading
Loading