Code covered by the BSD License  

Highlights from
Enhancing e-Infrastructures with Advanced Technical Computing: Parallel MATLAB® on the Grid

Demo3_spmd_script.m
%% serial part of code
n1 = 50;
n2 = 100;

%% simple spmd block
spmd
    a = rand(n1,n1);
    display(size(a))
end

%% spmd with distributed arrays
spmd
    a = rand(n2,n2,codistributor); % uses default distribution
    display(size(localPart(a)));
end

%% spmd with distributed arrays
% creating a distributed array from local parts
spmd
    % load or create data
    L = rand(n1,n1);
    % create distributed array
    D = codistributed(L);  % use default distribution
    % print sizes of arrays
    display(size(D));
    display(size(localPart(D)));
end

%% Parallel Math
% Data stays on workers between spmd blocks
spmd
    % perform matrix operations
    E = D*D'
    F = D.*D
    % use overloaded functions
    X = fft(D)
    Y = svd(D)
    % retrieve local part
    L = localPart(D);
end

%% Can access the data by referencing into it, now copies to client
Y1 = Y{1};
Y2 = Y{2};

%% Clear all variables that I don't want to send back
clearvars -except Y1 Y2

Contact us at files@mathworks.com