| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent e24e076 commit 590bc1e
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -106,7 +106,7 @@ int main(){ | |||
| 106 | 106 | B.precede(D); // B runs before D // | +---+ | | |
| 107 | 107 | C.precede(D); // C runs before D // +---->| C |-----+ | |
| 108 | 108 | // +---+ | |
| 109 | - executor.run(taskflow); | ||
| 109 | + executor.run(taskflow).get(); | ||
| 110 | 110 | ||
| 111 | 111 | return 0; | |
| 112 | 112 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,29 +1,38 @@ | |||
| 1 | + // This program demonstrates how to use cpp-taskflow to | ||
| 2 | + // write loop-based parallelism. | ||
| 3 | + | ||
| 1 | 4 | #include <taskflow/taskflow.hpp> | |
| 2 | 5 | #include <cassert> | |
| 3 | 6 | #include <numeric> | |
| 4 | 7 | ||
| 5 | 8 | // Procedure: parallel_for_on_range | |
| 6 | 9 | void parallel_for_on_range(int N) { | |
| 7 | 10 | ||
| 11 | + tf::Executor executor; | ||
| 12 | + tf::Taskflow taskflow; | ||
| 13 | + | ||
| 8 | 14 | std::vector<int> range(N); | |
| 9 | 15 | std::iota(range.begin(), range.end(), 0); | |
| 10 | 16 | ||
| 11 | - tf::Taskflow tf; | ||
| 12 | - tf.parallel_for(range.begin(), range.end(), [&] (const int i) { | ||
| 17 | + taskflow.parallel_for(range.begin(), range.end(), [&] (const int i) { | ||
| 13 | 18 | printf("parallel_for on container item: %d\n", i); | |
| 14 | 19 | }); | |
| 15 | - tf::Executor().run(tf); | ||
| 20 | + | ||
| 21 | + executor.run(taskflow).get(); | ||
| 16 | 22 | } | |
| 17 | 23 | ||
| 18 | 24 | // Procedure: parallel_for_on_index | |
| 19 | 25 | void parallel_for_on_index(int N) { | |
| 20 | - tf::Taskflow tf; | ||
| 26 | + | ||
| 27 | + tf::Executor executor; | ||
| 28 | + tf::Taskflow taskflow; | ||
| 21 | 29 | ||
| 22 | 30 | // [0, N) with step size 1 | |
| 23 | - tf.parallel_for(0, N, 1, [] (int i) { | ||
| 31 | + taskflow.parallel_for(0, N, 1, [] (int i) { | ||
| 24 | 32 | printf("parallel_for on index: %d\n", i); | |
| 25 | 33 | }); | |
| 26 | - tf::Executor().run(tf); | ||
| 34 | + | ||
| 35 | + executor.run(taskflow).get(); | ||
| 27 | 36 | } | |
| 28 | 37 | ||
| 29 | 38 | // ---------------------------------------------------------------------------- | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,11 +1,5 @@ | |||
| 1 | - // 2019/05/14 - modified by Tsung-Wei Huang | ||
| 2 | - // - isolated executor from taskflow | ||
| 3 | - // | ||
| 4 | - // 2019/02/15 - modified by Tsung-Wei Huang | ||
| 5 | - // - refactored the code | ||
| 6 | - // | ||
| 7 | - // 2019/01/17 - created by Chun-Xun | ||
| 8 | - // - added example of using the Framework | ||
| 1 | + // This example demonstrates how to use different methods to | ||
| 2 | + // run a taskflow object. | ||
| 9 | 3 | ||
| 10 | 4 | #include <taskflow/taskflow.hpp> | |
| 11 | 5 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,7 +6,8 @@ | |||
| 6 | 6 | #include <taskflow/taskflow.hpp> // the only include you need | |
| 7 | 7 | ||
| 8 | 8 | int main(){ | |
| 9 | - | ||
| 9 | + | ||
| 10 | + tf::Executor executor; | ||
| 10 | 11 | tf::Taskflow taskflow; | |
| 11 | 12 | ||
| 12 | 13 | auto [A, B, C, D] = taskflow.emplace( | |
@@ -21,7 +22,7 @@ int main(){ | |||
| 21 | 22 | B.precede(D); // D runs after B // +---->| C |-----+ | |
| 22 | 23 | C.precede(D); // D runs after C // +---+ | |
| 23 | 24 | ||
| 24 | - tf::Executor().run(taskflow); // create an executor to run the taskflow | ||
| 25 | + executor.run(taskflow).get(); | ||
| 25 | 26 | ||
| 26 | 27 | return 0; | |
| 27 | 28 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments