<para>Taskflow provides template methods that let users create reusable building blocks called <emphasis>modules</emphasis>. Users can connect modules together to build more complex parallel algorithms.</para>
<title>Include the Header</title><para>You need to include the header file, <computeroutput><refrefid="module_8hpp_source"kindref="compound">taskflow/algorithm/module.hpp</ref></computeroutput>, for creating a module task over a schedulable graph target.</para>
<title>What is a Module Task</title><para>Similar to <refrefid="ComposableTasking"kindref="compound">Composable Tasking</ref>, but in a more generic setting, the template function, <refrefid="namespacetf_1aae281ad3b89a5c421a1f4058f425e54c"kindref="member">tf::make_module_task</ref>, allows you to create a task over a taskflow graph that can be executed by an executor. This provides a flexible way to encapsulate and reuse complex task logic within your Taskflow applications. The example below demonstrates how to create and launch multiple taskflows in parallel using asynchronous tasking:</para>
<para>Since the four taskflows are launched asynchronously without any dependencies between them, we can observe any order of the output message:</para>
<para>If you need to enforce dependencies among these four taskflows, you can use dependent-async tasks. The example below launches the four taskflows one by one in sequential:</para>
<para>The module task maker, <refrefid="namespacetf_1aae281ad3b89a5c421a1f4058f425e54c"kindref="member">tf::make_module_task</ref>, functions basically similar to <refrefid="classtf_1_1FlowBuilder_1ac6f22228d4c2ea2e643c4b0d42c0e92a"kindref="member">tf::Taskflow::composed_of</ref> but provides a more generic interface that can be used beyond Taskflow. Specifically, the following two approaches achieve the same functionality.</para>
<para><simplesectkind="attention"><para>Similar to <refrefid="classtf_1_1FlowBuilder_1ac6f22228d4c2ea2e643c4b0d42c0e92a"kindref="member">tf::Taskflow::composed_of</ref>, <refrefid="namespacetf_1aae281ad3b89a5c421a1f4058f425e54c"kindref="member">tf::make_module_task</ref> does not assume ownership of the provided taskflow but a soft reference. You are responsible for ensuring that the encapsulated taskflow remains valid throughout its execution.</para>
<title>Create a Module Task over a Custom Graph</title><para>In addition to encapsulate taskflow graphs, you can create a module task to schedule a custom graph target. A schedulable target (of type <computeroutput>T</computeroutput>) must define the method <computeroutput>T::graph()</computeroutput> that returns a reference to the <refrefid="classtf_1_1Graph"kindref="compound">tf::Graph</ref> object managed by <computeroutput>T</computeroutput>. The following example defines a custom graph that can be scheduled through making module tasks:</para>
<para><simplesectkind="attention"><para>Users are responsible for ensuring the given custom graph remains valid throughout its execution. The executor does not assume ownership of the custom graph. </para>