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

Alternative Termination for parallel_do


Flush with success at my first parallel_for, I'm on to bigger and more complex. I now have a problem in which I have a stochastic process that is used to fill a data structure. The process can result in 0,1 or several additions to the data structure. I need to terminate when the data structure is full. The serial code is a simple do{StochasticProcess();}while (!dataStructure.isFull()); It takes 10's of thousands of calls to StochasticProcess to fill the dataStructure, and they are independent, so it's a great thing to parallelize. The dataStructure simply rejects calls to Add(item) once it is full, so I can tolerate some overrun. Any suggestions on how I feed parallel_do? Or is there a better pattern? Thanks

0 Kudos
1 Reply
parallel_do takes a couple of iterators and processes every element in between, with the ability to add more work if generated during the processing. So I guess it is not the best fit for you.
I would suggest you looking at the tbb::pipeline, which I think might be a good fit,particularly because the pipeline has no predefined work space; everything created by the first (or input) filter is processed.Even ifyour processing can not be separated into real stages, you might just create a pipeline consisting of a single parallel stage that runs repeatedly by multiple threads until the data structure is full. Serial stage(s) can be helpful to guarantee atomicity of updates to global data structure(s).
0 Kudos