Parallel workers
Each candidate economy has its own parameters and returns its own moments. Give independent economies to separate workers: a worker can start its next job while the others are still solving theirs.
- What is removed?
- The wait for one independent economy to finish before another can begin.
- What remains?
- Every economy must still be solved in full. Setup, the final join and uneven job lengths can limit the gain.
# Each call solves one independent economy.
results = pool.map(solve_economy, candidates)
moments = collect_in_candidate_order(results)
Try the worker illustration above ↑
Find this in the source
Download the current source. In 07_python/qmp/estimation.py, solve assigns rows to one serial shard and writes each result by row_id, and select checks the combined records. lessons/03_estimation/full_search.py runs several shards side by side, and lessons/04_parallel/scaling.py solves economies in a pool of worker processes, as in the pool.map example above.
60-second explanation · EnglishParallel workers: the same jobs, a shorter clock
Watch independent jobs leave a shared queue, overlap on worker lanes and meet at the final join. Then add the work that cannot overlap.
Check your result
| Workers | Serial work | Finish | Speedup |
|---|---|---|---|
| 1 | off | 24 units | 1.00× |
| 2 | off | 13 units | 1.85× |
| 4 | off | 7 units | 3.43× |
| 1 | on | 27 units | 1.00× |
| 2 | on | 16 units | 1.69× |
| 4 | on | 10 units | 2.70× |
Two reasons the gain falls short of the worker count. The jobs have different lengths, so lanes stand idle near the end: if the 24 units of work split evenly, four workers would finish at 6 units, but the last job ends at 7. And the 2 units of setup and 1 unit of join take the same time with any number of workers, so with serial work the speedup can never exceed 27 / 3 = 9.