xref: /oneTBB/doc/main/tbb_userguide/Edges.rst (revision cb6cc0ec)
1.. _Edges:
2
3Flow Graph Basics: Edges
4========================
5
6
7Most applications contain multiple nodes with edges connecting them to
8each other. In the flow graph interface, edges are directed channels
9over which messages are passed. They are created by calling the function
10``make_edge( p, s )`` with two arguments: ``p``, the predecessor, and ``s``, the
11successor. You can modify the example used in the **Nodes** topic to
12include a second node that squares the value it receives before printing
13it and then connect that to the first node with an edge.
14
15
16::
17
18
19       graph g;
20       function_node< int, int > n( g, unlimited, []( int v ) -> int {
21           cout << v;
22           spin_for( v );
23           cout << v;
24           return v;
25       } );
26       function_node< int, int > m( g, 1, []( int v ) -> int {
27           v *= v;
28           cout << v;
29           spin_for( v );
30           cout << v;
31           return v;
32       } );
33       make_edge( n, m );
34       n.try_put( 1 );
35       n.try_put( 2 );
36       n.try_put( 3 );
37       g.wait_for_all();
38
39
40Now there are two ``function_node`` ``s``, ``n`` and ``m``. The call to ``make_edge`` creates
41an edge from ``n`` to ``m``. The node ``n`` is created with unlimited concurrency,
42while ``m`` has a concurrency limit of 1. The invocations of ``n`` can all
43proceed in parallel, while the invocations of ``m`` will be serialized.
44Because there is an edge from ``n`` to ``m``, each value ``v``, returned by ``n``, will
45be automatically passed to node ``m`` by the runtime library.
46
47