I have constructed a tbb::flow::graph that consists of several function_node objects. During execution I'm passing multiple messages into the graph (from ~10 to ~100000). Sometimes one of the nodes throws an exception. If that's the case, the execution of the entire graph is cancelled, meaning all messages are discarded. However, my messages are independent from each other and I don't want their execution to be stopped.
I can catch the exception directly inside the node, but when that happens the further processing of the message won't make sense.
So my question is: how can I cancel or remove a single message from the graph without cancelling the execution of the other messages that are already in the graph?
For the nodes that might throw an exception, use
multifunction_nodeinstead offunction_node. The body functor of amultifunction_nodeaccepts a tuple of its output ports and, unlikefunction_node, should explicitly put messages to these ports. Thereforemultifunction_nodecan discard/drop messages, or create multiple outputs for each input.Note that multiple output ports of
multifunction_nodedo not assume a separate port for each successor. You can have a single output port and connect all successors to it; an output message will be broadcast to each successor in the same way asfunction_nodedoes. Multiple output ports however allowmultifunction_nodenot to be limited by a single type of output, making it a very flexible instrument for sophisticated message dispatch in a flow graph.For more information about message handling by different nodes, see single-push vs. broadcast-push, other flow graph concepts, and the node behavior policies in the TBB documentation.