User`s guide
2 Parallel for-Loops (parfor)
2-10
parfor Programming Considerations
In this section...
“MATLAB Path” on page 2-10
“Error Handling” on page 2-10
MATLAB Path
All workers executing a parfor-loop must have the same MATLAB search path as the
client, so that they can execute any functions called in the body of the loop. Therefore,
whenever you use cd, addpath, or rmpath on the client, it also executes on all the
workers, if possible. For more information, see the parpool reference page. When
the workers are running on a different platform than the client, use the function
pctRunOnAll to properly set the MATLAB search path on all workers.
Functions files that contain parfor-loops must be available on the search path of
the workers in the pool running the parfor, or made available to the workers by the
AttachedFiles or AdditionalPaths setting of the parallel pool.
Error Handling
When an error occurs during the execution of a parfor-loop, all iterations that are in
progress are terminated, new ones are not initiated, and the loop terminates.
Errors and warnings produced on workers are annotated with the worker ID and
displayed in the client’s Command Window in the order in which they are received by the
client MATLAB.
The behavior of lastwarn is unspecified at the end of the parfor if used within the loop
body.
More About
• “Variables and Transparency in parfor-Loops” on page 2-19
• “parfor Limitations” on page 2-11
• “Inputs and Outputs in parfor-Loops” on page 2-12