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

Multiple use of the flow graph

Maciej_S_
Beginner
174 Views

This is my first post, so I'd like to say hello to everyone.
I searched the forum, but I didn't find any answers to my question. I have following concern: I need to create a flow graph with approximately 6000 nodes (in fact it will be many graphs connected together to handle cancellation the way I want) and the thing is I want to process the graph(s) multiple times in a while loop with different input without the necessity of re-creating graph(s). Referring to doc., flow graph is automatically destroyed on completion. What would be the possible solution to my case?
I almost forgot: the inputs / outputs of nodes are taken from data store, I do not pass the values between nodes - basically the graph will consist only of continue_node<continue_msg>, broadcast_node<continue_msg>, and few limiter_node<continue_msg>.

0 Kudos
1 Reply
Christophe_H_Intel
174 Views

Hello, Maciej,

Thank you for your post, and sorry I didn't respond to your question ealier.  flow::graphs are not automatically destroyed; the user has to destroy them.  You can put to the nodes of a graph and do a wait_for_all() multiple times.  But the wait_for_all() does not reset the graph; it only waits for all the tasks associated with that graph to complete.  (So for multiple graphs you need to do a wait_for_all() for each graph to guarantee there is no activity.)

If you have multiple graphs you must call reset() on each graph to reset the contained nodes.  One more caveat; the original design of cancellation reset the function bodies of the nodes.  This was removed (because a use case for it did not exist.)  Customers have since asked for the ability, and so it may be enabled in a future release.

One possible additional concern: graph has been made so if an exception is thrown in a particular graph, it is handled in the same graph (after the wait_for_all().)  But if you are handling exceptions, in general the recommendation is to not use mulltiple graph objects because this is not guaranteed.  (Cancellation is not identical to exception handling, but it uses the same task_group_context mechanisms and is predictable, so the same warning does not apply.)

However, the graph components themselves do not throw, so the only exceptions that need to be handled are in the function bodies.

Thanks and Regards,
Chris

0 Kudos
Reply