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

tbb::concurent_vector::push_back

Denis_Bolshakov
Beginner
678 Views
I've tried to use tbb::concurent_vector and I've thought that if I call push_back conccurently then it's not guaranteed that insertion is serios(for example I fill vector in parallel_for), however as I've found out I was wrong(I've even make delay in a thread in order to change push_back order by others).

For more clearly short extract from my test
[bash]void test(int count, bool makeReserve) {
TBBVector arr1;
STDVector arr2;

std::cout << getExecutingTime(arr1, count, makeReserve) << '\n'
<< getExecutingTime(arr2, count, makeReserve) << '\n';

assert(std::equal(arr1.begin(), arr1.begin(), arr2.begin()) == true);
assert(false);//just to ensure that assert works properly
}

am I right?

I've attached my full test.

P.S. I use tbb3
[/bash]
0 Kudos
1 Solution
Anton_M_Intel
Employee
678 Views
Denis, if two threads executing push_back() simultaneously, the order of elements is not defined and actually can not be serialized. So, it seems you have no parallelism there, e.g. 'count' can be too small so it is executed by only one thread without possibility for other threads to steal some work. (I don't see your full code)

View solution in original post

0 Kudos
3 Replies
Anton_M_Intel
Employee
679 Views
Denis, if two threads executing push_back() simultaneously, the order of elements is not defined and actually can not be serialized. So, it seems you have no parallelism there, e.g. 'count' can be too small so it is executed by only one thread without possibility for other threads to steal some work. (I don't see your full code)
0 Kudos
Denis_Bolshakov
Beginner
678 Views
Thanks,

I was attaching my test, it seems I did something wrong(in my tests I used about 1000000 counts and sometimes passed to task_shceduler_init value 100.)
0 Kudos
RafSchietekat
Valued Contributor III
678 Views
Allocation of locations is serialised, but it is not guaranteed that preceding locations are already initialised.

You should not normally provide an argument to task_scheduler_init().
0 Kudos
Reply