| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent d6fdc1c commit b93349f
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,25 +8,25 @@ | |||
| 8 | 8 | #include <random> | |
| 9 | 9 | #include <climits> | |
| 10 | 10 | ||
| 11 | - using tf_simple_t = tf::BasicTaskflow<std::function, tf::SimpleThreadpool>; | ||
| 12 | - using tf_proactive_t = tf::BasicTaskflow<std::function, tf::ProactiveThreadpool>; | ||
| 13 | - using tf_speculative_t = tf::BasicTaskflow<std::function, tf::SpeculativeThreadpool>; | ||
| 14 | - using tf_privatized_t = tf::BasicTaskflow<std::function, tf::PrivatizedThreadpool>; | ||
| 11 | + using tf_simple_t = tf::BasicTaskflow<tf::SimpleThreadpool>; | ||
| 12 | + using tf_proactive_t = tf::BasicTaskflow<tf::ProactiveThreadpool>; | ||
| 13 | + using tf_speculative_t = tf::BasicTaskflow<tf::SpeculativeThreadpool>; | ||
| 14 | + using tf_privatized_t = tf::BasicTaskflow<tf::PrivatizedThreadpool>; | ||
| 15 | 15 | ||
| 16 | 16 | // Procedure: benchmark | |
| 17 | 17 | #define BENCHMARK(TITLE, F) \ | |
| 18 | 18 | std::cout << "========== " << TITLE << " ==========\n"; \ | |
| 19 | 19 | \ | |
| 20 | - std::cout << "Taskflow [simple + std::func] elapsed time: " \ | ||
| 20 | + std::cout << "Taskflow [simple ] elapsed time: " \ | ||
| 21 | 21 | << F<tf_simple_t>() << " ms\n"; \ | |
| 22 | 22 | \ | |
| 23 | - std::cout << "Taskflow [proactive + std::func] elapsed time: " \ | ||
| 23 | + std::cout << "Taskflow [proactive ] elapsed time: " \ | ||
| 24 | 24 | << F<tf_proactive_t>() << " ms\n"; \ | |
| 25 | 25 | \ | |
| 26 | - std::cout << "Taskflow [speculative + std::func] elapsed time: " \ | ||
| 26 | + std::cout << "Taskflow [speculative] elapsed time: " \ | ||
| 27 | 27 | << F<tf_speculative_t>() << " ms\n"; \ | |
| 28 | 28 | \ | |
| 29 | - std::cout << "Taskflow [privatized + std::func] elapsed time: " \ | ||
| 29 | + std::cout << "Taskflow [privatized ] elapsed time: " \ | ||
| 30 | 30 | << F<tf_privatized_t>() << " ms\n"; \ | |
| 31 | 31 | ||
| 32 | 32 | // ============================================================================ | |
@@ -97,7 +97,7 @@ auto map_reduce() { | |||
| 97 | 97 | ||
| 98 | 98 | T tf; | |
| 99 | 99 | ||
| 100 | - std::optional<typename T::Task> prev; | ||
| 100 | + std::optional<tf::Task> prev; | ||
| 101 | 101 | ||
| 102 | 102 | for(int i=0; i<num_batches; ++i) { | |
| 103 | 103 | ||
@@ -138,7 +138,7 @@ auto level_graph() { | |||
| 138 | 138 | ||
| 139 | 139 | T tf; | |
| 140 | 140 | ||
| 141 | - std::vector< std::vector<typename T::Task> > tasks; | ||
| 141 | + std::vector< std::vector<tf::Task> > tasks; | ||
| 142 | 142 | ||
| 143 | 143 | tasks.resize(num_levels); | |
| 144 | 144 | for(int l=0; l<num_levels; ++l) { | |
@@ -183,7 +183,7 @@ auto linear_graph() { | |||
| 183 | 183 | ||
| 184 | 184 | T tf; | |
| 185 | 185 | ||
| 186 | - std::vector<typename T::Task> tasks; | ||
| 186 | + std::vector<tf::Task> tasks; | ||
| 187 | 187 | ||
| 188 | 188 | for(int i=0; i<num_nodes; ++i) { | |
| 189 | 189 | tasks.push_back(tf.silent_emplace([&] () { ++sum; })); | |
@@ -214,9 +214,9 @@ auto binary_tree() { | |||
| 214 | 214 | T tf; | |
| 215 | 215 | ||
| 216 | 216 | std::atomic<size_t> sum {0}; | |
| 217 | - std::function<void(int, typename T::Task)> insert; | ||
| 217 | + std::function<void(int, tf::Task)> insert; | ||
| 218 | 218 | ||
| 219 | - insert = [&] (int l, typename T::Task parent) { | ||
| 219 | + insert = [&] (int l, tf::Task parent) { | ||
| 220 | 220 | ||
| 221 | 221 | if(l < num_levels) { | |
| 222 | 222 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -316,15 +316,52 @@ auto atomic_add() { | |||
| 316 | 316 | ||
| 317 | 317 | // ---------------------------------------------------------------------------- | |
| 318 | 318 | ||
| 319 | + struct Work { | ||
| 320 | + | ||
| 321 | + Work() { | ||
| 322 | + } | ||
| 323 | + | ||
| 324 | + Work(std::atomic<int>& in) : ptr {&in} { | ||
| 325 | + } | ||
| 326 | + | ||
| 327 | + std::atomic<int>* ptr {nullptr}; | ||
| 328 | + | ||
| 329 | + void operator () () { | ||
| 330 | + ptr->fetch_add(1, std::memory_order_relaxed); | ||
| 331 | + } | ||
| 332 | + }; | ||
| 333 | + | ||
| 334 | + void test_work() { | ||
| 335 | + | ||
| 336 | + const int num_threads = std::thread::hardware_concurrency(); | ||
| 337 | + const int num_tasks = 1000000; | ||
| 338 | + | ||
| 339 | + std::atomic<int> counter(0); | ||
| 340 | + auto beg = std::chrono::high_resolution_clock::now(); | ||
| 341 | + | ||
| 342 | + tf::SimpleThreadpool2<Work> threadpool(num_threads); | ||
| 343 | + for(size_t i=0; i<num_tasks; i++){ | ||
| 344 | + threadpool.emplace(counter); | ||
| 345 | + } | ||
| 346 | + | ||
| 347 | + auto end = std::chrono::high_resolution_clock::now(); | ||
| 348 | + std::cout << std::chrono::duration_cast<std::chrono::milliseconds>(end - beg).count() | ||
| 349 | + << " ms... " << counter << '\n'; | ||
| 350 | + } | ||
| 351 | + | ||
| 319 | 352 | // Function: main | |
| 320 | 353 | int main(int argc, char* argv[]) { | |
| 321 | 354 | ||
| 355 | + test_work(); | ||
| 356 | + | ||
| 322 | 357 | BENCHMARK("Atomic Add", atomic_add); | |
| 323 | 358 | BENCHMARK("Empty Jobs", empty_jobs); | |
| 324 | 359 | BENCHMARK("Linear Insertions", linear_insertions); | |
| 325 | 360 | BENCHMARK("Modulo Insertions", modulo_insertions); | |
| 326 | 361 | BENCHMARK("Binary Tree", binary_tree); | |
| 327 | 362 | BENCHMARK("Divide and Conquer", subsum); | |
| 363 | + | ||
| 364 | + | ||
| 328 | 365 | ||
| 329 | 366 | return 0; | |
| 330 | 367 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments