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

Advice on how to structure a program with TBB

Brandon_S_1
Beginner
251 Views

Hello all,

I'm very new to using TBB and I'm hoping someone can loosely point me in the right direction for a system I'm trying to implement.

The gist of the task is that I will have a system that is acquiring a sequence of images, saving them, and sending them to an analyzer object I've created for an analysis which is cumulative across the image sequence (so they are all sent to the same analyzer instance).

The naive serial approach that is currently in place is 1) rapidly collect the image sequence and store them in memory  2) send them one by one to the analyzer  3) save them to disk one by one. 

I would like to create a system where saving and analysis tasks for each image are launched as soon as it is acquired, and these tasks would then execute while the system is free to continue on capturing the sequence.

I was envisioning using a flow graph to do this as it would be able to queue the subtasks in function nodes if they took longer than acquiring the next frame, limiting the analysis node to 1 at a time and having unlimited concurrency on the saving node.  However, because the analyzer object needs to be the same instance (and modifies its internal state with each frame), I'm not sure that the flow graph setup will work due to the requirement for a const argument.

I'm sure this is just me being oblivious to how to use TBB most effectively, so any advice would be much appreciated.  (And apologies for the somewhat verbose post)

0 Kudos
1 Reply
Alexei_K_Intel
Employee
251 Views

Hi Brandon,

With function_node you can try to use non-const qualified operator() in your body class. Or you can store a pointer inside the body and modify the "external" state from const qualified operator(). So your flow graph based algorithm can be: source_node (acquires images) -> (serial)function_node (analyzes images) -> function_node (stores images to disk). You also may want to use sequencer_node before the last function_node to restore the ordering of images.

In addition, you can consider tbb::parallel_pipeline algorithm as an alternative solution. 

Regards, Alex

 

0 Kudos
Reply