function spmdExample matlabpool open 4 % This program compute the arithmetic series s = 1 + 2 + ... + n n = 10; % computes para11e1 range beginning and end indices % [n1,nb,ne]=prange(1, n, matlabpool('size')); spmd s = 0; % initia1ize 1oca1 sum for i=nb(labindex):ne(labindex) s = s + i; % local sum on each worker end disp(['Local sum on worker ' num2str(labindex) ' is ' num2str(s)]) s = gplus(s); % compute global sum with gplus end % spmd disp(['Global sum is ' num2str(s{1})]) matlabpool close