<divclass="textblock"><p>Composition is a key to improve the programmability of a complex workflow. This chapter describes how to create a large parallel graph through composition of modular and reusable blocks that are easier to optimize.</p>
<p>A powerful feature of <aclass="el" href="classtf_1_1Taskflow.html" title="main entry to create a task dependency graph ">tf::Taskflow</a> is its <em>composable</em> interface. You can break down a large parallel workload into smaller pieces each designed to run a specific task dependency graph. This largely facilitates the <em>modularity</em> of writing a parallel task program.</p>
<li>Line 1-12 creates a taskflow of three tasks f1A, f1B, and f1C with f1A and f1B preceding f1C </li>
<li>Line 17-30 creates a taskflow of four tasks f2A, f2B, f2C, and f2D </li>
<li>Line 32 creates a module task from taskflow f1 through the method <aclass="el" href="classtf_1_1FlowBuilder.html#a0a01192f4f92c15380a4f259e2fec2d9" title="creates a module task from a taskflow ">Taskflow::composed_of</a></li>
<li>Line 33 enforces task f2C to run before the module task </li>
<li>Line 34 enforces the module task to run before task f2D</li>
</ul>
<h1><aclass="anchor" id="C5_ModuleTask"></a>
Module Task</h1>
<p>The task created from <aclass="el" href="classtf_1_1FlowBuilder.html#a0a01192f4f92c15380a4f259e2fec2d9" title="creates a module task from a taskflow ">Taskflow::composed_of</a> is a <em>module</em> task that runs on a pre-defined taskflow. A module task does not own the taskflow but maintains a soft mapping to the taskflow. You can create multiple module tasks from the same taskflow but only one module task can run at one time. For example, the following composition is valid. Even though the two module tasks <code>module1</code> and <code>module2</code> refer to the same taskflow <code>F1</code>, the dependency link prevents <code>F1</code> from multiple executions at the same time.</p>
<p>However, the following composition is <em>invalid</em>. Both module tasks refer to the same taskflow. They can not run at the same time because they are associated with the same graph.</p>