Skip to content

Commit 8964f98

Browse files
committed
no more inline stack size control
1 parent e12afd6 commit 8964f98

File tree

4 files changed

+57
-44
lines changed

4 files changed

+57
-44
lines changed

RcppParallel.Rproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
Version: 1.0
2+
ProjectId: f1ae2e5b-eb1d-4d93-9ae1-29e364a5eaa6
23

34
RestoreWorkspace: No
45
SaveWorkspace: No

inst/include/RcppParallel/Common.h

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff 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-
4544
struct 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-
6260
struct 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

inst/include/RcppParallel/TBB.h

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313

1414
namespace RcppParallel {
1515

16-
namespace {
17-
1816
struct 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-
227185
inline void tbbParallelFor(std::size_t begin,
228186
std::size_t end,
229187
Worker& worker,

src/tbb.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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

0 commit comments

Comments
 (0)