matlab-setup-worker-state
Set up worker environment and per-worker state for parallel pools. Use when code needs paths, environment variables, database connections, loaded libraries, or expensive objects available on workers before parfor/parfeval runs. Teaches parallel.pool.Constant, parfevalOnAll, and parpool name-value pairs. Also use when refactoring existing code that uses spmd for side-effect setup (an anti-pattern). Triggers: worker setup, pool constant, per-worker state, non-serializable, loadlibrary on workers, database connection parfor, addpath workers, spmd before parfor, worker environment, reduce parfor o
npx skills add matlab/matlab-agentic-toolkit --skill matlab-setup-worker-state --agent claude-code
Same command for any agent — swap --agent for codex, cursor, copilot.
Weekly change comes from our own snapshots, not the repository page — it measures attention, not adoption.
# Set Up Worker State for Parallel Pools By default, process workers in a parallel pool inherit MATLAB path state from their controlling client, but they do not inherit loaded libraries, open connections, or expensive pre-computed objects. Code that relies on any of these needs explicit setup. This skill teaches the correct APIs for each scenario. Most patterns target process-based pools; thread pool applicability is noted where relevant. ## When to Use - Code needs a **non-serializable resource** on workers (database connections, COM objects, loaded shared libraries, file handles) - Code needs **expensive one-time setup** per worker (large object construction, data loading) that should not repeat every parfor iteration - Code needs **paths or environment variables** set on workers - User has existing code using **spmd for side-effect setup** before parfor (anti-pattern — help them modernise) - User sees errors about objects not being serializable when passed to parfor ## When NOT to Use - Data already in client memory used in a single parfor loop (MATLAB broadcasts it automatically — Constant adds complexity for no benefit in this case) - Choosing between process and thread pools
- When to Use
- When NOT to Use
- Decision Framework
- The spmd Anti-Pattern
- What it looks like
- Why it's fragile
- How to modernise
- Patterns
- Pattern 1: Loading data from a file for use in parfor
- Pattern 2: Shared library (non-serializable, needs cleanup)
- Pattern 3: One-shot setup with parfevalOnAll (no cleanup needed)
- Pattern 4: Database connection (use createConnectionForPool)
- Recognising When pool.Constant Is Needed
- Common Mistakes
What does the matlab-setup-worker-state skill do?
Set up worker environment and per-worker state for parallel pools. Use when code needs paths, environment variables, database connections, loaded libraries, or expensive objects available on workers before parfor/parfeval runs. Teaches parallel.pool.Constant, parfevalOnAll, and parpool name-value pairs. Also use when refactoring existing code that uses spmd for side-effect setup (an anti-pattern). Triggers: worker setup, pool constant, per-worker state, non-serializable, loadlibrary on workers, database connection parfor, addpath workers, spmd before parfor, worker environment, reduce parfor o
How do I install it?
Run `npx skills add matlab/matlab-agentic-toolkit --skill matlab-setup-worker-state --agent claude-code` — it drops the skill into your project so the agent can pick it up. Swap the --agent value for codex, cursor or copilot if you use one of those.
Where does this skill come from?
From matlab/matlab-agentic-toolkit, a repository with 868 stars. We read it straight from the repository tree rather than a submitted listing, so what you see here is what is actually published.
Is a popular skill a good skill?
Not necessarily. Stars measure attention, not adoption — a repository can trend for a week and be abandoned. That is why we show the weekly change from our own snapshots next to the total, instead of a single flattering number.
