-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathmodule.hpp
More file actions
81 lines (60 loc) · 2.23 KB
/
Copy pathmodule.hpp
File metadata and controls
81 lines (60 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#pragma once
#include "../taskflow.hpp"
/**
@file module.hpp
@brief module algorithm include file
*/
namespace tf {
// ----------------------------------------------------------------------------
template <GraphLike T>
auto Algorithm::make_module_task(T& target) {
return [&graph=retrieve_graph(target)](tf::Runtime& rt){
if(graph.empty()) {
return;
}
rt._executor._schedule_graph(rt._worker, graph, rt._node->_topology, rt._node);
};
}
// ----------------------------------------------------------------------------
/**
@brief creates a module task using the given graph
@tparam T type satisfying tf::GraphLike
@param target the target object used to create the module task
@return a module task that can be used by %Taskflow or asynchronous tasking
This example demonstrates how to create and launch multiple taskflows in parallel
using modules with asynchronous tasking:
@code{.cpp}
tf::Executor executor;
tf::Taskflow A;
tf::Taskflow B;
tf::Taskflow C;
tf::Taskflow D;
A.emplace([](){ printf("Taskflow A\n"); });
B.emplace([](){ printf("Taskflow B\n"); });
C.emplace([](){ printf("Taskflow C\n"); });
D.emplace([](){ printf("Taskflow D\n"); });
// launch the four taskflows using asynchronous tasking
executor.async(tf::make_module_task(A));
executor.async(tf::make_module_task(B));
executor.async(tf::make_module_task(C));
executor.async(tf::make_module_task(D));
executor.wait_for_all();
@endcode
The module task maker, tf::make_module_task, is basically the same as tf::Taskflow::composed_of
but provides a more generic interface that can be used beyond %Taskflow.
For instance, the following two approaches achieve the same functionality.
@code{.cpp}
// approach 1: composition using composed_of
tf::Task m1 = taskflow1.composed_of(taskflow2);
// approach 2: composition using make_module_task
tf::Task m1 = taskflow1.emplace(tf::make_module_task(taskflow2));
@endcode
@attention
Users are responsible for ensuring that the given target remains valid throughout its execution.
The executor does not assume ownership of the target object.
*/
template <GraphLike T>
auto make_module_task(T& target) {
return Algorithm::make_module_task(target);
}
} // end of namespact tf -----------------------------------------------------