Use Nested Algorithms to Increase Scalability

One powerful way to increase the scalability of a flow graph is to nest other parallel algorithms inside of node bodies. Doing so, you can use a flow graph as a coordination language, expressing the most coarse-grained parallelism at the level of the graph, with finer grained parallelism nested within.

In the example below, five nodes are created: a source_node, matrix_source, that reads a sequence of matrices from a file, two function_nodes, n1 and n2, that receive these matrices and generate two new matrices by applying a function to each element, and two final function_nodes, n1_sink and n2_sink, that process these resulting matrices. The matrix_source is connected to both n1 and n2. The node n1 is connected to n1_sink, and n2 is connected to n2_sink. In the lambda expressions for n1 and n2, a parallel_for is used to apply the functions to the elements of the matrix in parallel. The functions read_next_matrix, f1, f2, consume_f1 and consume_f2 are not provided below.