Skip to content

Commit 762a579

Browse files
authored
interim release to help with future binary compatibility (#234)
* rearrange a bit * no more inline stack size control * move parallel-for stuff into cpp * move parallel reducer out of header * revert some test changes * prepare for release * need to link to RcppParallel in plugin on Windows * compiler warnings * Update DESCRIPTION
1 parent 0b136ce commit 762a579

File tree

13 files changed

+433
-304
lines changed

13 files changed

+433
-304
lines changed

DESCRIPTION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: RcppParallel
22
Type: Package
33
Title: Parallel Programming Tools for 'Rcpp'
4-
Version: 5.1.9.9000
4+
Version: 5.1.10.9000
55
Authors@R: c(
66
person("Kevin", "Ushey", role = c("aut", "cre"), email = "[email protected]",
77
comment = c(ORCID = "0000-0003-2880-7407")),

NEWS.md

+6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99
implementation. In practice, this implies that RcppParallel will now only
1010
provide a TBB backend with R (>= 4.2.0).
1111

12+
## RcppParallel 5.1.10
13+
14+
* Fixed an issue where packages linking to RcppParallel could inadverently
15+
depend on internals of the TBB library available during compilation, even
16+
if the package did not explicitly use TBB itself.
17+
1218
## RcppParallel 5.1.9
1319

1420
* RcppParallel no longer passes `-rpath` when building / linking on Windows.

R/flags.R

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
11

22
#' Compilation flags for RcppParallel
3-
#'
3+
#'
44
#' Output the compiler or linker flags required to build against RcppParallel.
5-
#'
5+
#'
66
#' These functions are typically called from `Makevars` as follows:
7-
#'
7+
#'
88
#' ```
99
#' PKG_LIBS += $(shell "${R_HOME}/bin/Rscript" -e "RcppParallel::LdFlags()")
1010
#' ```
11-
#'
11+
#'
1212
#' On Windows, the flags ensure that the package links with the built-in TBB
1313
#' library. On Linux and macOS, the output is empty, because TBB is loaded
1414
#' dynamically on load by `RcppParallel`.
15-
#'
15+
#'
1616
#' \R packages using RcppParallel should also add the following to their
1717
#' `NAMESPACE` file:
18-
#'
18+
#'
1919
#' ```
2020
#' importFrom(RcppParallel, RcppParallelLibs)
2121
#' ```
22-
#'
22+
#'
2323
#' This is necessary to ensure that \pkg{RcppParallel} (and so, TBB) is loaded
2424
#' and available.
25-
#'
25+
#'
2626
#' @name flags
2727
#' @rdname flags
2828
#' @aliases RcppParallelLibs LdFlags CxxFlags
29-
#'
29+
#'
3030
#' @return Returns \code{NULL}, invisibly. These functions are called for
3131
#' their side effects (writing the associated flags to stdout).
3232
#'

R/tbb.R

+19-19
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,39 @@
11

22
#' Get the Path to a TBB Library
3-
#'
3+
#'
44
#' Retrieve the path to a TBB library. This can be useful for \R packages
55
#' using RcppParallel that wish to use, or re-use, the version of TBB that
66
#' RcppParallel has been configured to use.
7-
#'
7+
#'
88
#' @param name
99
#' The name of the TBB library to be resolved. Normally, this is one of
1010
#' `tbb`, `tbbmalloc`, or `tbbmalloc_proxy`. When `NULL`, the library
1111
#' path containing the TBB libraries is returned instead.
12-
#'
12+
#'
1313
#' @export
1414
tbbLibraryPath <- function(name = NULL) {
15-
15+
1616
# library paths for different OSes
1717
sysname <- Sys.info()[["sysname"]]
18-
18+
1919
# find root for TBB install
2020
tbbRoot <- Sys.getenv("TBB_LIB", unset = tbbRoot())
2121
if (is.null(name))
2222
return(tbbRoot)
23-
23+
2424
# form library names
2525
tbbLibNames <- list(
2626
"Darwin" = paste0("lib", name, ".dylib"),
2727
"Windows" = paste0( name, ".dll"),
2828
"SunOS" = paste0("lib", name, ".so"),
2929
"Linux" = paste0("lib", name, c(".so.2", ".so"))
3030
)
31-
31+
3232
# skip systems that we know not to be compatible
3333
isCompatible <- !is_sparc() && !is.null(tbbLibNames[[sysname]])
3434
if (!isCompatible)
3535
return(NULL)
36-
36+
3737
# find the request library (if any)
3838
libNames <- tbbLibNames[[sysname]]
3939
for (libName in libNames) {
@@ -49,12 +49,12 @@ tbbLibraryPath <- function(name = NULL) {
4949
return(tbbName)
5050

5151
}
52-
52+
5353
}
5454

5555
tbbCxxFlags <- function() {
56-
57-
if (!TBB_ENABLED)
56+
57+
if (!TBB_ENABLED)
5858
return("-DRCPP_PARALLEL_USE_TBB=0")
5959

6060
flags <- c("-DRCPP_PARALLEL_USE_TBB=1")
@@ -66,7 +66,7 @@ tbbCxxFlags <- function() {
6666
flags <- c(flags, "-DTBB_USE_GCC_BUILTINS")
6767
}
6868
}
69-
69+
7070
# if TBB_INC is set, apply those library paths
7171
tbbInc <- Sys.getenv("TBB_INC", unset = TBB_INC)
7272
if (!file.exists(tbbInc)) {
@@ -86,10 +86,10 @@ tbbCxxFlags <- function() {
8686
flags <- c(flags, paste0("-I", asBuildPath(tbbInc)))
8787

8888
}
89-
89+
9090
# return flags as string
9191
paste(flags, collapse = " ")
92-
92+
9393
}
9494

9595
# Return the linker flags required for TBB on this platform
@@ -120,20 +120,20 @@ tbbLdFlags <- function() {
120120
fmt <- "-L%s -l%s -l%s"
121121
return(sprintf(fmt, asBuildPath(tbbLibraryPath()), TBB_NAME, TBB_MALLOC_NAME))
122122
}
123-
123+
124124
# nothing required on other platforms
125125
""
126-
126+
127127
}
128128

129129
tbbRoot <- function() {
130-
130+
131131
if (nzchar(TBB_LIB))
132132
return(TBB_LIB)
133-
133+
134134
rArch <- .Platform$r_arch
135135
parts <- c("lib", if (nzchar(rArch)) rArch)
136136
libDir <- paste(parts, collapse = "/")
137137
system.file(libDir, package = "RcppParallel")
138-
138+
139139
}

R/zzz.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ loadTbbLibrary <- function(name) {
4343

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

4949
}

RcppParallel.Rproj

+4-1
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@ Encoding: UTF-8
1313
RnwWeave: Sweave
1414
LaTeX: pdfLaTeX
1515

16+
AutoAppendNewline: Yes
17+
StripTrailingWhitespace: Yes
18+
1619
BuildType: Package
1720
PackageCleanBeforeInstall: No
18-
PackageInstallArgs: --with-keep.source --clean
21+
PackageInstallArgs: --with-keep.source
1922
PackageCheckArgs: --as-cran
2023
PackageRoxygenize: rd,collate,namespace

inst/include/RcppParallel.h

+7-7
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include "RcppParallel/TinyThread.h"
77

88
// Use TBB only where it's known to compile and work correctly
9-
// (NOTE: Windows TBB is temporarily opt-in for packages for
9+
// (NOTE: Windows TBB is temporarily opt-in for packages for
1010
// compatibility with CRAN packages not previously configured
1111
// to link to TBB in Makevars.win)
1212
#ifndef RCPP_PARALLEL_USE_TBB
@@ -31,14 +31,14 @@
3131
namespace RcppParallel {
3232

3333
inline void parallelFor(std::size_t begin,
34-
std::size_t end,
34+
std::size_t end,
3535
Worker& worker,
3636
std::size_t grainSize = 1,
3737
int numThreads = -1)
3838
{
39-
grainSize = resolveValue("RCPP_PARALLEL_GRAIN_SIZE", grainSize, 1u);
39+
grainSize = resolveValue("RCPP_PARALLEL_GRAIN_SIZE", grainSize, std::size_t(1));
4040
numThreads = resolveValue("RCPP_PARALLEL_NUM_THREADS", numThreads, -1);
41-
41+
4242
#if RCPP_PARALLEL_USE_TBB
4343
if (internal::backend() == internal::BACKEND_TBB)
4444
tbbParallelFor(begin, end, worker, grainSize, numThreads);
@@ -51,14 +51,14 @@ inline void parallelFor(std::size_t begin,
5151

5252
template <typename Reducer>
5353
inline void parallelReduce(std::size_t begin,
54-
std::size_t end,
54+
std::size_t end,
5555
Reducer& reducer,
5656
std::size_t grainSize = 1,
5757
int numThreads = -1)
5858
{
59-
grainSize = resolveValue("RCPP_PARALLEL_GRAIN_SIZE", grainSize, 1);
59+
grainSize = resolveValue("RCPP_PARALLEL_GRAIN_SIZE", grainSize, std::size_t(1));
6060
numThreads = resolveValue("RCPP_PARALLEL_NUM_THREADS", numThreads, -1);
61-
61+
6262
#if RCPP_PARALLEL_USE_TBB
6363
if (internal::backend() == internal::BACKEND_TBB)
6464
tbbParallelReduce(begin, end, reducer, grainSize, numThreads);

inst/include/RcppParallel/Common.h

+26-14
Original file line numberDiff line numberDiff line change
@@ -19,51 +19,63 @@ inline int resolveValue(const char* envvar,
1919

2020
if (useRequestedValue)
2121
return requestedValue;
22-
22+
2323
// otherwise, try reading the default from associated envvar
2424
// if the environment variable is unset, use the default
2525
const char* var = getenv(envvar);
2626
if (var == NULL)
2727
return defaultValue;
28-
28+
2929
// try to convert the string to a number
3030
// if an error occurs during conversion, just use default
3131
errno = 0;
3232
char* end;
3333
long value = strtol(var, &end, 10);
34-
34+
3535
// check for conversion failure
3636
if (end == var || *end != '\0' || errno == ERANGE)
3737
return defaultValue;
38-
39-
// okay, return the parsed environment variable value
38+
39+
// okay, return the parsed environment variable value
4040
return value;
4141
}
4242

43+
// Tag type used for disambiguating splitting constructors
44+
struct Split {};
45+
4346
// Work executed within a background thread. We implement dynamic
4447
// dispatch using vtables so we can have a stable type to cast
4548
// to from the void* passed to the worker thread (required because
4649
// the tinythreads interface allows to pass only a void* to the
4750
// thread main rather than a generic type / template)
48-
49-
struct Worker
50-
{
51+
struct Worker
52+
{
5153
// construct and destruct (delete virtually)
5254
Worker() {}
5355
virtual ~Worker() {}
54-
56+
5557
// dispatch work over a range of values
56-
virtual void operator()(std::size_t begin, std::size_t end) = 0;
57-
58-
// disable copying and assignment
58+
virtual void operator()(std::size_t begin, std::size_t end) = 0;
59+
5960
private:
61+
// disable copying and assignment
6062
Worker(const Worker&);
6163
void operator=(const Worker&);
6264
};
6365

64-
// Tag type used for disambiguating splitting constructors
66+
// Used for controlling the stack size for threads / tasks within a scope.
67+
class ThreadStackSizeControl
68+
{
69+
public:
70+
ThreadStackSizeControl();
71+
~ThreadStackSizeControl();
72+
73+
private:
74+
// COPYING: not copyable
75+
ThreadStackSizeControl(const ThreadStackSizeControl&);
76+
ThreadStackSizeControl& operator=(const ThreadStackSizeControl&);
77+
};
6578

66-
struct Split {};
6779

6880
} // namespace RcppParallel
6981

0 commit comments

Comments
 (0)