| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → Parallel Computing Toolbox |
| Contents | Index |
| Learn more about Parallel Computing Toolbox |
| On this page… |
|---|
All labs executing an spmd statement must have the same MATLAB path configuration as the client, so that they can execute any functions called in their common block of code. Therefore, whenever you use cd, addpath, or rmpath on the client, it also executes on all the labs, if possible. For more information, see the matlabpool reference page. When the labs are running on a different platform than the client, use the function pctRunOnAll to properly set the MATLAB path on all labs.
When an error occurs on a lab during the execution of an spmd statement, the error is reported to the client. The client tries to interrupt execution on all labs, and throws an error to the user.
Errors and warnings produced on labs are annotated with the lab ID and displayed in the client's Command Window in the order in which they are received by the MATLAB client.
The behavior of lastwarn is unspecified at the end of an spmd if used within its body.
The body of an spmd statement must be transparent, meaning that all references to variables must be "visible" (i.e., they occur in the text of the program).
In the following example, because X is not visible as an input variable in the spmd body (only the string 'X' is passed to eval), it does not get transferred to the labs. As a result, MATLAB issues an error at run time:
X = 5;
spmd
eval('X');
end
Similarly, you cannot clear variables from a worker's workspace by executing clear inside an spmd statement:
spmd; clear('X'); endTo clear a specific variable from a worker, clear its Composite from the client workspace. Alternatively, you can free up most of the memory used by a variable by setting its value to empty, presumably when it is no longer needed in your spmd statement:
spmd
<statements....>
X = [];
endExamples of some other functions that violate transparency are evalc, evalin, and assignin with the workspace argument specified as 'caller'; save and load, unless the output of load is assigned.
MATLAB does successfully execute eval and evalc statements that appear in functions called from the spmd body.
Inside a function, the body of an spmd statement cannot make any direct reference to a nested function. However, it can call a nested function by means of a variable defined as a function handle to the nested function.
Because the spmd body executes on workers, variables that are updated by nested functions called inside an spmd statement do not get updated in the workspace of the outer function.
The body of an spmd statement cannot define an anonymous function. However, it can reference an anonymous function by means of a function handle.
The body of an spmd statement cannot contain another spmd. However, it can call a function that contains another spmd statement. Be sure that your MATLAB pool has enough labs to accommodate such expansion.
The body of a parfor-loop cannot contain an spmd statement, and an spmd statement cannot contain a parfor-loop.
The body of an spmd statement cannot contain break or return statements.
The body of an spmd statement cannot contain global or persistent variable declarations.
![]() | Distributing Arrays | Interactive Parallel Computation with pmode | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |