tbb::concurent_vector::push_back

tbb::concurent_vector::push_back

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

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
4 posts / novo 0
Último post
Para obter mais informações sobre otimizações de compiladores, consulte Aviso sobre otimizações.
Best Reply

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)

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.)

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().

Deixar um comentário

Faça login para adicionar um comentário. Não é membro? Inscreva-se hoje mesmo!