File: RcppParallel.h

package info (click to toggle)
r-cran-rcppparallel 5.1.7%2Bdfsg-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 544 kB
  • sloc: cpp: 1,852; sh: 19; makefile: 11
file content (72 lines) | stat: -rw-r--r-- 2,172 bytes parent folder | download | duplicates (2)
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
63
64
65
66
67
68
69
70
71
72

#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
# else
#  define RCPP_PARALLEL_USE_TBB 0
# endif
#endif

#if RCPP_PARALLEL_USE_TBB
# include "RcppParallel/TBB.h"
#endif

#include "RcppParallel/Backend.h"

#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,
                        int numThreads = -1)
{
   grainSize = resolveValue("RCPP_PARALLEL_GRAIN_SIZE", grainSize, 1u);
   numThreads = resolveValue("RCPP_PARALLEL_NUM_THREADS", numThreads, -1);
   
#if RCPP_PARALLEL_USE_TBB
   if (internal::backend() == internal::BACKEND_TBB)
      tbbParallelFor(begin, end, worker, grainSize, numThreads);
   else
      ttParallelFor(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,
                           int numThreads = -1)
{
   grainSize = resolveValue("RCPP_PARALLEL_GRAIN_SIZE", grainSize, 1);
   numThreads = resolveValue("RCPP_PARALLEL_NUM_THREADS", numThreads, -1);
   
#if RCPP_PARALLEL_USE_TBB
   if (internal::backend() == internal::BACKEND_TBB)
      tbbParallelReduce(begin, end, reducer, grainSize, numThreads);
   else
      ttParallelReduce(begin, end, reducer, grainSize);
#else
   ttParallelReduce(begin, end, reducer, grainSize);
#endif
}

} // end namespace RcppParallel

#endif // __RCPP_PARALLEL__