- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Link Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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).
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page