Multicore & Synchronization

When splitting loop iterations among threads, which division suits iterations whose costs vary widely?

  1. AStatic assignment, dividing iterations evenly by count at the start and never adjusting
  2. BGiving every iteration to a single thread
  3. CDynamic assignment, where work is split into small chunks and idle threads grab the next chunk
Show answer and explanation

Answer: C. Dynamic assignment, where work is split into small chunks and idle threads grab the next chunk

Static assignment has little overhead, but if iterations differ in cost, the threads that drew heavy parts lag while the rest wait. With dynamic assignment, threads take the next piece of work from a shared counter or similar, so faster threads take on more and the load evens out. Chunks that are too small increase the overhead of fetching work, so their size must be tuned.

  • A. Equal counts with unequal costs leave imbalance.
  • B. That is not parallelization at all.
  • C. Correct. It evens out imbalance automatically.
Practice this topic Back to topic

More Multicore & Synchronization questions

  1. When several threads sum all elements of an array, which approach performs well?
  2. What is a characteristic of a reader-writer lock?
  3. What is the most suitable use of a counting semaphore?
  4. What is the difference between cache coherence and a memory consistency model?
  5. Which describes the idea of hardware transactional memory?