matlab-use-thread-pool

Speed up local parfor, parfeval, and spmd code using thread-based parallel pools in MATLAB.

995|122|Updated Apr 3, 2026
One-click install
npx skills add https://github.com/matlab/matlab-agentic-toolkit --skill matlab-use-thread-pool
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: matlab-use-thread-pool
Source: https://github.com/matlab/matlab-agentic-toolkit/tree/main/skills-catalog/parallel-computing/matlab-use-thread-pool
Command: npx skills add https://github.com/matlab/matlab-agentic-toolkit --skill matlab-use-thread-pool

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Local parallel MATLAB code often underperforms because the default process-based pool adds serialization and data-transfer overhead per worker. This Skill guides an AI agent to switch to a thread-based parallel pool, which eliminates inter-process communication costs for broadcast data and reduces pool startup time.

Core Features & Use Cases

  • Thread Pool Activation: Starts a thread-based pool with parpool("Threads") only when the current pool is not already a thread pool, without disrupting existing parfor, parfeval, or spmd code.
  • Diagnostic-Driven Fallback: Runs the code first and reads MATLAB error diagnostics to determine thread support, recommending parpool("Processes") only when MATLAB reports an unsupported feature.
  • Persistent Configuration: Sets Threads as the default parallel profile via parallel.defaultProfile("Threads") on R2022b or later for users who want thread pools every session.
  • Use Case: A user's parfor loop on a laptop is barely faster than a for loop because large broadcast arrays are serialized to each process worker. The agent switches to a thread pool, where broadcast variables are zero-copy, and the loop speeds up without code changes.

Quick Start

Ask the agent to run my parfor code on a thread-based parallel pool and tell me if anything is unsupported.

Frequently Asked Questions about matlab-use-thread-pool

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I speed up a slow parfor loop in MATLAB?

Start a thread-based parallel pool with parpool("Threads") instead of the default process pool. Broadcast variables become zero-copy on threads, removing serialization and inter-process data transfer that often makes parfor barely faster than a for loop.

What is the difference between thread-based and process-based parallel pools in MATLAB?

Thread pools share memory, so broadcast variables are zero-copy and startup is faster, but they are local-only. Process pools work on clusters and support all features including Simulink parallel tools, but pay serialization and IPC costs per worker.

Does a MATLAB function work on a thread-based pool?

Run the code on a thread pool and read the diagnostic if it errors; MATLAB reports unsupported features explicitly. Do not rely on memory or documentation alone, since thread support expands each release and some support is undocumented.

Can I use a thread pool on a cluster or with Simulink?

No. Thread pools are local-only, so cluster jobs require a process-based pool. Simulink parallel features such as parsim, and distributed or codistributed arrays, also require process-based pools.

How do I make Threads the default parallel pool in MATLAB?

On R2022b or later, run parallel.defaultProfile("Threads") to set Threads as the default profile. This persists across MATLAB sessions without needing a startup script.