Install any skill in seconds. Free to start, no credit card required.
Get Started Free →matlab/matlab-setup-worker-state
Set up worker environment and per-worker state for parallel pools.
Passed 21 of 22 test cases with the skill, and 11 of 22 without it.
and 14 more in the full report
11 fixed10 passed either way0 still failing1 broke
Tokens, turns and time describe resource use, not a dollar price.
One of 11 test cases the skill fixed. Same model, same prompt, with and without the skill.
My MATLAB script has an active parallel pool running. I need to set the environment variable `MEX_DEBUG` to `'1'` across all active worker processes without closing and reopening the pool, as restarting the pool takes too long. What code should I run?
| Checked | Without skill | With skill |
|---|---|---|
| uses parfevalOnAll to execute setenv across workers | Missed | Passed |
| passes zero as the output count argument to parfevalOnAll | Missed | Passed |
The instructions your model reads when the skill loads.
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.
| Scenario | Correct API | Why |
|---|---|---|
| Non-serializable resource needing cleanup (connections, libraries) | parallel.pool.Constant(@buildFcn, @cleanupFcn) | Constructs on each worker; automatic cleanup on delete |
| Data from a file needed on workers | parallel.pool.Constant(@() load(file).var) | Default for file-based data. Each worker loads from disk; client never holds the dataset. Always prefer this when the source is a file. |
| Data already in client memory, used in multiple parfor loops | parallel.pool.Constant(data) | Transfers once for pool lifetime; without Constant, broadcast re-sends for every parfor loop. Not needed for a single parfor — let MATLAB broadcast. |
| One-shot side effect, no return value needed | parfevalOnAll(pool, @fcn, 0) | Runs once on all workers; use fetchOutputs to surface errors |
| Paths needed on workers — parpool call is in your code | parpool(..., AdditionalPaths=paths) | Cleanest option when you can modify the parpool call; client path entries are inherited automatically |
| Paths needed on workers — pool opened elsewhere (can't modify call) | parfevalOnAll(pool, @addpath, 0, p) | Never delete and recreate a pool just to add paths — use parfevalOnAll on the existing pool |
| Environment variables on workers — parpool call is in your code | parpool(..., EnvironmentVariables=vars) | Forwards named env vars from client to workers at startup; set values with setenv on the client before this call |
| Environment variables on workers — pool opened elsewhere (can't modify call) | parfevalOnAll(pool, @setenv, 0, k, v) | Never delete and recreate a pool just to set env vars — use parfevalOnAll on the existing pool |
Thread pool notes: parallel.pool.Constant and parfevalOnAll also work on
thread pools. However, thread workers share the client's process, so path and
test cases passed, vs 11 / 22 without
More skills from the same source and nearby in the registry, with their headline benchmark lift.