Skip to content

Commit c0d6f55

Browse files
committed
Merge branch 'master' of github.com:jjallaire/RcppParallel
2 parents c14c8a8 + f4e34fd commit c0d6f55

File tree

4 files changed

+38
-16
lines changed

4 files changed

+38
-16
lines changed

R/options.R

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@
33
dllInfo <- NULL
44

55
.onLoad <- function(libname, pkgname) {
6-
7-
# load tbb and make it's symbols available globally
6+
7+
# load tbb if we aren't on windows
88
sysname <- Sys.info()['sysname']
9-
if (sysname == "Darwin")
10-
ext = ".dylib"
11-
else if (sysname == "Linux")
12-
ext = ".so.2"
13-
else if (sysname == "Windows")
14-
ext = ".dll"
15-
else
16-
ext = .Platform$dynlib.ext
17-
dll <- system.file(paste("lib/libtbb", ext, sep = ""), package = "RcppParallel")
18-
dllInfo <<- dyn.load(dll, local = FALSE, now = TRUE)
9+
if (sysname != "Windows") {
10+
if (sysname == "Darwin")
11+
ext = ".dylib"
12+
else if (sysname == "Linux")
13+
ext = ".so.2"
14+
else
15+
ext = .Platform$dynlib.ext
16+
dll <- system.file(paste("lib/libtbb", ext, sep = ""), package = "RcppParallel")
17+
dllInfo <<- dyn.load(dll, local = FALSE, now = TRUE)
18+
}
1919

2020
# load the package library
2121
library.dynam("RcppParallel", pkgname, libname)
@@ -29,8 +29,9 @@ dllInfo <- NULL
2929
# unload the package library
3030
library.dynam.unload("RcppParallel", libpath)
3131

32-
# unload tbb
33-
dyn.unload(dllInfo[["path"]])
32+
# unload tbb if we loaded it (i.e. aren't on windows)
33+
if (!is.null(dllInfo))
34+
dyn.unload(dllInfo[["path"]])
3435
}
3536

3637
setThreadOptions <- function(numThreads = "auto", stackSize = "auto") {

src/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
*.o
22
*.so
3+
*.dll

src/Makevars.win

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
PKG_CPPFLAGS += -I../inst/include/
3+
4+

src/tbb.cpp renamed to src/options.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11

2+
#include <Rinternals.h>
3+
4+
#ifndef _WIN32
5+
26
#include <string>
37
#include <exception>
48

59
#include <tbb/task_scheduler_init.h>
610

7-
#include <Rinternals.h>
8-
911
extern "C" SEXP setThreadOptions(SEXP numThreadsSEXP, SEXP stackSizeSEXP) {
1012

1113
static tbb::task_scheduler_init* s_pTaskScheduler = NULL;
@@ -40,3 +42,17 @@ extern "C" SEXP defaultNumThreads() {
4042
INTEGER(threadsSEXP)[0] = tbb::task_scheduler_init::default_num_threads();
4143
return threadsSEXP;
4244
}
45+
46+
#else
47+
48+
extern "C" SEXP setThreadOptions(SEXP numThreadsSEXP, SEXP stackSizeSEXP) {
49+
return R_NilValue;
50+
}
51+
52+
extern "C" SEXP defaultNumThreads() {
53+
SEXP threadsSEXP = Rf_allocVector(INTSXP, 1);
54+
INTEGER(threadsSEXP)[0] = 4;
55+
return threadsSEXP;
56+
}
57+
58+
#endif

0 commit comments

Comments
 (0)