1.. _Graph_Object:
2
3Flow Graph Basics: Graph Object
4===============================
5
6
7Conceptually a flow graph is a collection of nodes and edges. Each node
8belongs to exactly one graph and edges are made only between nodes in
9the same graph. In the flow graph interface, a graph object represents
10this collection of nodes and edges, and is used for invoking whole graph
11operations such as waiting for all tasks related to the graph to
12complete, resetting the state of all nodes in the graph, and canceling
13the execution of all nodes in the graph.
14
15
16The code below creates a graph object and then waits for all tasks
17spawned by the graph to complete. The call to ``wait_for_all`` in this
18example returns immediately since this is a trivial graph with no nodes
19or edges, and therefore no tasks are spawned.
20
21
22::
23
24
25   graph g;
26   g.wait_for_all();
27
28The graph object does not own the nodes associated with it. You need to make sure that the graph object's lifetime is longer than the lifetimes of all nodes added to the graph and any activity associated with the graph.
29
30.. tip:: Call ``wait_for_all`` on a graph object before destroying it to make sure all activities are complete.
31
32 Even when using smart pointers, be aware of the order of destruction for nodes and the graph to make sure that nodes are not deleted before the graph.
33
34
35