If all the filters in my pipeline are serial, would I still see an improvement in performance vs. running them sequentially?
Specifically, if I had serial filters A->B->C->D, would B be running and generating the next item at the same time C is processing the last item generated by B?
Thanks a lot.
In theory, you could see a performance improvement, since the filters will be operating in parallel. Whether you get this performance improvement in practice depends upon whether there is enough work per item to amortize scheduling overheads, and how balanced the work is across the stages.
Amdahl's law for a tbb::pipeline is that the throughput of the pipeline is limited by the throughput of the slowest serial stage.
>>I had serial filters A->B->C->D...
Also consider the implications of
Where the otherwise single thread only capable functions/tasks A, B, C, D can now work in parallel on seperate work items.
You'll find a diagram similar to this in my blog post (three parts) using TBB pipeline to overlap streaming file I/O and processing. One misleading aspect of Jim's diagram above is that it accidentally meets Arch's expression of the Amdahl limit for pipelines: if all the stages are the same "length" the pipeline reaches maximal concurrency. If each stage is truly serial, i.e., cannot support concurrent processing, throwing in a little variance in length might show another picture:
If only a single copy of B can execute at a time in this distended variant of Jim's example, you can see a growing separation between when A finishes and B begins, but note that the Ds finish at a regular interval, though not nearly as quickly as the As.
Right - so Robert,
I should have pointed this out, thanks for your additional comments.
Now that the viewers have had a chance to digest what you have illustrated, they should now appreciate that the little bit of extra effort in making each stage of the pipeline thread safe is well worth the effort.(i.e. making it so A1 can run concurrent with A2, etc...)
As your article shows.
One of the other things this illustrates is when your application has additional work to perform, the task stealing nature of TBB will fill in the blanks so to speak.