parallel_for with concurrent_vector (without grain size)

parallel_for with concurrent_vector (without grain size)


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::iterator>(v.begin(), v.end())

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



2 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

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.

Leave a Comment

Please sign in to add a comment. Not a member? Join today