Intel® oneAPI Threading Building Blocks
Ask questions and share information about adding parallelism to your applications when using this threading library.
Announcements
Welcome to the Intel Community. If you get an answer you like, please mark it as an Accepted Solution to help others. Thank you!
2401 Discussions

parallel_for with concurrent_vector (without grain size)

AJ13
New Contributor I
110 Views
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
Alexey_K_Intel3
Employee
110 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.

Reply