Skip to content

Commit db3517d

Browse files
committed
Various refinements to Boost.SIMD implementation
- Opt-in via preprocessor variable (RCPP_PARALLEL_USE_SIMD) rather then dedicated include. This is more clear and enables dynamic use of SIMD where available with a fallback where it's not. - Introduce LdFlags and CxxFlags functions for dynamic configuration from Makevars (more consistent with other packages in the Rcpp family) - Remove explicit -mtune= (I found no difference between mtune=native and mtune=core2 on OS X). In any case this is really the business of the particular installation of R rather than an individual package. - Add option to disable RStudio clang indexing to .Rprofile (expression templates are too much for the indexing engine).
1 parent b21daa8 commit db3517d

16 files changed

+188
-64
lines changed

.Rbuildignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
^.*\.Rproj$
22
^\.Rproj\.user$
3+
^\.Rprofile$
34
^src/tbb/build/lib_.*$
45
^tests/testthat/pkg/RcppParallelTest/src/.*\.s?o$
56
^tests/testthat/pkg/RcppParallelTest/src/.*\.dll$
@@ -8,4 +9,4 @@
89
^README.md
910
^doc$
1011
^src/.*\.o$
11-
^examples/
12+
^examples/

DESCRIPTION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Description: High level functions for doing parallel programming with 'Rcpp'.
1818
For example, the parallelFor() function can be used to convert the work of
1919
a standard serial "for" loop into a parallel one and the parallelReduce()
2020
function can be used for accumulating aggregate or other values.
21+
Depends: R (>= 3.0.2)
2122
Suggests:
2223
Rcpp,
2324
RUnit,

R/build.R

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,36 @@
11

22

3+
# Output the CXX flags. These flags are propagated to sourceCpp via the
4+
# inlineCxxPlugin (defined below) and to packages via a line in Makevars[.win]
5+
# like this:
6+
#
7+
# PKG_CXXFLAGS += $(shell "${R_HOME}/bin${R_ARCH_BIN}/Rscript.exe" -e "RcppParallel::CxxFlags()")
8+
#
9+
CxxFlags <- function(simd = FALSE) {
10+
cat(tbbCxxFlags(simd = simd))
11+
}
12+
13+
314
# Output the LD flags for building against TBB. These flags are propagated
415
# to sourceCpp via the inlineCxxPlugin (defined below) and to packages
5-
# via a line in Makevars.win like this:
16+
# via a line in Makevars[.win] like this:
617
#
718
# PKG_LIBS += $(shell "${R_HOME}/bin${R_ARCH_BIN}/Rscript.exe" -e "RcppParallel::LdFlags()")
819
#
9-
# Note that this is only required for Windows builds (on Linux and OS X no
10-
# explicit link to TBB is required).
11-
RcppParallelLibs <- function() {
20+
LdFlags <- function() {
1221
cat(tbbLdFlags())
1322
}
1423

24+
# alias for backward compatibility
25+
RcppParallelLibs <- function() {
26+
LdFlags()
27+
}
1528

16-
# Inline plugin used by sourceCpp to link to the TBB library
29+
# Inline plugin used by sourceCpp.
1730
inlineCxxPlugin <- function() {
1831
list(
1932
env = list(
20-
PKG_CXXFLAGS = paste(tbbCxxFlags(), mtuneFlags()),
33+
PKG_CXXFLAGS = paste(tbbCxxFlags()),
2134
PKG_LIBS = tbbLdFlags()
2235
),
2336
includes = "#include <RcppParallel.h>",
@@ -27,19 +40,19 @@ inlineCxxPlugin <- function() {
2740
)
2841
}
2942

30-
mtuneFlags <- function() {
31-
switch(Sys.info()[["sysname"]],
32-
"Linux" = "-mtune=native",
33-
"Darwin" = "-mtune=core2",
34-
"Windows" = "-mtune=core2",
35-
""
36-
)
37-
}
38-
39-
tbbCxxFlags <- function() {
43+
tbbCxxFlags <- function(simd = FALSE) {
44+
45+
# request use of C++11 when possible
4046
flags <- "$(CXX1XSTD)"
47+
48+
# opt-in to TBB on Windows
4149
if (Sys.info()['sysname'] == "Windows")
4250
flags <- paste(flags, "-DRCPP_PARALLEL_USE_TBB=1")
51+
52+
# reflect requested use of boost::simd
53+
if (isTRUE(simd))
54+
flags <- paste(flags, "-DRCPP_PARALLEL_USE_SIMD=1")
55+
4356
flags
4457
}
4558

examples/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.html

examples/boost-simd-abssum.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// [[Rcpp::depends(RcppParallel)]]
2-
#include <RcppParallelSIMD.h>
2+
#define RCPP_PARALLEL_USE_SIMD 1
3+
#include <RcppParallel.h>
34
#include <Rcpp.h>
45
using namespace Rcpp;
56

examples/boost-simd-accumulate.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// [[Rcpp::depends(RcppParallel)]]
2-
#include <RcppParallelSIMD.h>
2+
#define RCPP_PARALLEL_USE_SIMD 1
3+
#include <RcppParallel.h>
34
#include <Rcpp.h>
45
using namespace Rcpp;
56

examples/boost-simd-capabilities.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// [[Rcpp::depends(RcppParallel)]]
2-
#include <RcppParallelSIMD.h>
2+
#define RCPP_PARALLEL_USE_SIMD 1
3+
#include <RcppParallel.h>
34
#include <Rcpp.h>
45
using namespace Rcpp;
56

examples/boost-simd-dot.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// [[Rcpp::depends(RcppParallel)]]
2-
#include <RcppParallelSIMD.h>
2+
#define RCPP_PARALLEL_USE_SIMD 1
3+
#include <RcppParallel.h>
34
#include <Rcpp.h>
45
using namespace Rcpp;
56

examples/boost-simd-hello-world.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// [[Rcpp::depends(RcppParallel)]]
2-
#include <RcppParallelSIMD.h>
2+
#define RCPP_PARALLEL_USE_SIMD 1
3+
#include <RcppParallel.h>
34
#include <Rcpp.h>
45
using namespace Rcpp;
56

examples/boost-simd-transform.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// [[Rcpp::depends(RcppParallel)]]
2-
#include <RcppParallelSIMD.h>
2+
#define RCPP_PARALLEL_USE_SIMD 1
3+
#include <RcppParallel.h>
34
#include <Rcpp.h>
45
using namespace Rcpp;
56

0 commit comments

Comments
 (0)