Skip to content

Commit 88e0d63

Browse files
added work stealing threadpool
1 parent 1637456 commit 88e0d63

File tree

7 files changed

+289
-41
lines changed

7 files changed

+289
-41
lines changed

CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
2727
message(FATAL_ERROR "\nCpp-Taskflow requires MSVC++ at least v14.14")
2828
endif()
2929
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /O2 /W3")
30+
add_definitions(-D_ENABLE_EXTENDED_ALIGNED_STORAGE)
3031
else()
3132
message(FATAL_ERROR "\n\
3233
Cpp-Taskflow currently supports the following compilers:\n\
@@ -190,7 +191,7 @@ add_test(WorkStealingQueue.4Thieves ${TF_UTEST_DIR}/threadpool -tc=WSQ.4Thieves)
190191
add_test(simple_threadpool ${TF_UTEST_DIR}/threadpool -tc=SimpleThreadpool)
191192
add_test(proactive_threadpool ${TF_UTEST_DIR}/threadpool -tc=ProactiveThreadpool)
192193
add_test(speculative_threadpool ${TF_UTEST_DIR}/threadpool -tc=SpeculativeThreadpool)
193-
add_test(privatized_threadpool ${TF_UTEST_DIR}/threadpool -tc=PrivatizedThreadpool)
194+
add_test(work_stealing_threadpool ${TF_UTEST_DIR}/threadpool -tc=WorkStealingThreadpool)
194195

195196
# threadpool_cxx14 unittest (contributed by Glen Fraser)
196197
add_executable(threadpool_cxx14_tmp unittest/threadpool_cxx14.cpp)

example/taskflow.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// 2018/12/04 - modified by Tsung-Wei Huang
2+
// - replaced privatized threadpool with work stealing threadpool
3+
//
14
// 2018/10/24 - modified by Tsung-Wei Huang
25
// - Taskflow is templated at threadpool
36
// - added graph-level comparison with different thread pools
@@ -16,20 +19,20 @@
1619
#define BENCHMARK(TITLE, F) \
1720
std::cout << "========== " << TITLE << " ==========\n"; \
1821
\
19-
std::cout << "Taskflow [simple executor ]: " \
22+
std::cout << "Taskflow [simple executor ]: " \
2023
<< F<tf::BasicTaskflow<tf::SimpleThreadpool>>() \
2124
<< " ms\n"; \
2225
\
23-
std::cout << "Taskflow [practive executor ]: " \
26+
std::cout << "Taskflow [practive executor ]: " \
2427
<< F<tf::BasicTaskflow<tf::ProactiveThreadpool>>() \
2528
<< " ms\n"; \
2629
\
27-
std::cout << "Taskflow [speculative executor]: " \
30+
std::cout << "Taskflow [speculative executor ]: " \
2831
<< F<tf::BasicTaskflow<tf::SpeculativeThreadpool>>() \
2932
<< " ms\n"; \
3033
\
31-
std::cout << "Taskflow [privatized executor]: " \
32-
<< F<tf::BasicTaskflow<tf::PrivatizedThreadpool>>() \
34+
std::cout << "Taskflow [work stealing executor]: " \
35+
<< F<tf::BasicTaskflow<tf::WorkStealingThreadpool>>() \
3336
<< " ms\n"; \
3437

3538
// ============================================================================

example/threadpool.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// 2018/12/04 modified by Tsung-Wei Huang
2+
// - replace privatized threadpool with work stealing threadpool
3+
//
14
// 2018/10/04 modified by Tsung-Wei Huang
25
// - removed binary_tree
36
// - removed modulo_insertions
@@ -35,8 +38,8 @@
3538
std::cout << "SpeculativeThreadpool elapsed time: " \
3639
<< F<tf::SpeculativeThreadpool<std::function<void()>>>() << " ms\n"; \
3740
\
38-
std::cout << "PrivatizedThreadpool elapsed time: " \
39-
<< F<tf::PrivatizedThreadpool<std::function<void()>>>() << " ms\n"; \
41+
std::cout << "WorkStealingThreadpool elapsed time: " \
42+
<< F<tf::WorkStealingThreadpool<std::function<void()>>>() << " ms\n"; \
4043

4144
// ============================================================================
4245
// Divide and conquer to solve max subarray sum problem

taskflow/graph/basic_taskflow.hpp

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,10 @@ class BasicTaskflow : public FlowBuilder {
1818
struct Closure {
1919

2020
Closure() = default;
21-
Closure(const Closure&) = delete;
22-
Closure(Closure&&);
21+
Closure(const Closure&);
2322
Closure(BasicTaskflow&, Node&);
2423

25-
Closure& operator = (Closure&&);
26-
Closure& operator = (const Closure&) = delete;
24+
Closure& operator = (const Closure&);
2725

2826
void operator ()() const;
2927

@@ -83,10 +81,8 @@ class BasicTaskflow : public FlowBuilder {
8381

8482
// Constructor
8583
template <template <typename...> typename E>
86-
BasicTaskflow<E>::Closure::Closure(Closure&& rhs) :
84+
BasicTaskflow<E>::Closure::Closure(const Closure& rhs) :
8785
taskflow {rhs.taskflow}, node {rhs.node} {
88-
rhs.taskflow = nullptr;
89-
rhs.node = nullptr;
9086
}
9187

9288
// Constructor
@@ -95,13 +91,11 @@ BasicTaskflow<E>::Closure::Closure(BasicTaskflow& t, Node& n) :
9591
taskflow{&t}, node {&n} {
9692
}
9793

98-
// Move assignment
94+
// copy assignment
9995
template <template <typename...> typename E>
100-
typename BasicTaskflow<E>::Closure& BasicTaskflow<E>::Closure::operator = (Closure&& rhs) {
96+
typename BasicTaskflow<E>::Closure& BasicTaskflow<E>::Closure::operator = (const Closure& rhs) {
10197
taskflow = rhs.taskflow;
10298
node = rhs.node;
103-
rhs.taskflow = nullptr;
104-
rhs.node = nullptr;
10599
return *this;
106100
}
107101

taskflow/taskflow.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44

55
namespace tf {
66

7-
//using Taskflow = BasicTaskflow<SpeculativeThreadpool>;
8-
using Taskflow = BasicTaskflow<PrivatizedThreadpool>;
7+
using Taskflow = BasicTaskflow<WorkStealingThreadpool>;
98

109
}; // end of namespace tf. ---------------------------------------------------
1110

0 commit comments

Comments
 (0)