
290 Accelerating MATLAB
®
Performance
parfor idx = 1 : length(funList)
funcList{idx}(dataList{idx}); % this is run in parallel
end
When the computations are done, the workers pool should be closed or released:
delete(gcp)
Variables that appear in the body of a parfor-loop can be attributed to one of the classes
listed in the following table:
These variable classes are exemplied in the following code fragment:
c = pi; s = 0;
X = rand(1,100);
parfor k = 1 : 100
a = k; % a - temporary variable; k - loop variable
s = s + k; % s - reduction variable
if i <= c % c - broadcast variable
a = 3*a - 1;
end
Y(k) = X(k) + a; % Y - output ...