%% Execute Code in Parallel with spmd
% Create a parallel pool, and perform a simple calculation in parallel using spmd. MATLAB executes the code inside the spmd on all workers in the parallel pool.

parpool(3);
spmd
  q = magic(labindex + 2);
end

% Plot the results.

figure
subplot(1,3,1), imagesc(q{1});
subplot(1,3,2), imagesc(q{2});
subplot(1,3,3), imagesc(q{3});

% When you are done with computations, you can delete the current parallel pool.

delete(gcp);

% Copyright 2018 The MathWorks, Inc.