%% Test1
%nlabs=4;
% nlabs=16;
% Triton (default: 20, may vary)
%parpool(nlabs) % Opening the pool takes some time.
spmd
% build magic squares in parallel
q = magic(labindex + 2);
end
%%
for ii=1:length(q);figure,imagesc(q{ii});end
%%
Q=cell(1,nlabs);
% Create a cell array Q.
Q(1:nlabs)=q(1:nlabs)
%%
p=parpool % If not open. (Takes a while.)
numlabs=p.NumWorkers
f=@(x) 4./(1+x.^2)
%%
spmd
a = (labindex - 1)/numlabs;
b = labindex/numlabs;
%fprintf('Subinterval: [%-4g, %-4g]\n', a, b);
Int=integral(f,a,b)
S=gop(@plus,Int)
end