-
Notifications
You must be signed in to change notification settings - Fork 59
Expand file tree
/
Copy pathRcppParallel.h
More file actions
55 lines (41 loc) · 1.43 KB
/
RcppParallel.h
File metadata and controls
55 lines (41 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
#ifndef __RCPP_PARALLEL__
#define __RCPP_PARALLEL__
// TinyThread implementation
#include "RcppParallel/TinyThread.h"
// Use TBB only where it's known to compile and work correctly
// (NOTE: Windows TBB is temporarily opt-in for packages for
// compatibility with CRAN packages not previously configured
// to link to TBB in Makevars.win)
#ifndef RCPP_PARALLEL_USE_TBB
#if defined(__APPLE__) || defined(__gnu_linux__) || ((defined(__sun) && defined(__SVR4) && !defined(__sparc)))
#define RCPP_PARALLEL_USE_TBB 1
#include "RcppParallel/TBB.h"
#else
#define RCPP_PARALLEL_USE_TBB 0
#endif
#endif
#if RCPP_PARALLEL_USE_TBB
#include "RcppParallel/TBB.h"
#endif
#include "RcppParallel/RVector.h"
#include "RcppParallel/RMatrix.h"
namespace RcppParallel {
inline void parallelFor(std::size_t begin, std::size_t end,
Worker& worker, std::size_t grainSize = 1) {
#if RCPP_PARALLEL_USE_TBB
tbbParallelFor(begin, end, worker, grainSize);
#else
ttParallelFor(begin, end, worker, grainSize);
#endif
}
template <typename Reducer>
inline void parallelReduce(std::size_t begin, std::size_t end,
Reducer& reducer, std::size_t grainSize = 1) {
#if RCPP_PARALLEL_USE_TBB
tbbParallelReduce(begin, end, reducer, grainSize);
#else
ttParallelReduce(begin, end, reducer, grainSize);
#endif
}
} // namespace RcppParallel
#endif // __RCPP_PARALLEL__