Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
New Contributor I
37 Views

parallel_for with concurrent_vector (without grain size)

Hi,

In the TBB book it shows that concurrent_vector has a function named range(size_t grainsize).

I want to iterate over a concurrent_vector, applying an operation to each element. However, I would prefer to use the auto partitioner. Currently, I am passing this for range type in a parallel_for:

tbb::blocked_range<:CONCURRENT_VECTOR>::iterator>(v.begin(), v.end())

Is there a better way, that uses the auto partitioner?

Thanks!

AJ
0 Kudos
1 Reply
Highlighted
37 Views

You should be able to use the blocked_range as youcreated above together with auto_partitioner.

You could also use the method range(size_t grainsize)of concurrent_vector with auto_partitioner; just specify grainsize of 1 for it. This method will do for you what you did manually, i.e. construct a blocked_range over iteration space [ v.begin(), v(end) ) with a given grainsize. The value of 1 is the default grainsize value for blocked_range; we should have made it the default value in the concurrent_vector's range method as well.

Both ways are essentially the same.

0 Kudos