Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Denis_Bolshakov
Beginner
106 Views

tbb::concurent_vector::push_back

Jump to solution
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
106 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

3 Replies
Anton_M_Intel
Employee
107 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

Denis_Bolshakov
Beginner
106 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.)
RafSchietekat
Black Belt
106 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().
Reply