Toolboxes
Parallel Computing Toolbox → joblib / multiprocessing / dask
MATLAB's parfor and spmd parallelize loops and distribute work across cores. Python's equivalent choices are joblib (simple, parallel map), multiprocessing (stdlib, explicit), or dask (for out-of-core data that doesn't fit in RAM). Pick joblib for drop-in parfor replacement.
Install
pip install joblib dask| MATLAB | Python | Note |
|---|---|---|
| parfor i = 1:n\n y(i) = f(x(i));\nend | from joblib import Parallel, delayed\ny = Parallel(n_jobs=-1)(delayed(f)(xi) for xi in x) | Drop-in parfor replacement |
| parpool | joblib uses auto-detected pool | No explicit pool setup needed |
| parpool(4) | Parallel(n_jobs=4)(...) | 4 cores |
| delete(gcp) | # pool auto-closes at context exit | No action needed with joblib |
| parfeval(@f, 1, args) | from concurrent.futures import ProcessPoolExecutor\nexecutor.submit(f, *args) | Future-based async execution |
| fetchOutputs(future) | future.result() | |
| spmd\n ...\nend | Use multiprocessing.Pool with explicit worker rank | Rarely a direct port — redesign is usually cleaner |
| labindex | rank from multiprocessing.current_process() or explicit arg | |
| numlabs | os.cpu_count() or pool size | |
| gcp (get current pool) | # implicit in joblib | |
| distributed(X) | dask.array.from_array(X, chunks=...) | For data too large for RAM |
| gather(D) | D.compute() # dask | Materialize a dask array to numpy |
| batch(script) | subprocess.run(['python', script]) | Fire-and-forget background job |
The converter automatically detects Parallel Computing functions and adds the correct imports.
Try the converter