function totalpi = calcPiSpmd(npts)
% CALCPISPMD
% Approximates the integral of 4/(1+x*x) between 0 and 1
if nargin==0, npts = 4; end
% Set up step size based on number of points
h = 1/npts;
% Initialize variable containing local portion of integral
mysum = 0;
% Obtain cumlative sum of points for local lab
spmd
x = h * (labindex - 0.5);
mysum = mysum + 4 / (1 + x*x);
S = gplus(mysum);
end
% Multiply by step size to get area under the curve
totalpi = h * S{1};