Intel® oneAPI Threading Building Blocks
Ask questions and share information about adding parallelism to your applications when using this threading library.
2477 Discussions

Getting output of nodes from flow graph, and specifically async_node

victor_d_1
Beginner
831 Views

I've seen examples of sending input to a node of the flow graph from C++ code outside of the flow graph by using:

node.try_put()

Could you provide examples of how to receive output from a node of the flow graph by C++ code outside of the flow graph? I'm especially interested in getting output of async_node. I tried 

output_type result;

while( node.try_get(result))

cout << "got result of " << result << endl;

But, this never returns true. Plus, how does the output know when the graph is done, so that the while loop can terminate? Maybe this is a more general question of how to interface with the graph at the output of the graph.

Thanks,

-Victor

0 Kudos
4 Replies
Nikita_P_Intel
Employee
831 Views

Hi Victor,

Currently, only nodes that support output buffering can be used in the way that you want (doc - try_get() section) and async_node is not on the list. You may connect async_node with some buffering node to store the results there and then retrieve them with try_get().

- Nikita

0 Kudos
Nikita_P_Intel
Employee
831 Views

Could you please provide a use case for your request? What do you want to achieve? Maybe we could find a better solution.

Nikita

0 Kudos
victor_d_1
Beginner
831 Views

Hi Nikita,

Thank you for your response. I tried having async_node feed queue_node and used .try_get() to get output, which seems to work properly. The use case is where the graph is only a part of an overall system and is not the whole system itself. In this case, the overall system provides inputs to the graph and gets results from the graph.

Thank you once again,

-Victor

0 Kudos
victor_d_1
Beginner
831 Views

Hi Nikita,

When I use queue_node and get its output using .try_get() in my C++ code running outside of the flow graph, most. of the time .try_get() returns false, as it has nothing to return. Is there a more efficient way to get an output from queue_node than using .try_get() and polling until .try_get() returns a true? Is there an asynchronous way to accomplish this with a callback function that will be called when the queue_node has an element available? Or, is there a convenient way to accomplish push-pull method in my own C++ code to get output of queue_node?

Thank you,

-Victor

0 Kudos
Reply