Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
Merge branch 'master' into release/5.1.10
  • Loading branch information
kevinushey authored Jan 27, 2025
commit aa94cebf6961b06b0c6d86ed397ff8de1c0f7ebd
10 changes: 10 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@

## RcppParallel 6.0.0 (UNRELEASED)

* RcppParallel now bundles oneTBB 2022.0.0. Note that the TBB ABI has changed;
packages which depend on RcppParallel may need to be rebuilt.

* On Windows, RcppParallel now uses the copy of TBB provided by Rtools.
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.10

* Fixed an issue where packages linking to RcppParallel could inadverently
Expand Down
81 changes: 40 additions & 41 deletions R/tbb.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,28 +54,37 @@ tbbLibraryPath <- function(name = NULL) {

tbbCxxFlags <- function() {

flags <- character()

# opt-in to TBB on Windows
if (is_windows()) {
flags <- c(flags, "-DRCPP_PARALLEL_USE_TBB=1")
if (!TBB_ENABLED)
return("-DRCPP_PARALLEL_USE_TBB=0")

flags <- c("-DRCPP_PARALLEL_USE_TBB=1")

# TBB does not have assembly code for Windows ARM64
# so we need to use compiler builtins
if (TBB_ENABLED && is_windows()) {
if (R.version$arch == "aarch64") {
flags <- c(flags, "-DTBB_USE_GCC_BUILTINS")
}
}

# if TBB_INC is set, apply those library paths
tbbInc <- Sys.getenv("TBB_INC", unset = TBB_INC)
if (nzchar(tbbInc)) {

# add include path
flags <- c(flags, paste0("-I", asBuildPath(tbbInc)))

# prefer new interface if version.h exists
if (!file.exists(tbbInc)) {
tbbInc <- system.file("include", package = "RcppParallel")
}

# add include path
if (nzchar(tbbInc) && file.exists(tbbInc)) {

# prefer new interface if version.h exists -- we keep this
# for compatibility with packages like StanHeaders, rstan
versionPath <- file.path(tbbInc, "tbb/version.h")
if (file.exists(versionPath))
flags <- c(flags, "-DTBB_INTERFACE_NEW")


# now add the include path
flags <- c(flags, paste0("-I", asBuildPath(tbbInc)))

}

# return flags as string
Expand All @@ -85,41 +94,31 @@ tbbCxxFlags <- function() {

# Return the linker flags required for TBB on this platform
tbbLdFlags <- function() {

tbbFlags <- tbbLdFlagsImpl()


# on Windows, we statically link to oneTBB
if (is_windows()) {
libDir <- system.file("libs", .Platform$r_arch, package = "RcppParallel")
libName <- paste0("RcppParallel", .Platform$dynlib.ext)
newFlags <- sprintf("-L%s -lRcppParallel", shQuote(libDir))
tbbFlags <- paste(newFlags, tbbFlags)

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)

}

tbbFlags

}

tbbLdFlagsImpl <- function() {


# 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
4 changes: 3 additions & 1 deletion R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ loadTbbLibrary <- function(name) {
.tbbMallocProxyDllInfo <<- loadTbbLibrary("tbbmalloc_proxy")

# load RcppParallel library if available
.dllInfo <<- library.dynam("RcppParallel", pkgname, libname, local = FALSE)
if (.Platform$OS.type != "windows") {
.dllInfo <<- library.dynam("RcppParallel", pkgname, libname, local = FALSE)
}

}

Expand Down
2 changes: 1 addition & 1 deletion RcppParallel.Rproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Version: 1.0
ProjectId: f1ae2e5b-eb1d-4d93-9ae1-29e364a5eaa6
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 != static_cast<T>(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
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.