Flow Graph¶
[flow_graph]
In addition to loop parallelism, the oneAPI Threading Building Blocks (oneTBB) library also supports graph parallelism. With this feature, highly scalable and completely sequential graphs can be created.
There are three types of components used to implement a graph:
A
graph
class instanceNodes
Ports and edges
Graph Class¶
The graph
class instance owns all the tasks created on behalf of the flow graph. Users can wait
on the graph
if they need to wait for the completion of all of the tasks related to the flow
graph execution. Users can also register external interactions with the graph
and run tasks under
the ownership of the flow graph.
Nodes¶
Abstract Interfaces¶
To be used as a graph node type, a class needs to inherit certain abstract types and implement the
corresponding interfaces. graph_node
is the base class for any other node type; its interfaces
always have to be implemented. If a node sends messages to other nodes, it has to implement the sender
interface, while with the receiver
interface the node may accept messages. For nodes that have multiple
inputs and/or outputs, each input port is a receiver
and each output port is a sender
.
Functional Nodes¶
Functional nodes do computations in response to input messages (if any), and send the result or a signal to their successors.
Auxiliary
Buffering Nodes¶
Buffering nodes are designed to accumulate input messages and pass them to successors in a predefined order, depending on the node type.
Service Nodes¶
These nodes are designed for advanced control of the message flow, such as combining messages from different paths in a graph or limiting the number of simultaneously processed messages, as well as for creating reusable custom nodes.
Ports and Edges¶
Flow Graph provides an API to manage connections between the nodes.
For nodes that have more than one input or output ports (for example, join_node
),
making a connection requires to specify a certain port by using special helper functions.
Special Messages Types¶
Flow Graph supports a set of specific message types.