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

tbb::concurrent_bounded_queue<T> memory allocation issues

Amir_A_1
Beginner
297 Views

Hi,

I have a novice question concerning tb::concurrent_bounded_queue class.

While using it in the way shown below I notice that the memory used by the program increases over time!

Please advise me if I'm doing anything wrong:

***************************************************************************************************

{

   tbb::task_scheduler_init init(tbb::task_scheduler_init::automatic);

    typedef tbb::concurrent_bounded_queue<size_t> ConcurrentBoundedQueueType;
    ConcurrentBoundedQueueType _pcvMatBoundedQueue;

    size_t N = 10e+7;
    _pcvMatBoundedQueue.set_capacity(N);

    for (size_t j=0; j < 1000000; j++){
        std::cout << j << " :" << std::endl;

        std::cout << _pcvMatBoundedQueue.size() << " items exist" << std::endl;

        tbb::parallel_for<size_t>(0, N,[&](size_t i){
            _pcvMatBoundedQueue.try_push(1);
        });

        std::cout << _pcvMatBoundedQueue.size() << " items exist" << std::endl;

        //tbb::parallel_for<size_t>(0,N,[&](size_t i){
        for(size_t i=0; i < N; ++i){
            size_t v=0;
            _pcvMatBoundedQueue.try_pop(v);//pop(v);
        }//);


        std::cout << _pcvMatBoundedQueue.size() << " items exist" << std::endl;
        _pcvMatBoundedQueue.clear();

        std::cout << "is empty: " << _pcvMatBoundedQueue.empty() << std::endl;
    }
}

***********************************************************************************************************

0 Kudos
1 Reply
RafSchietekat
Valued Contributor III
297 Views

Do any of those try_push() and try_pop() calls fail, or could you have put assertions there?

Do you see ever-increasing memory use, or does it plateau? Any numbers (level after first iteration, level of plateau, or memory consumption per iteration)?

What seems peculiar about the program is that the queue is filled in parallel, and emptied sequentially. Do you see any difference when trying any of the 3 other possible combinations?

I don't see anything problematic with the program, except perhaps "size_t N = 10e+7;" (it would never occur to me to assign an integer from a floating-point value (does that even work without a cast?), and the number is suspicious (why no 1e+8 instead, or did you really mean 10 to the 7th power?)), or the explicit task_scheduler_init (this has not been required anymore for quite a while now).

(Added 2013-11-22) Apparently (verified on a recent Clang compiler) one can initialise and assign a size_t from a non-integral double variable, an integral double literal, but not a non-integral double literal except with a cast. Where's the logic in that, and how is it even allowed (real questions)? And is there more information yet about the actual problem, perhaps confirmation of simple underestimation by a factor 10? :-)

0 Kudos
Reply