This is a computer translation of the original content. It is provided for general information only and should not be relied upon as complete or accurate.

Sorry, we can't translate this content right now, please try again later.

Use Nested Flow Graphs

In addition to nesting algorithms within a flow graph node, it is also possible to nest flow graphs. For example, below there is a graph g with two nodes, a and b. When node a receives a message, it constructs and executes an inner dependence graph. When node b receives a message, it constructs and executes an inner data flow graph:

If the nested graph remains unchanged in structure between invocations of the node, it is redundant to construct it each time. Reconstructing the graph only adds overhead to the execution. You can modify the example above, for example, to have node b reuse a graph that is persistent across its invocations:

It is only necessary to call h.wait_for_all() at the end of each invocation of b's body in our modified code, if you wish for this b's body to block until the inner graph is done. In the first implementation of b, it was necessary to call h.wait_for_all at the end of each invocation since the graph was destroyed at the end of the scope. So it would be valid in the body of b above to call m1.try_put(i) and then return without waiting for h to become idle.