Visible to Intel only — GUID: GUID-8A6C1470-7EC3-4B41-AA92-F31C8789B730
Visible to Intel only — GUID: GUID-8A6C1470-7EC3-4B41-AA92-F31C8789B730
Flow Graph Basics: Mapping Nodes to Tasks
The following figure shows the timeline for one possible execution of the two node graph example in the previous section. The bodies of n and m will be referred to as λn and λm, respectively. The three calls to try_put spawn three tasks; each one applies the lambda expression, λn, on one of the three input messages. Because n has unlimited concurrency, these tasks can execute concurrently if there are enough threads available. The call to g.wait_for_all() blocks until there are no tasks executing in the graph. As with other wait_for_all functions in oneTBB, the thread that calls wait_for_all is not spinning idly during this time, but instead can join in executing other tasks from the work pool.
Execution Timeline of a Two Node Graph
As each task from n finishes, it puts its output to m, since m is a successor of n. Unlike node n, m has been constructed with a concurrency limit of 1 and therefore does not spawn all tasks immediately. Instead, it sequentially spawns tasks to execute its body, λm, on the messages in the order that they arrive. When all tasks are complete, the call to wait_for_all returns.
The above timeline shows the sequence when there are enough threads to execute all of the tasks that can be executed in parallel. If there are fewer threads, some spawned tasks will need to wait until a thread is available to execute them.