liveBook · Manning

Granularity

As explained in Grokking Concurrency

Granularity is the degree to which a computation is divided into tasks, characterized by the number and size of those tasks.

Granularity describes how a computation is divided into tasks: both the number of tasks and the amount of work in each task. A decomposition with larger tasks is coarse-grained; one with many smaller tasks is fine-grained. section 7.9

Choosing granularity is part of decomposing a concurrent application. The goal is to expose enough independent work for available processing resources without creating unnecessary communication or coordination. section 7.0 section 7.9

The main trade-offs are:

  • Coarse-grained decomposition assigns larger computations to fewer tasks. It reduces communication and coordination overhead, but uneven task sizes can leave processors idle and limit concurrency. section 7.9
  • Fine-grained decomposition creates many smaller tasks. It exposes more parallelism and gives the runtime more flexibility in scheduling work across available resources. section 7.9
  • A useful target is at least as many tasks as available processing resources, preferably more, so the runtime can keep resources busy and schedule work flexibly. section 7.10

Four versus eight threads

On a system with eight cores, dividing work into four threads leaves four cores idle under the stated assumptions. Dividing it into eight threads creates a finer-grained decomposition: all eight tasks can run together when eight cores are available. With only four available cores, the scheduler can run four threads first and the remaining four afterward. section 7.9

How Grokking Concurrency covers it

How deep it goes
Defines coarse and fine granularity, explains their trade-offs, and stops short of implementation-specific scheduling details.
Examples
Contrasts four and eight threads on an eight-core system, including how a scheduler handles fewer available cores.
What it assumes
Assumes familiarity with concurrent programming as independent tasks while focusing on application-level decomposition rather than execution mechanics.
What you can do after
Apply granularity choices when decomposing work, balancing parallelism and runtime coordination overhead.
How it connects
Connects granularity with decomposition, concurrency, scheduling, load balancing, communication overhead, and data decomposition patterns.

Also explained in

Compare how 8 books explain granularity →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking Concurrency. The section links point to the parts of the book it draws on.