File tree Expand file tree Collapse file tree 4 files changed +57
-44
lines changed
inst/include/RcppParallel Expand file tree Collapse file tree 4 files changed +57
-44
lines changed Original file line number Diff line number Diff line change 11Version: 1.0
2+ ProjectId: f1ae2e5b-eb1d-4d93-9ae1-29e364a5eaa6
23
34RestoreWorkspace: No
45SaveWorkspace: No
Original file line number Diff line number Diff line change @@ -41,7 +41,6 @@ inline int resolveValue(const char* envvar,
4141// to from the void* passed to the worker thread (required because
4242// the tinythreads interface allows to pass only a void* to the
4343// thread main rather than a generic type / template)
44-
4544struct Worker
4645{
4746 // construct and destruct (delete virtually)
@@ -58,9 +57,22 @@ struct Worker
5857};
5958
6059// Tag type used for disambiguating splitting constructors
61-
6260struct Split {};
6361
62+ // Used for controlling the stack size for threads / tasks within a scope.
63+ class ThreadStackSizeControl
64+ {
65+ public:
66+ ThreadStackSizeControl ();
67+ ~ThreadStackSizeControl ();
68+
69+ private:
70+ // COPYING: not copyable
71+ ThreadStackSizeControl (const ThreadStackSizeControl&);
72+ ThreadStackSizeControl& operator =(const ThreadStackSizeControl&);
73+ };
74+
75+
6476} // namespace RcppParallel
6577
6678
Original file line number Diff line number Diff line change 1313
1414namespace RcppParallel {
1515
16- namespace {
17-
1816struct TBBWorker
1917{
2018 explicit TBBWorker (Worker& worker) : worker_(worker) {}
@@ -184,46 +182,6 @@ class TBBArenaParallelReduceExecutor
184182 std::size_t grainSize_;
185183};
186184
187- class ThreadStackSizeControl
188- {
189- public:
190-
191- ThreadStackSizeControl ()
192- : control_(nullptr )
193- {
194- int stackSize = resolveValue (" RCPP_PARALLEL_STACK_SIZE" , 0 , 0 );
195- if (stackSize > 0 )
196- {
197- control_ = new tbb::global_control (
198- tbb::global_control::thread_stack_size,
199- stackSize
200- );
201- }
202- }
203-
204- ~ThreadStackSizeControl ()
205- {
206- if (control_ != nullptr )
207- {
208- delete control_;
209- control_ = nullptr ;
210- }
211- }
212-
213- private:
214-
215- // COPYING: not copyable
216- ThreadStackSizeControl (const ThreadStackSizeControl&);
217- ThreadStackSizeControl& operator =(const ThreadStackSizeControl&);
218-
219- // private members
220- tbb::global_control* control_;
221-
222- };
223-
224- } // anonymous namespace
225-
226-
227185inline void tbbParallelFor (std::size_t begin,
228186 std::size_t end,
229187 Worker& worker,
Original file line number Diff line number Diff line change 1+
2+
3+ #include < RcppParallel/Common.h>
4+
5+ #ifndef TBB_PREVIEW_GLOBAL_CONTROL
6+ # define TBB_PREVIEW_GLOBAL_CONTROL 1
7+ #endif
8+
9+ #include < tbb/tbb.h>
10+ #include < tbb/global_control.h>
11+ #include < tbb/scalable_allocator.h>
12+
13+ namespace RcppParallel {
14+
15+ tbb::global_control* s_globalControl = nullptr ;
16+
17+ ThreadStackSizeControl::ThreadStackSizeControl ()
18+ {
19+ #ifdef RCPP_PARALLEL_USE_TBB
20+ int stackSize = resolveValue (" RCPP_PARALLEL_STACK_SIZE" , 0 , 0 );
21+ if (stackSize > 0 )
22+ {
23+ s_globalControl = new tbb::global_control (
24+ tbb::global_control::thread_stack_size,
25+ stackSize
26+ );
27+ }
28+ #endif
29+ }
30+
31+ ThreadStackSizeControl::~ThreadStackSizeControl ()
32+ {
33+ #ifdef RCPP_PARALLEL_USE_TBB
34+ if (s_globalControl != nullptr )
35+ {
36+ delete s_globalControl;
37+ s_globalControl = nullptr ;
38+ }
39+ #endif
40+ }
41+
42+ } // end namespace RcppParallel
You can’t perform that action at this time.
0 commit comments