-
Notifications
You must be signed in to change notification settings - Fork 59
Expand file tree
/
Copy pathoptions.cpp
More file actions
62 lines (45 loc) · 1.43 KB
/
options.cpp
File metadata and controls
62 lines (45 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <RcppParallel.h>
#include <Rinternals.h>
#if RCPP_PARALLEL_USE_TBB // TBB support turned on
#include <string>
#include <exception>
#include <tbb/task_scheduler_init.h>
extern "C" SEXP setThreadOptions(SEXP numThreadsSEXP, SEXP stackSizeSEXP) {
static tbb::task_scheduler_init* s_pTaskScheduler = NULL;
int numThreads = Rf_asInteger(numThreadsSEXP);
int stackSize = Rf_asInteger(stackSizeSEXP);
try
{
if (!s_pTaskScheduler) {
s_pTaskScheduler = new tbb::task_scheduler_init(numThreads, stackSize);
} else {
s_pTaskScheduler->terminate();
s_pTaskScheduler->initialize(numThreads, stackSize);
}
}
catch(const std::exception& e)
{
Rf_error(("Error loading TBB: " + std::string(e.what())).c_str());
}
catch(...)
{
Rf_error("Error loading TBB: (Unknown error)");
}
return R_NilValue;
}
extern "C" SEXP defaultNumThreads() {
SEXP threadsSEXP = Rf_allocVector(INTSXP, 1);
INTEGER(threadsSEXP)[0] = tbb::task_scheduler_init::default_num_threads();
return threadsSEXP;
}
#else // TBB support not turned on
#include <tthread/tinythread.h>
extern "C" SEXP setThreadOptions(SEXP numThreadsSEXP, SEXP stackSizeSEXP) {
return R_NilValue;
}
extern "C" SEXP defaultNumThreads() {
SEXP threadsSEXP = Rf_allocVector(INTSXP, 1);
INTEGER(threadsSEXP)[0] = tthread::thread::hardware_concurrency();
return threadsSEXP;
}
#endif