1.4 Choosing a Parallel Execution Model
1.4.1 Motivation
Once you know your workload’s bottleneck and structure, you can choose how to parallelize it. The models below are compared on nine dimensions, and no model wins on all of them.
Read the dimension definitions. Identify which dimensions matter for your job. Then use the table to narrow choices.
1.4.2 Nine dimensions for comparison
Startup latency
How long before the first task starts? Fast startup matters for interactive work, I/O-bound jobs with many small tasks, and exploratory analysis. Slow startup is tolerable for long-running compute jobs.
Steady-state overhead
Once workers are running, how much overhead remains? Overhead per task, per data transfer, or per synchronization. Matters for fine-grained parallelism.
Data movement cost
How much does data transfer or serialization cost per task and per gigabyte? Matters for memory-intensive workloads.
Memory behavior
Does memory use grow with worker count? Processes copy heaps (linear growth). Threads share one heap. Matters when memory is the bottleneck.
Portability
Does the code run on Windows, macOS, and Linux? Some models are Unix-only.
Package compatibility
Do third-party packages work unchanged? CRAN packages expect one interpreter per process.
Process/thread isolation
If one worker crashes, are others safe? Process isolation is kernel-enforced. Thread isolation requires programmer discipline. Matters for production jobs and long-running clusters.
Determinism and reproducibility
Are results bit-identical across runs? Shared state and concurrency can introduce nondeterminism. Matters for science and auditing.
Failure containment
If a worker fails, can you restart it without restarting everything? In a process-based system a crash ends only that worker, but a restart depends on the framework: R’s parallel package has no function that replaces one PSOCK worker, so you make a new cluster. Thread crashes kill the parent.
1.4.3 Execution models compared
BLAS/OpenMP inside native libraries
Used indirectly whenever you call matrix operations or statistical functions that use multithreaded C code.
| Dimension | Assessment |
|---|---|
| Startup latency | none |
| Steady-state overhead | none |
| Data movement | none (reads in place) |
| Memory behavior | 1x (one heap) |
| Portability | all |
| Package compatibility | perfect (unchanged packages) |
| Isolation | no (one interpreter) |
| Determinism | fair (floating-point results can change with the thread count) |
| Failure containment | no (crash kills process) |
When to use: Your workload is dominated by linear algebra and R is linked to a multithreaded BLAS. No custom parallelism required.
When to avoid: You need parallelism beyond what packages provide. Custom loops stay serial.
Threads inside native packages (user-visible)
Packages like data.table run OpenMP threads inside C functions. You call them from R.
| Dimension | Assessment |
|---|---|
| Startup latency | none |
| Steady-state overhead | none |
| Data movement | none |
| Memory behavior | 1x |
| Portability | varies (OpenMP support varies) |
| Package compatibility | good (package controls threads) |
| Isolation | no (one process) |
| Determinism | fair (depends on package) |
| Failure containment | no |
When to use: Packages you depend on have parallel implementations. No custom parallelism required.
When to avoid: You need to parallelize your own code. Only the package author can add threads inside a package.
PSOCK clusters (sockets)
parallel::makeCluster(type = "PSOCK") or future::plan(multisession). PSOCK is the default type of makeCluster() on every platform.
| Dimension | Assessment |
|---|---|
| Startup latency | under a second for bare R, seconds with heavy packages |
| Steady-state overhead | serialization cost |
| Data movement | serialize in, serialize out |
| Memory behavior | Nx (N workers, N heaps) |
| Portability | all |
| Package compatibility | perfect |
| Isolation | excellent (kernel-enforced) |
| Determinism | good (no shared state) |
| Failure containment | good (a crash ends one worker and fails the call; parallel cannot replace that worker, so you make a new cluster) |
When to use: Portability is critical. Package compatibility is required. Workload is coarse-grained (tasks take seconds or more).
When to avoid: Data is large or tasks are fine-grained. Serialization overhead dominates.
Fork clusters (Unix only)
parallel::makeCluster(type = "FORK") or future::plan(multicore). Unix-alikes only, such as Linux and macOS.
| Dimension | Assessment |
|---|---|
| Startup latency | milliseconds |
| Steady-state overhead | low |
| Data movement | copy-on-write, then partial privatization |
| Memory behavior | close to Nx once each child has run a garbage collection |
| Portability | Unix only; R’s documentation discourages it from a GUI such as RStudio |
| Package compatibility | good, except packages that run their own threads |
| Isolation | good (separate address spaces) |
| Determinism | good once each child gets its own RNG stream |
| Failure containment | good (a crash ends one child; with mclapply() the elements that child held come back as NULL with a warning, and with a makeForkCluster() cluster the call fails as it does for PSOCK) |
When to use: Unix-only code is acceptable. Coarse-grained tasks with moderate data movement. Want to avoid PSOCK serialization.
When to avoid: Windows is required, or the code runs inside RStudio. Memory is the main constraint: the garbage collector privatizes the pages a forked worker inherits, so a forked pool keeps little of its memory shared (fork, copy-on-write, and the first GC has sunlight’s measurements). Also avoid it when the parent process already runs threads from a multithreaded library, which a forked child can deadlock in.
Cluster managers (SLURM, Kubernetes, etc.)
External schedulers start workers on machines across a network. parallel::makePSOCKcluster() can start workers on other hosts over ssh, and packages such as batchtools and crew.cluster submit workers as scheduler jobs (SLURM, PBS, SGE and others). HPC clusters use this model.
| Dimension | Assessment |
|---|---|
| Startup latency | seconds to minutes |
| Steady-state overhead | network latency, serialization |
| Data movement | serialize + network |
| Memory behavior | Nx but distributed |
| Portability | cluster-specific |
| Package compatibility | perfect |
| Isolation | excellent |
| Determinism | good |
| Failure containment | excellent |
When to use: Tasks run on different machines. Scale beyond one machine. Isolation and failure containment are critical.
When to avoid: Tasks are fine-grained. Startup latency is prohibitive. Network bandwidth is limited.
1.4.4 Decision table by workload characteristics
This table suggests which model(s) fit your workload.
| Workload characteristic | Suggested model(s) | Reason |
|---|---|---|
| Embarrassingly parallel, large data, Unix only | Fork | Fast startup, avoids serialization |
| Embarrassingly parallel, large data, Windows required | PSOCK, with the data split before sending or read from disk by each worker | No fork on Windows, so avoid sending the whole dataset to every worker |
| Embarrassingly parallel, medium data, portability required | PSOCK | Serialization cost acceptable for moderate data |
| Fine-grained parallel tasks | Any model, after batching tasks into chunks | Per-task dispatch costs more than a microsecond task |
| Coarse-grained tasks, production reliability | PSOCK or cluster manager | Isolation and failure handling |
| Mixed: some parallel, some serial | BLAS/OpenMP or native threads | No explicit parallelism overhead |
| Across machines, no single machine suffices | Cluster manager | Distributed memory is necessary |
| Iterative algorithms, shared state | Separate workers whose updates are merged, or threads in compiled code with careful synchronization | R code itself cannot share state across threads in GNU R |
1.4.5 Choosing
Answer these questions in order.
Can you parallelize your workload? If not, add more memory or buy a faster machine.
Must it run on Windows? If yes, use PSOCK or a cluster manager. Fork is not available.
Is startup latency critical (interactive work, many small tasks)? If yes, prefer fork on Unix, or keep one set of persistent workers alive and reuse it.
Is data large (gigabytes or terabytes)? If yes, avoid sending it whole: fork after loading it (Unix), let each worker read its own part, or distribute across machines.
Do you require production-level failure handling? If yes, use PSOCK or cluster managers, where a crash ends one worker and not the whole session.
Must existing packages work unchanged? If yes, use PSOCK, fork, or cluster managers. Apartments need compiled packages rebuilt for them.
Is memory the bottleneck? If yes, keep the number of R processes small, since each one holds its own heap, and let a multithreaded BLAS or a native package use the cores inside one process.
Are tasks very fine-grained (microseconds)? If yes, batch them into chunks before choosing any model. GNU R cannot run R code on several threads.
1.4.6 Mixing models
A single program can use multiple models at different scales. For example:
- Use BLAS multithreading for matrix operations (built in once R is linked to a threaded BLAS).
- Use fork or PSOCK for embarrassingly-parallel outer loop (explicit parallelism).
- Use a work queue within each worker if tasks are dynamic (scheduling).
The layers multiply. Four workers that each run a BLAS with a thread per core put four times as many threads on the machine as it has cores, so cap the inner layer when you add the outer one. Nested Parallelism and Oversubscription shows how.
Further reading
- A Map of Parallel R. Technical details of each execution model.
- When Parallelism Helps and When It Does Not. Costs that determine whether parallelism pays.
- Processes vs Threads. The tradeoffs between the two in detail.
- Multi-Interpreter Architecture. Design and status of the apartment model.