- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dear all,
I am now considering how to iterate several of iterator in tbb::parallel_for,
because I believe iterator's access is faster than index access.
For example, is the below sequential code converted to tbb::parallel_for sentence?
In addition, though this example has two iterators,
I need to handle more iterators'case.
I would appreciate it if you could explain to me.
== Example code ==================================================
std::vector<ClsA>::iterator iterA = A.begin(); // A is data of std::vector<ClsA>
std::vector<ClsB>::iterator iterB = B.begin(); // B is data of std::vector<ClsB>
for (; iterB != B.end(); iterB++, iterA++)
(*iterB) = (*iterA).method();
================================================================
Best regards,
Mitsuru Nishikawa
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dear Mitsuru,
To iterate over two or more iterators, you may want to consider the zip iterator approach (e.g. tbb::zip_iterator or boost::zip_iterator).
because I believe iterator's access is faster than index access.
It depends on iterator type and the compiler capabilities. If you have a random access iterator (e.g. your example with std::vector), the performance should be the same in the both cases. If we are speaking about parallel loops, usually, it is difficult to apply them for non-random access iterators. So, choosing between index approach vs iterator approach, I would recommend considering convenience related aspects rather than abstract performance considerations.
Regards,
Alex
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dear Alex,
I always appreciate your helpful teaching, thank you very much.
I will try tbb::zip_iterator and check the performance.
By the way, if you do not mind,
I would appreciate it if you could teach my comment in parallel_for of "Mixture of data and task parallelization in TBB " thread,
about scalable performance.
Kind regards,
Mitsuru Nishikawa
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page