Reputation: 1008
I've read TBB flow graph conditional execution and have a slightly different problem.
Is it possible to create a node with multiple inputs and multiple outputs AND to control the execution by a conditional variable? Maybe without ugly casts.
I've attached a simple example how I would like to design the graph. How is the besst way to get it run with TBB flow graph?
start_node
sends a start_msg
to some_node
if start_msg
is empty, some_node
sends a continue_msg
to end_node
, else some_node
sends a continue_msg
to itself AND a data_msg
to end_node
if continue_msg
is received by some_node
, previous start_msg is checked if it's empty, if so, a continue_msg
is send to end_node
, else a data_msg
is send.
+--continue_msg--+
| |
+-----+ +-----+
| |
| | +----data_msg---+
v | / \
start_node --start_msg--> some_node end_node
\ /
+--continue_msg--+
One problem I'm dealing with: I can't say how many good elements are inside of start_msg
even is the size is known (let's say start_msg
holds a tbb::concurrent_vector<T>
. If some_node
finds a bad element, it will be ignored and some_node
is sending a continue_msg
to itself.
Upvotes: 0
Views: 328
Reputation: 632
It looks like, the source_node
can be used in your algorithm. source_node
can generate as many messages as you need. So the algorithm can be reworked a bit:
source_node -> ... -> end_node
Why do you need a continue_msg
to be sent to the end_node
? To mark the last message? Perhaps, you can use a std::pair<T,bool>
where the first element is data and the second one is an indication of the last message.
The Body of the source_node
finds the valid element in tbb::concurrent_vector<T>
, creates a new message make_pair(Data, false)
and returns true
for each Body invocation. When the last element is extracted from the container it creates make_pair(Data, true)
and returns false
as an indication of the last element.
Unfortunately, I do not know the original algorithm and my suggestion can be inappropriate. Could you provide more details if it does not suit your needs, please?
Upvotes: 1