1.10 Parallel Patterns in Scientific Computing
1.10.1 Motivation
Scientific workloads fall into recognizable shapes. A Monte Carlo simulation draws random samples. A bootstrap resamples data. A parameter sweep tries many values. Each shape has a dominant cost, a reproducibility requirement and a set of execution models that suit it. The sections below treat the patterns as mechanisms, not as domain tutorials: for each one, the shape of the work predicts which parallel strategy will work and which will fail.
1.10.2 Overview
The table below summarizes eight patterns.
| Pattern | Computation shape | Dominant cost | Reproducibility | Execution models that suit it | Common failure |
|---|---|---|---|---|---|
| Monte Carlo | Draw N random samples, compute statistic on each | Random number generation and arithmetic | Results identical at any worker count | Independent streams (L’Ecuyer-CMRG), one worker per batch of samples | Seeding all workers identically |
| Bootstrap / permutation test | Resample data N times, compute test statistic each time | Resampling and statistic computation | Identical p-values and confidence intervals at any worker count | Independent RNG streams with stable task-to-stream mapping | Wrong stream partitioning, stream overlap across retries |
| Parameter sweep | Evaluate function at N parameter combinations | Function evaluation time, which varies | Identical results at each parameter point | Map-reduce: each parameter set is one task | Load imbalance when parameter costs vary widely |
| Independent model fitting | Fit model to data on N subsets or with N random initializations | Model fitting time (usually seconds to hours per task) | Reproducible parameter estimates and convergence | Persistent workers or fork template with seed control | Worker crashes lose intermediate models, no checkpointing |
| Chunked matrix or genomic workload | Split large array or sequence into N chunks, process each chunk | Chunk processing and data I/O, memory bandwidth if data lives in one place | Results identical regardless of chunk boundary placement | Map-reduce with local I/O or shared immutable data, fork with copy-on-write | Chunk boundaries in wrong places (e.g., middle of genes), workers read entire dataset instead of their slice |
| File and database pipeline | Read from source, transform, aggregate, pipeline stages run in parallel | I/O bandwidth and stage latency | Idempotent read and aggregate, reproducible if seed is fixed | Work queue with persistent workers, persistent database connections | Connection pooling exhaustion, pipeline deadlock if stage A waits on B which waits on A |
| Reduction and aggregation | Combine N partial results (sums, counts, fitted models) into one | Communication and combining | Exact for integer counts; floating-point sums can differ in the last digits | Tree reduce, or collect and combine in the main process | A grouping that changes between runs; a crash that loses a branch of the tree |
| Irregular task graph | Tasks wait on other tasks | Scheduling, and workers idling until their inputs are ready | Deterministic ordering within stages | DAG schedulers such as targets, dynamic work queues | Cycles deadlock; one failed task blocks everything downstream |
1.10.3 Monte Carlo simulations
The canonical embarrassingly parallel workload. Each task draws N random samples, computes a statistic, and returns one number.
The mechanism: one task draws random deviates from a stream, computes a sum or a regression, and returns the result. Scale to 10,000 tasks, and each task draws from a different stream. Reproducibility requires stable stream assignment: task 5000 always draws from stream 5000.
The failure mode: seeding all workers with the same seed. The workers then produce identical results, and the simulation returns N copies of one replicate.
1.10.4 Bootstrap and permutation tests
Resample data, compute a statistic, and repeat. The dominant cost is computing the statistic on each resample.
The mechanism: each task draws one bootstrap resample, rows sampled with replacement from the fixed data. Task 47 can draw rows (1, 1, 3, 8, 1, …) and task 48 rows (2, 4, 7, 9, 2, …). A permutation test shuffles the group labels instead. Each task computes the statistic on its resample and returns one number, and the main process collects the numbers into the bootstrap distribution.
The failure mode: wrong stream partitioning. If tasks 47 and 48 resample using the same RNG stream, they produce identical samples and identical statistics. The bootstrap distribution then holds repeated values, and its Monte Carlo error is larger than the number of resamples suggests.
1.10.5 Parameter sweeps
Evaluate a function at many parameter combinations. Common in sensitivity analysis, model selection, and hyperparameter tuning.
The mechanism: one task evaluates the function at one parameter point. Task 1 tries parameters (alpha=0.01, beta=0.1). Task 2 tries (alpha=0.01, beta=0.2). The result is a vector of function values, one per parameter point.
The failure mode: load imbalance. Some parameter points take seconds to evaluate. Others take minutes. If tasks are split among the workers up front, some workers finish early and sit idle while others continue for hours. A work queue that assigns tasks dynamically, not up front, fixes this.
1.10.6 Independent model fitting
Fit a statistical model many times on different data subsets or with different random initializations. Examples: cross-validation folds, bootstrapped model confidence intervals, ensemble methods.
The mechanism: one task fits a model and returns the fitted coefficients. Task 1 fits on subset 1 and returns coefficients. Task 2 fits on subset 2 and returns coefficients. A reduction step aggregates coefficients into a final estimate or a distribution.
The failure mode: worker crashes lose intermediate models, and restarting the entire job recalculates. With hundreds of model fits, retrying all is expensive. Checkpointing is important: write results to disk as workers complete. On restart, skip done tasks.
1.10.7 Chunked matrix or genomic workloads
Split a large matrix or genomic sequence into chunks, process each chunk independently, and aggregate results. Examples: processing parts of a genome, computing statistics on matrix blocks, large-scale image analysis.
The mechanism: chunk 1 is rows 1 to 1000. Chunk 2 is rows 1001 to 2000. Each task reads its chunk and computes a local result (local mean, local summary statistic). A reduction aggregates local results into global results.
The failure mode: chunk boundaries are wrong or workers read the entire dataset. If chunk boundaries fall in the middle of a gene or a semantically meaningful unit, results are wrong. If a worker reads the entire 100 GB dataset instead of just its 1 GB chunk, parallelism fails due to I/O bandwidth exhaustion.
1.10.8 File and database pipelines
Read data from a source, transform through stages, and write results. Stages run in parallel: while one stage reads, another transforms, and another writes.
The mechanism: task 1 reads file 1 from disk. Task 2 transforms the previous stage’s output. Task 3 aggregates into a summary. Each stage can run on a different worker. A persistent worker keeps its database connection open across many tasks.
The failure mode: connection pooling exhaustion. Each worker opens a database connection. With 32 workers, the database has 32 open connections. Connection limits are hit. New workers hang waiting for a connection to free. A pipeline deadlock occurs. Stage A waits on stage B to consume its output. Stage B waits for a database connection that stage A holds.
1.10.9 Reductions and aggregation
Combine N partial results into one. Examples: sum a billion numbers, fit a meta-analysis from studies, ensemble predictions from trained models.
The mechanism: task 1 computes a sum on data partition 1. Task 2 computes a sum on partition 2. A reduction stage combines the two sums. Then combines that result with other sums. A tree structure keeps work parallel: instead of one worker summing all partial results sequentially, many workers sum pairs in parallel.
The failure mode: non-associative aggregation. Floating-point arithmetic is not strictly associative: (a + b) + c does not always equal a + (b + c). In R, (0.1 + 0.2) + 0.3 == 0.1 + (0.2 + 0.3) is FALSE; the two sums differ in the last bit. A parallel reduction whose grouping changes with the worker count, or with the order in which partial results arrive, can give slightly different results across runs.
1.10.10 Irregular task graphs
Tasks have dependencies. Some tasks run after others finish. The task graph is a DAG (directed acyclic graph) of dependencies.
The mechanism: task 1 runs first. Its result is input to tasks 2 and 3, which run in parallel. Their results are input to task 4. A DAG scheduler tracks dependencies and launches tasks when their inputs are ready.
The failure mode: severe load imbalance and cascade failures. Suppose task 4 depends on tasks 2 and 3. If task 2 takes twice as long as task 3, the worker that ran task 3 sits idle until task 2 finishes and task 4 can start. A cascade failure occurs when task 2 crashes: tasks 4, 5, 6, and any task downstream now cannot run. The entire downstream computation is lost.
1.10.11 Choosing a pattern for your workload
These patterns help you recognize your workload and choose the right execution model. A Monte Carlo simulation needs independent RNG streams. A reduction requires careful thinking about associativity. A pipeline needs persistent workers and careful synchronization.
Mixing patterns is common. Many real analyses combine a parameter sweep (outer loop) with independent model fits (inner loop). Recognizing each component helps you design the parallel structure correctly.
Further reading
- Embarrassingly parallel, the glossary entry.
- Reproducible Random Numbers in Parallel.
- Work Stealing. Dynamic scheduling for irregular tasks.
- Task granularity, the glossary entry, with its links to load balancing.