Reputation: 487
I am new to TBB, so my apologies, if this question is obvious... but how do I set up an aggregating node with TBB? Out of all pre-made nodes I cannot find the right type for it.
Imagine I have a stream of incoming images. I want a node that keeps accepting images (with a FIFO buffer), does some calculation on them (i.e. it needs an internal state) and whenever it has received N images (fixed parameter), it emits a single result.
Upvotes: 4
Views: 301
Reputation: 404
I think there is no such singular node in TBB flow graph that does accumulating with some sort of preprocessing and then, when accumulation is done, forwards the result of it to successor.
However, I believe the effect could be achieved by using several nodes. For example, consider queue_node
as a starting point in the graph. It will serve as a buffer with FIFO semantics. After it there goes multifunction_node
with N outputs. This node will do actual image preprocessing and send the result to its output port that correponds to image number. Then goes join_node
that has all its N inputs connected to corresponding outputs of multifunction_node
. At the end there will be a successor of join_node
that will receive N images as its input. Since join_node
aggregates its inputs in a tuple the drawback of this design could be quickly seen in case the number N is relatively large.
The other variant might be having the same queue_node
connected with function_node
with unlimited concurrency as successor (function_node
is supposed to be doing some image preprocessing), and then having a multifunction_node
with serial concurrency (meaning that only single instance of its body could be working at a time) that will sort of accumulate the images and do try_put
call from inside the body to its successor when the number N is reached.
Of course there could be other variants how to implement desired behavior by using other flow graph topologies. By the way, to make such a graph as a singular node one could use composite_node
that represents the subgraphs as a single node.
Upvotes: 2