- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I would like to return the result inside parallel_for operation. How do I do?(For example, if I have variable type int named a that is variable of class C used by parallel_for. How do I get value of a?)
Link Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting - nuntawat
I would like to return the result inside parallel_for operation. How do I do?(For example, if I have variable type int named a that is variable of class C used by parallel_for. How do I get value of a?)
Do you mean that you try to accumulate some result in the body class you use with parallel_for, and then want it back?
That simply won't work well with parallel_for, because this algorithm copies body objects all the time, so any attempt to accumulate something in a non-static member variable would just fail. If you need the total result back, use parallel_reduce, which body is supposed to have the method join()that merges with the data accumulated by in another body object. To get the accumulated value after parallel_reduce completes, instantiate the body object as a non-temporary:
MyBodyClass accumulator;
tbb::parallel_reduce( blocked_range(0,N), accumulator );
cout << accumulator.result << endl;

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