Community
cancel
Showing results for 
Search instead for 
Did you mean: 
tims666
Beginner
53 Views

A word of warning to users of the Pipeline / Cycling Token Buffer paradigm

Hi,
This applies to use of the pipeline class, with a cycling array of buffered tokens as in the tutorial example.
( It may be blatantly obvious to all the experienced TBB users out there, but it's driven me mad for half a day, so thought I'd share this in case any other new users have similar problems):

***ALWAYS use a serial_in_order filter as the last filter in the pipeline if you are cycling through an array of buffered tokens!***

I was getting really weird bugs where it seemed that the filters were being run in the wrong order. Eventually I figured out that what was really happening was that the tokens were exiting the pipeline in a jumbled order and so the "next free token slot" was actually still in use. Perhaps a note could be added to this effect in the tutorial? But I don't know who to ask about that.

Other than that, I'm loving TBB - just moved to a dual Xeon 8-core and things are flying...
0 Kudos
2 Replies
Alexey_K_Intel3
Employee
53 Views

Such a note does exist in the Tutorial. See the following excerpt from Section 4.2 "Working on the Assembly Line: pipeline", right before the subsection 4.2.1 starts:

" The buffers are allocated from a circular queue of size n_buffer. This might seem
risky, because after the initial n_buffer input operations, buffers are recycled without
any obvious checks as to whether they are still in use. The recycling is indeed safe,
because of two constraints:
The pipeline received n_buffer tokens when pipeline::run was called.
Therefore, no more than n_buffer buffers are ever in flight simultaneously.
The first and last stages are serial_in_order. Therefore, the buffers are retired
by the last stage in the order they were allocated by the first stage.
Notice that if the first and last stage were not serial_in_order, then you would have
to keep track of which buffers are currently in use, because buffers might not be
retired in the same order they were allocated."

If you think the text could be improved somehow to make the problem more clearly visible and understandable for readers, we certainly welcome feedback and suggestions.
tims666
Beginner
53 Views

Ah... should have RTFM. Hey ho.

Reply