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 post / 0 nuovi
Ultimo contenuto
Per informazioni complete sulle ottimizzazioni del compilatore, consultare l'Avviso sull'ottimizzazione
Ritratto di Anton Malakhov (Intel)
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.)

Ritratto di Raf Schietekat

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

Accedere per lasciare un commento.