Skip to content

Commit 9ff12a7

Browse files
committed
allow opt-out from Boost.SIMD
1 parent d5d2cf3 commit 9ff12a7

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

R/build.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ tbbCxxFlags <- function(simd = TRUE) {
4949
flags <- paste(flags, "-DRCPP_PARALLEL_USE_TBB=1")
5050

5151
# reflect requested use of boost::simd
52-
if (isTRUE(simd))
53-
flags <- paste(flags, "-DRCPP_PARALLEL_USE_SIMD=1")
52+
if (!simd)
53+
flags <- paste(flags, "-DRCPP_PARALLEL_USE_SIMD=0")
5454

5555
flags
5656
}

examples/simd-operations.Rmd

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,24 @@ The two `transformDataImpl` functions have the same name, but only one will be c
156156
157157
Note that if you conditionally compile all uses of Boost.SIMD within your package then you can actually drop the `C++11` from `SystemRequirements` (it's no longer required as a result of your fallback implementation).
158158
159+
## Disabling SIMD
159160
161+
If you don't want to use Boost.SIMD at all you can explicitly disable it as follows:
160162
163+
1. For `sourceCpp` you can define `RCPP_PARALLEL_USE_TBB`:
164+
165+
```cpp
166+
#define RCPP_PARALLEL_USE_TBB 0
167+
```
168+
169+
2. For R packages you can pass `simd = FALSE` to the CxxFlags function:
170+
171+
```make
172+
PKG_CXXFLAGS += $(shell ${R_HOME}/bin/Rscript -e "RcppParallel::CxxFlags(simd = FALSE)")
173+
```
174+
175+
176+
161177
162178
163179

inst/include/RcppParallel.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,11 @@ inline void parallelReduce(std::size_t begin, std::size_t end,
5252

5353
} // namespace RcppParallel
5454

55-
// Enable SIMD if requested (requires C++11)
56-
#if RCPP_PARALLEL_USE_SIMD && (__cplusplus <= 199711L)
57-
#undef RCPP_PARALLEL_USE_SIMD
55+
// Auto enable/disable SIMD unless it's been explicitly set (requires C++11)
56+
#ifndef RCPP_PARALLEL_USE_SIMD
57+
#if (__cplusplus > 199711L)
58+
#define RCPP_PARALLEL_USE_SIMD 1
59+
#endif
5860
#endif
5961
#if RCPP_PARALLEL_USE_SIMD
6062
#include "RcppParallel/SIMD.h"

0 commit comments

Comments
 (0)