Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>TBB has a lot of parts. Concurrent_queue is just a queue that can be safely accessed by multiple threads. Concurrent queue is not directly part of the "fine grain parallelism" or "task parallelism" part of TBB. (Although those parts can <em>use</em> concurrent_queue.)</p> <ol> <li><p>You create fine grained/task parallelism in tbb by using <a href="http://threadingbuildingblocks.org/docs/help/reference/algorithms/parallel_for_func.htm" rel="nofollow noreferrer"><code>tbb::parallel_for</code></a>. See the examples on that page or <a href="https://stackoverflow.com/questions/14495829/tbb-parallel-for-example-c-without-lambda">at this stack overflow question</a>. When you use parallel_for tbb will take care of all the thread creation and will also do dynamic load balancing.</p></li> <li><p>Concurrent_queue doesn't create any parallelism at all: it just allows multiple threads to safely (and relatively efficiently) access the same queue. It ensures there are no race conditions. In your example you are getting no more than 8 threads worth of concurrency. Actually: concurrent_queue is <em>serializing</em> accesses to the queue. Your parallelism is coming from your "operations on v". The accesses to the concurrent_queue should be thought of as overhead.</p></li> <li><p>You are implementing a basic kind of task level parallelism in your example. I found <a href="https://stackoverflow.com/questions/4130194/what-is-the-difference-between-task-and-thread">this brilliant description of the difference between a task and a thread from a Stack Overflow answer by @Mitch Wheat</a>:</p> <blockquote> <p>A task is something you want doing.</p> <p>A thread is one of possibly many workers who perform that task.</p> </blockquote> <p>More technically: tasks must not block waiting for one another. Your tasks are the "operations on v" that you are performing. You are achieving task-level parallelism. The advantage of using something like <code>tbb::parallel_for</code> is that it (a) automatically starts the threads for you, (b) tries to automatically choose a number of threads most appropriate for the number of cores on your user's system, (c) is optimized to reduce the overhead of distributing tasks to threads, and (d) also does some pretty cool dynamic load balancing if your task operations aren't of equal length.</p></li> <li><p>Let's distinguish between <em>concurrency</em>, and <em>parallelism</em>. Your machine has 8 hardware threads. So you have a maximum cpu parallelism of 8. I would use the term <em>concurrency</em> to mean something like "the maximum parallelism you could achieve if you had a magical processor with an infinite number of cores." Typically the main reason for creating more threads than you have cores is if your threads are doing a lot of long-latency i/o operations. The operating system can switch to one of the extra threads to do cpu work while the other thread is waiting for the disk/network.</p></li> </ol>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload