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

Doubt with parallel_for.

kio_marv
Beginner
432 Views
Hi,
I'm using parallel_for to speed up the filling of two vectors I'm using. The INIT_V1_SIZE and INIT_V2_SIZE variables are read from user input in another place.
[cpp]class World { private: std::vector v1; std::vector v2; // more things public: World() { v1.reserve( INIT_V1_SIZE ); v2.reserve( INIT_V2_SIZE ); // more things void StartUp() {
/// more things
tbb::parallel_for(tbb::blocked_range(0,v1.size()),FillObjectVector(&v1,....),tbb::auto_partitioner()); tbb::parallel_for(tbb::blocked_range(0,v2.size()),FillContainerVector(&v2,....),tbb::auto_partitioner()); } };[/cpp] FillObjectVector and FillContainerVector iterate through the vector and in each position create a new object. Each object is independent from the rest.
What I want to know if it it possible to launch all of the parallel_for's at the same time. Would it be a good idea?.

Thanks.
0 Kudos
1 Solution
RafSchietekat
Valued Contributor III
432 Views
0 Kudos
3 Replies
RafSchietekat
Valued Contributor III
433 Views
0 Kudos
kio_marv
Beginner
432 Views
Thanks a lot!!
0 Kudos
jimdempseyatthecove
Honored Contributor III
432 Views
Depending on the number of memory channels available, if you have two then consider parallel_invoke with each vector listed in the task list using standard for(... to fill/copy the data. On such a system using more than two threads to perform the copy may be counter productive.

Jim Dempsey
0 Kudos
Reply