I am using matlab2011 for parallel calculation with multiple cores, which in my code is simply implemented with the block SPMD END. However, for some times, I want to turn off the spmd in the program based on the input parameter. I try the following code, but it doesn’t work
if (switchSpmdOn)
spmd
end
% here I put my code for calculation in parallel or series
if (switchSpmdOn)
end % this end is used to close the spmd block
end
I am wondering if there is anything like marco to turn off spmd in the code.
You can pass the number of workers as a parameter to
spmd. If the number of workers specified is0, i.e.,then MATLAB will execute the block body locally and create Composite objects, the same as if there is no pool available.
Example