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

using range() from containers for parallel_reduce

Alexander_Herz
Beginner
324 Views
This is probably a stupid question, but after staring at miles of template errors ...

given a tbb::concurrent_hash_map map I want to perform a parallel_reduce on the keys:

tbb::parallel_reduce( map.range(), Body );

where Body contains:

void operator()(tbb::concurrent_hash_map::range_type range) const
{
for (tbb::concurrent_hash_map::iterator size=range.begin(); size != range.end(); ++size) //...
}

Apparently map.range() doesn't give the right kind of range object for parallel_reduce??
So into which type and how am I supposed to convert the retval of map.range() so I can plug it into
parallel_reduce?

Thx,
Alex

P.S.: It'd be neat to have an example which actually uses a container and it's range....
0 Kudos
4 Replies
RafSchietekat
Valued Contributor III
324 Views
Try without const.
0 Kudos
Alexander_Herz
Beginner
324 Views
thx,

that actually helped to reduce the errors to something comprehensible...
0 Kudos
RafSchietekat
Valued Contributor III
324 Views
And did you eventually get things working?

You might also pass the range by const reference instead of by value, but that shouldn't make any noticeable difference. Maybe if you do make a mistake in the operation's signature it may ensure a clearer error message, maybe not. Although... has anyone ever verified whether passing the range by value allows the compiler to optimise the code without hoisting range.end() out of the loop, which is always slightly ugly and inconvenient? And wouldn't it actually be more performant to work from a copy that can be located in registers than always through a pointer (a reference is merely a pointer in disguise)? Just wondering...
0 Kudos
Alexander_Herz
Beginner
324 Views
yep, was easy afterwards.
0 Kudos
Reply