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

Difference between normal for and range based for loop?

Riyad_Parvez
Beginner
111 Views

What is the difference between these two loop? 

tbb::concurrent_vector<T> list;
tbb::parallel_for(tbb::blocked_range<size_t>(0, list.size()),
    [&](const tbb::blocked_range<size_t>& r)
    {
        for(size_t i = std::begin(r); i != std::end(r); ++i)
        {
            //Do something with list
        }
    }
);

tbb::parallel_for(tbb::blocked_range<size_t>(0, list.size()),
    [&](const tbb::blocked_range<size_t>& r)
    {
        for(auto& l : list)
        {
            //Do something with l
        }
    }
);

0 Kudos
1 Reply
MLema2
New Contributor I
111 Views

Is this a quiz or what ?  

Pretty obvious second loop won't give expected parallelism and is incorrect.

Reply